• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MappingBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testCreateManualBackup

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

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

    assertTrue(messages.isEmpty());

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


示例17: testDeleteBackup

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

    Response<Boolean> response = api.backups().deleteBackup(12345, "daily", "12345ACDEF");
    List<Message> messages = response.getMessages();
    Boolean result = response.getResult();

    assertTrue(messages.isEmpty());

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


示例18: testRestoreBackup

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

    Response<Boolean> response = api.backups().restoreBackup(12345, "daily", "12345ACDEF");
    List<Message> messages = response.getMessages();
    Boolean result = response.getResult();

    assertTrue(messages.isEmpty());

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


示例19: regurgitatorStub

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的package包/类
/**
 * To be invoked similarly to this:
 * <code>WireMock.stubFor(RegurgitatorWireMock.regurgitatorStub(mock));</code>
 *
 * This alleviates the need for mocking the content as such in wiremock, and
 * you can concentrate on getting the headers right.
 */
public static MappingBuilder regurgitatorStub(ServerResponse mock) {
    RequestMethod requestMethod = resolveMethodFrom( mock.getMeta() );

    UrlMatchingStrategy urlMatchingStrategy = null;
    try {
        urlMatchingStrategy = WireMock.urlEqualTo(new URI(mock.getMeta().getUri()).getPath());
    } catch (URISyntaxException e) {
        throw new RegurgitatorException("Not expecting previously saved mock to contain error in URI. " +
                "But it did... Contents:"+mock.getMeta().getUri());
    }

    final ResponseDefinitionBuilder aResponse = WireMock.aResponse();

    final Headers headers = mock.getMeta().getHeaders();
    headers.getHeaderNames()
            .stream()
            .forEach(k -> aResponse.withHeader(k, headers.getHeaderValue(k)));

    return new MappingBuilder(requestMethod, urlMatchingStrategy )
            .willReturn(aResponse
                .withStatus(mock.getMeta().getStatus())
                    .withBody(mock.getContent()));
}
 
开发者ID:amedia,项目名称:regurgitator,代码行数:31,代码来源:RegurgitatorWireMock.java


示例20: stubRequest

import com.github.tomakehurst.wiremock.client.MappingBuilder; //导入依赖的package包/类
private static void stubRequest(String method, String endpoint, int status, Collection<Pair> headers, String body) {
	UrlPattern urlPattern = urlEqualTo(endpoint);
	MappingBuilder request = request(method, urlPattern);

	ResponseDefinitionBuilder response = aResponse().withStatus(status);

	for (Pair header : headers) {
		response.withHeader(header.getO1(), header.getO2());
	}

	if (body != null) {
		response.withBody(body);
	}

	stubFor(request.willReturn(response));
}
 
开发者ID:mjeanroy,项目名称:junit-servers,代码行数:17,代码来源:WireMockTestUtils.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DefaultGoApiRequest类代码示例发布时间:2022-05-22
下一篇:
Java Database类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap