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


Java MappingBuilder类代码示例

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


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

示例1: test_resp

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例2: test_jsonResp

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例3: test_errorResp

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例4: test_queryParams

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例5: test_resp

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例6: test_jsonResp

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例7: test_jsonErrorResp

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例8: test_errorResp

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例9: test_formBody

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例10: test_jsonBody

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例11: test_textBody

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例12: test

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的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

示例13: testCreatePeriodicalBackups

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的package包/类
/**
 * Test for {@link ModuleBackups#createPeriodicalBackups(int, int, int)}.
 */
@TestTemplate
void testCreatePeriodicalBackups(WireMockServer wireMock, JiffyBoxApi api) {
    MappingBuilder builder = post(urlPathEqualTo("/00000000000000000000000000000000/v1.0/backups/12345"));
    StringValuePattern body = equalToJson("{\"dayid\": 0, \"timeid\": 1}", false, false);
    wireMock.stubFor(builder.withRequestBody(body)
            .willReturn(aResponse().withHeaders(WireMockHelper.headers())
                    .withStatus(200)
                    .withBodyFile("modules/backups/testCreatePeriodicalBackups.json")));

    Response<BackupConfig> response = api.backups().createPeriodicalBackups(12345, 0, 1);
    List<Message> messages = response.getMessages();
    BackupConfig backup = response.getResult();

    assertTrue(messages.isEmpty());

    assertEquals(0, backup.getDayid());
    assertEquals(1, backup.getTimeid());
}
 
开发者ID:jschlichtholz,项目名称:jiffybox,代码行数:22,代码来源:ModuleBackupsTest.java

示例14: testUpdatePeriodicalBackups

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的package包/类
/**
 * Test for {@link ModuleBackups#updatePeriodicalBackups(int, int, int)}.
 */
@TestTemplate
void testUpdatePeriodicalBackups(WireMockServer wireMock, JiffyBoxApi api) {
    MappingBuilder builder = put(urlPathEqualTo("/00000000000000000000000000000000/v1.0/backups/12345"));
    StringValuePattern body = equalToJson("{\"dayid\": 0, \"timeid\": 1}", false, false);
    wireMock.stubFor(builder.withRequestBody(body)
            .willReturn(aResponse().withHeaders(WireMockHelper.headers())
                    .withStatus(200)
                    .withBodyFile("modules/backups/testUpdatePeriodicalBackups.json")));

    Response<BackupConfig> response = api.backups().updatePeriodicalBackups(12345, 0, 1);
    List<Message> messages = response.getMessages();
    BackupConfig backup = response.getResult();

    assertTrue(messages.isEmpty());

    assertEquals(0, backup.getDayid());
    assertEquals(1, backup.getTimeid());
}
 
开发者ID:jschlichtholz,项目名称:jiffybox,代码行数:22,代码来源:ModuleBackupsTest.java

示例15: testDeletePeriodicalBackups

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的package包/类
/**
 * Test for {@link ModuleBackups#deletePeriodicalBackups(int)}.
 */
@TestTemplate
void testDeletePeriodicalBackups(WireMockServer wireMock, JiffyBoxApi api) {
    MappingBuilder builder = delete(urlPathEqualTo("/00000000000000000000000000000000/v1.0/backups/12345"));
    wireMock.stubFor(builder.willReturn(aResponse().withHeaders(WireMockHelper.headers())
            .withStatus(200)
            .withBodyFile("modules/backups/testDeletePeriodicalBackups.json")));

    Response<Boolean> response = api.backups().deletePeriodicalBackups(12345);
    List<Message> messages = response.getMessages();
    Boolean result = response.getResult();

    assertTrue(messages.isEmpty());

    assertTrue(result);
}
 
开发者ID:jschlichtholz,项目名称:jiffybox,代码行数:19,代码来源:ModuleBackupsTest.java


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