All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.httpmock.builder.ResponseBuilder Maven / Gradle / Ivy

package com.github.httpmock.builder;

import static com.github.httpmock.util.CollectionUtil.emptyMap;

import java.util.Map;

import org.apache.commons.codec.binary.Base64;

import com.github.httpmock.dto.ResponseDto;

public class ResponseBuilder {
	private String payload;
	private int statusCode;
	private Map headers;

	public ResponseBuilder() {
		statusCode = 200;
		headers = emptyMap();
	}

	public ResponseBuilder payload(String string) {
		return payload(string.getBytes());
	}

	public ResponseBuilder payload(byte[] bytes) {
		this.payload = new String(Base64.encodeBase64(bytes));
		return this;
	}

	public ResponseBuilder contentType(String contentType) {
		return header("Content-Type", contentType);
	}

	public ResponseBuilder statusCode(int statusCode) {
		this.statusCode = statusCode;
		return this;
	}

	public ResponseBuilder header(String key, String value) {
		headers.put(key, value);
		return this;
	}

	public ResponseDto build() {
		ResponseDto responseDto = new ResponseDto();
		responseDto.setPayload(payload);
		responseDto.setStatusCode(statusCode);
		responseDto.setHeaders(headers);
		return responseDto;
	}

	public static ResponseBuilder response() {
		return new ResponseBuilder();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy