当前位置: 首页>>代码示例>>Java>>正文


Java ResponseDefinitionBuilder类代码示例

本文整理汇总了Java中com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder的典型用法代码示例。如果您正苦于以下问题:Java ResponseDefinitionBuilder类的具体用法?Java ResponseDefinitionBuilder怎么用?Java ResponseDefinitionBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResponseDefinitionBuilder类属于com.github.tomakehurst.wiremock.client包,在下文中一共展示了ResponseDefinitionBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resetWireMock

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
/**
 * Reset wire mock and re-configure stubbing.
 */
private void resetWireMock() {
    WireMock.reset();
    // Stub to return 200 for all requests
    final ResponseDefinitionBuilder responseDefBuilder = aResponse().withStatus(200);
    // XML Unmarshallers expect at least one level in the XML document.
    if (model.getMetadata().isXmlProtocol()) {
        responseDefBuilder.withBody("<foo></foo>");
    }
    stubFor(any(urlMatching(".*")).willReturn(responseDefBuilder));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:14,代码来源:MarshallingTestRunner.java

示例2: toResponseBuilder

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
private ResponseDefinitionBuilder toResponseBuilder(GivenResponse givenResponse) {

        final ResponseDefinitionBuilder responseBuilder = aResponse().withStatus(200);
        if (givenResponse.getHeaders() != null) {
            givenResponse.getHeaders().forEach(responseBuilder::withHeader);
        }
        if (givenResponse.getStatusCode() != null) {
            responseBuilder.withStatus(givenResponse.getStatusCode());
        }
        if (givenResponse.getBody() != null) {
            responseBuilder.withBody(givenResponse.getBody());
        } else if (metadata.isXmlProtocol()) {
            // XML Unmarshallers expect at least one level in the XML document. If no body is explicitly
            // set by the test add a fake one here.
            responseBuilder.withBody("<foo></foo>");
        }
        return responseBuilder;
    }
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:19,代码来源:UnmarshallingTestRunner.java

示例3: test_resp

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_resp() {
	MappingBuilder mockReq = get(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse().withStatus(200).withBody("data");
	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.get(url);

		httpClient.setResultReader(TextReader.INSTANCE);
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);
		Assert.assertEquals(httpClient.getResultObject(), "data");

		Assert.assertNull(httpClient.getErrorObject());
	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:23,代码来源:HttpGetTest.java

示例4: test_jsonResp

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_jsonResp() {
	MappingBuilder mockReq = get(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse().withStatus(200).withBody("{\"prop1\": \"value1\"}");
	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.get(url);

		httpClient.setResultReader(new JsonReader()).setResultClass(HashMap.class);
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);
		Map<String, Object> result = httpClient.getResultObject();
		Assert.assertEquals(result.get("prop1"), "value1");

		Assert.assertNull(httpClient.getErrorObject());
	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:24,代码来源:HttpGetTest.java

示例5: test_errorResp

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_errorResp() {
	MappingBuilder mockReq = get(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse().withStatus(500).withBody("Error");
	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.get(url);
		httpClient.setResultReader(TextReader.INSTANCE);
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 500);
		Assert.assertEquals(httpClient.getErrorObject(), "Error");
	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:20,代码来源:HttpGetTest.java

示例6: test_queryParams

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_queryParams() {
	MappingBuilder mockReq = get(urlPathMatching("/action"));

	mockReq.withQueryParam("p1", equalTo("v1"));
	mockReq.withQueryParam("p2", equalTo("v 2"));

	ResponseDefinitionBuilder mockResp = aResponse().withStatus(200);
	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl() + "?" + new QueryParams().param("p1", "v1").param("p2", "v 2");

		httpClient = HttpClient.get(url);
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);
	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:23,代码来源:HttpGetTest.java

示例7: test_resp

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_resp() {
	MappingBuilder mockReq = post(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse().withStatus(200).withBody("data");
	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.post(url);

		httpClient.setResultReader(TextReader.INSTANCE);
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);

		String result = httpClient.getResultObject();
		Assert.assertEquals(result, "data");

	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:24,代码来源:HttpPostTest.java

示例8: test_jsonResp

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_jsonResp() {
	MappingBuilder mockReq = post(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse().withStatus(200).withBody("{\"prop1\": \"value1\"}");

	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.post(url);

		httpClient.setResultReader(new JsonReader()).setResultClass(HashMap.class);
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);

		Map<String, Object> result = httpClient.getResultObject();
		Assert.assertEquals(result.get("prop1"), "value1");

	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:25,代码来源:HttpPostTest.java

示例9: test_jsonErrorResp

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_jsonErrorResp() {
	MappingBuilder mockReq = post(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse().withStatus(500).withBody("{\"success\": false}");

	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.post(url);

		httpClient.setErrorReader(new JsonReader()).setErrorClass(HashMap.class);
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 500);
		Assert.assertNull(httpClient.getResultObject());

		Map<String, Object> result = httpClient.getErrorObject();
		Assert.assertEquals(result.get("success"), Boolean.FALSE);

	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:26,代码来源:HttpPostTest.java

示例10: test_errorResp

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_errorResp() {
	MappingBuilder mockReq = post(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse().withStatus(500).withBody("Error");
	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.post(url);
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 500);
		Assert.assertEquals(httpClient.getErrorObject(), "Error");

	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:20,代码来源:HttpPostTest.java

示例11: test_formBody

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_formBody() {
	MappingBuilder mockReq = post(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse();

	mockReq.withRequestBody(containing("p1=v1"));
	mockReq.withRequestBody(containing("p2=v+2"));

	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.post(url);

		httpClient.setRequestBody(new FormBody().param("p1", "v1").param("p2", "v 2"));
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);

	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:25,代码来源:HttpPostTest.java

示例12: test_jsonBody

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_jsonBody() {
	MappingBuilder mockReq = post(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse();
	mockReq.withRequestBody(equalTo("{\"id\":1,\"name\":\"user1\"}"));

	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.post(url);

		httpClient.setRequestBody(new JsonBody(new User(1, "user1"), CharsetUtils.UTF_8));
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);

	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:23,代码来源:HttpPostTest.java

示例13: test_textBody

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test_textBody() {
	MappingBuilder mockReq = post(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse();
	mockReq.withRequestBody(equalTo("textBody"));

	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.post(url);

		httpClient.setRequestBody(new TextBody("textBody"));
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);

	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:23,代码来源:HttpPostTest.java

示例14: test

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Test
public void test() {
	MappingBuilder mockReq = head(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse().withStatus(200).withHeader("header1", "value1");
	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.head(url);
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);
		Assert.assertEquals(httpClient.getResponseHeader("header1"), "value1");

		Assert.assertNull(httpClient.getResultObject());

	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:22,代码来源:HttpHeadTest.java

示例15: transform

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request,
                                    ResponseDefinition responseDefinition,
                                    FileSource files,
                                    Parameters parameters) {


  ResponseDefinitionBuilder builder = new ResponseDefinitionBuilder().like(responseDefinition);
  String templatePath   = responseDefinition.getBodyFileName();

  if (templatePath != null && templatePath.contains(".template")) {
    try {
      Map scope = new ResponseScope(session, new HashMap(this.config), RequestReader.read(request));
      responseWriter = responseWriter == null ? new ResponseWriter(files.getPath()) : responseWriter;
      new BeforeBlock().run(responseDefinition, scope);
      responseWriter.writeTo(builder, scope, templatePath);
    } catch (Exception e) {
      String errorMessage = "************* Jeyson Error *******************" + System.getProperty("line.separator");
      errorMessage += e.getMessage() + System.getProperty("line.separator");
      System.err.println(errorMessage);
      e.printStackTrace();
    }
  }

  return builder.build();
}
 
开发者ID:nishants,项目名称:wirestub,代码行数:27,代码来源:JeysonWiremock.java


注:本文中的com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。