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


Java WireMock类代码示例

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


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

示例1: setUp

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
  stubFor(WireMock.post(urlPathEqualTo("/rest/as"))
      .withRequestBody(containing("foo=as&response=" + URLEncoder.encode("{}", "UTF-8")))
      .willReturn(
          aResponse()
              .withStatus(HttpStatus.SC_OK)
              .withBody("{\n"
                  + "  \"body\": \"success\",\n"
                  + "  \"sagaChildren\": [\"none\"]\n"
                  + "}")));

  stubFor(WireMock.post(urlPathEqualTo("/rest/bs"))
      .withRequestBody(containing("foo=bs"))
      .willReturn(
          aResponse()
              .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)
              .withBody("process failed")));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:20,代码来源:SagaSpringApplicationTestBase.java

示例2: setupMocks

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@Before
public void setupMocks() {
    WireMock.configureFor(wireMock.port());
    stubFor(WireMock

        .post(urlEqualTo(
            "/api/v1/connectors/salesforce/actions/io.syndesis:salesforce-create-or-update-connector:latest"))//
        .withHeader("Accept", equalTo("application/json"))//
        .withRequestBody(equalToJson("{\"clientId\":\"a-client-id\",\"sObjectName\":null,\"sObjectIdName\":null}"))
        .willReturn(aResponse()//
            .withStatus(200)//
            .withHeader("Content-Type", "application/json")//
            .withBody(read("/verifier-response-salesforce-no-properties.json"))));

    stubFor(WireMock
        .post(urlEqualTo(
            "/api/v1/connectors/salesforce/actions/io.syndesis:salesforce-create-or-update-connector:latest"))//
        .withHeader("Accept", equalTo("application/json"))//
        .withRequestBody(
            equalToJson("{\"clientId\":\"a-client-id\",\"sObjectName\":\"Contact\",\"sObjectIdName\":null}"))
        .willReturn(aResponse()//
            .withStatus(200)//
            .withHeader("Content-Type", "application/json")//
            .withBody(read("/verifier-response-salesforce-type-contact.json"))));
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:26,代码来源:DynamicActionDefinitionITCase.java

示例3: setupMocks

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@Before
public void setupMocks() {
    WireMock.configureFor(wireMock.port());
    stubFor(WireMock
        .post(urlEqualTo(
            "/api/v1/connectors/sql/actions/sql-stored-connector"))//
        .withHeader("Accept", containing("application/json"))//
        .withRequestBody(
                equalToJson("{\"template\":null,\"Pattern\":\"To\",\"procedureName\":null,\"user\":\"sa\"}"))
        .willReturn(aResponse()//
            .withStatus(200)//
            .withHeader("Content-Type", "application/json")//
            .withBody(read("/verifier-response-sql-stored-list.json"))));

    stubFor(WireMock
        .post(urlEqualTo(
            "/api/v1/connectors/sql/actions/sql-stored-connector"))//
        .withHeader("Accept", equalTo("application/json"))//
        .withRequestBody(
                equalToJson("{\"template\":null,\"Pattern\":\"To\",\"user\":\"sa\",\"procedureName\":\"DEMO_ADD\"}"))
        .willReturn(aResponse()//
            .withStatus(200)//
            .withHeader("Content-Type", "application/json")//
            .withBody(read("/verifier-response-sql-stored-demo-add-metadata.json"))));
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:26,代码来源:DynamicActionSqlStoredITCase.java

示例4: MockPersistenceProvider

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
/**
 * Create a mock persistence using a wire mock rule.
 * Recommended: Use {@link #DEFAULT_MOCK_PERSISTENCE_PORT} as port.
 * @param rule The wire mock rule to create the mocking stubs for.
 */
public MockPersistenceProvider(WireMockRule rule) {
	this.port = rule.port();
	rule.stubFor(WireMock.get(WireMock.urlEqualTo(
			"/" + Service.PERSISTENCE.getServiceName() + "/rest/orders"))
					.willReturn(WireMock.okJson(getOrders())));
	rule.stubFor(WireMock.get(WireMock.urlEqualTo(
			"/" + Service.PERSISTENCE.getServiceName() + "/rest/orderitems"))
					.willReturn(WireMock.okJson(getOrderItems())));
	rule.stubFor(WireMock.get(WireMock.urlEqualTo(
			"/" + Service.PERSISTENCE.getServiceName() + "/rest/generatedb/finished"))
					.willReturn(WireMock.ok("true")));
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:18,代码来源:MockPersistenceProvider.java

示例5: initializeServiceQueryStubs

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
private void initializeServiceQueryStubs(WireMockRule rule,
		List<Integer> persistencePorts, List<Integer> recommenderPorts)
		throws JsonProcessingException {
	List<String> persistences = new LinkedList<String>();
	for (int persistencePort: persistencePorts) {
		persistences.add("localhost:" + persistencePort);
	}
	String json = new ObjectMapper().writeValueAsString(persistences);
	rule.stubFor(WireMock.get(WireMock.urlEqualTo(
			"/tools.descartes.petsupplystore.registry/rest/services/" + Service.PERSISTENCE.getServiceName() + "/"))
					.willReturn(WireMock.okJson(json)));
	List<String> recommenders = new LinkedList<String>();
	for (int recommenderPort: recommenderPorts) {
		recommenders.add("localhost:" + recommenderPort);
	}
	json = new ObjectMapper().writeValueAsString(recommenders);
	rule.stubFor(WireMock.get(WireMock.urlEqualTo(
			"/tools.descartes.petsupplystore.registry/rest/services/" + Service.RECOMMENDER.getServiceName() + "/"))
					.willReturn(WireMock.okJson(json)));
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:21,代码来源:MockRegistry.java

示例6: customerByIdShouldReturnACustomer

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@Test
public void customerByIdShouldReturnACustomer() {

    WireMock.stubFor(WireMock.get(WireMock.urlMatching("/customers/1"))
            .willReturn(
                    WireMock.aResponse()
                            .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
                            .withStatus(HttpStatus.OK.value())
                            .withBody(asJson(customerById))
            ));

    Customer customer = client.getCustomerById(1L);
    BDDAssertions.then(customer.getFirstName()).isEqualToIgnoringCase("first");
    BDDAssertions.then(customer.getLastName()).isEqualToIgnoringCase("last");
    BDDAssertions.then(customer.getEmail()).isEqualToIgnoringCase("email");
    BDDAssertions.then(customer.getId()).isEqualTo(1L);
}
 
开发者ID:applied-continuous-delivery-livelessons,项目名称:testing-101,代码行数:18,代码来源:CustomerClientWiremockTest.java

示例7: get

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@Test
public void get() throws Exception {
  String agentId = UUID.randomUUID().toString();
  AgentDto agent = new AgentDto();
  agent.setAddress("sip:[email protected]");

  stubFor(WireMock.get(urlEqualTo("/api/routers/" + routerRef + "/agents/" + agentId))
      .withHeader("Accept", equalTo("application/json"))
      .willReturn(aResponse()
          .withStatus(200)
          .withHeader("Content-Type", "application/json")
      .withBody(objectMapper.writeValueAsString(agent))));

  AgentDto agentDto = serviceClient.get(new RouterObjectRef(agentId, routerRef));

  assertNotNull("agent is found",
      agentDto);

  assertEquals("address matches",
      agent.getAddress(), agentDto.getAddress());
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:22,代码来源:AgentServiceClientTest.java

示例8: restDocsWireMockDemoTest

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@Test
public void restDocsWireMockDemoTest() throws Exception {
    mockMvc.perform(get("/product?id=537"))
            .andExpect(status().isOk())
            .andExpect(content()
                    .json("{" +
                            "\"name\": \"Consumer Test\"," +
                            "\"description\" : \"Consumer Test verifies provider\"," +
                            "\"type\": \"testing product\"" +
                            "}"))
            .andDo(WireMockRestDocs.verify().
                    wiremock(WireMock
                            .get(WireMock.urlPathEqualTo("/product"))
                            .withQueryParam("id", equalTo("537")))
                    .stub("restdocs-resource-2"));
}
 
开发者ID:nt-ca-aqe,项目名称:blog-contract-testing-with-spring-cloud-contract,代码行数:17,代码来源:ProviderRestDocsDemoTest.java

示例9: before

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@Before
public void before(){
    SSOConfig c = new SSOConfig();
    c.setClientId("clientId");
    c.setClientSecret("clientSecret");
    c.setRedirectUri(LOCAL_HOST);
    c.autoConfigureUrls("http://localhost:9999");
    client = new SSOClient(c);
    
    sr.registerServlet( "/ssoclient/login", LoginServlet.class.getName());

    String pk = org.apache.commons.codec.binary.Base64.encodeBase64String(keyPair.getPublic().getEncoded());

    Map<String, String> resp = new HashMap<String, String>();
    resp.put("access_token","accesstoken");
    resp.put("refresh_token","refreshtoken");
    resp.put("expires_in","3600");
    resp.put("token_type","Bearer");
    
    stubFor(WireMock.get("/oauth2/publickey").willReturn(aResponse().withStatus(200).withBody(pk)));
    stubFor(post("/oauth2/token").willReturn(aResponse().withStatus(200).withBody(JSON.encode(resp))));
}
 
开发者ID:bingo-oss,项目名称:sso-client,代码行数:23,代码来源:ServletTest.java

示例10: sendHttpRequestWithVarsPost

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@Test
public void sendHttpRequestWithVarsPost() throws java.lang.Exception {
    String body = "testBodyValue";
    String bodyVarName = "testBodyName";
    akitaScenario.setVar(bodyVarName, body);

    stubFor(post(urlEqualTo("/post/resource"))
            .withRequestBody(WireMock.equalTo(body))
            .willReturn(aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")
                    .withBody("TEST_BODY")));

    List<RequestParam> params = Collections.singletonList(
            RequestParam.builder()
                    .name("body")
                    .type(RequestParamType.BODY)
                    .value("{" + bodyVarName + "}")
                    .build());

    api.sendHttpRequestSaveResponse("POST", "/post/resource", "RESPONSE_POST_BODY", params);
    assertThat(akitaScenario.getVar("RESPONSE_POST_BODY"), equalTo("TEST_BODY"));
}
 
开发者ID:alfa-laboratory,项目名称:akita,代码行数:24,代码来源:ApiStepsTest.java

示例11: resetWireMock

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

示例12: mockMinio

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
private void mockMinio() {

        mockServer.stubFor(get(urlMatching("/alpha.*"))
                .willReturn(aResponse().withBody(
                        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                        "<ListBucketResult>\n" +
                        "    <Name>alpha</Name>\n" +
                        "    <Prefix/>\n" +
                        "    <KeyCount>0</KeyCount>\n" +
                        "    <MaxKeys>100</MaxKeys>\n" +
                        "    <IsTruncated>false</IsTruncated>\n" +
                        "</ListBucketResult>")));

        mockServer.stubFor(WireMock.head(urlMatching("/alpha.*")).willReturn(aResponse().withStatus(200)));

        mockServer.stubFor(WireMock.put(urlMatching(".*")).willReturn(aResponse().withStatus(200)));

    }
 
开发者ID:fnproject,项目名称:fdk-java,代码行数:19,代码来源:ThumbnailsFunctionTest.java

示例13: executeTest

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
protected void executeTest(String engine) throws Exception {

        stubFor(WireMock.get(WireMock.urlPathMatching("/some/url"))
                        .withHeader("accept", WireMock.equalTo("application/xml"))
                        .willReturn(aResponse()
                                .withStatus(200)
                                .withBody("" +
                                        "<payload>" +
                                        "    <value>Body Text</value>" +
                                        "</payload>"
                                )
                        ));

        ResponseEntity<String> response = new JCurl()
            .execute(
                "--engine", engine
                , "-H", "accept: application/xml"
                , "--verbose"
                , "--count", "3"
                , "http://localhost:" + wireMockRule.port() + "/some/url");

        assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
    }
 
开发者ID:eeichinger,项目名称:jcurl,代码行数:24,代码来源:JCurlTest.java

示例14: createObject

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@Override
protected URL createObject(DeploymentEndpoints endpoints) {
    for(DeploymentEndpoints.Endpoint endpoint : endpoints.list()) {
        if(endpoint.getName().equals("wiremock-server")) {
            String host = endpoint.getHost();
            int port = endpoint.getPort();
            WireMock wireMock = new WireMock(host,port);
            wireMock.register(StubMapping.buildFrom(stubMapping));
            try {
                return new URL(String.format("http://%s:%s", host, port));
            } catch (MalformedURLException e) {
                return null;
            }
        }
    }
    return null;
}
 
开发者ID:LivePersonInc,项目名称:ephemerals,代码行数:18,代码来源:WireMockEphemeral.java

示例15: before

import com.github.tomakehurst.wiremock.client.WireMock; //导入依赖的package包/类
@Before
public void before() {
    wireMockServer = new WireMockServer(0);
    wireMockServer.start();

    // resets the mock server that was set inside the rest template
    authenticatedRestTemplate.restTemplate = new CookieStoreRestTemplate();
    authenticatedRestTemplate.init();

    // if port was 0, then the server will randomize it on start up, and now we
    // want to get that value back
    int port = wireMockServer.port();
    logger.debug("Wiremock server is running on port = {}", port);
    resttemplateConfig.setPort(port);
    WireMock.configureFor("localhost", port);
}
 
开发者ID:box,项目名称:mojito,代码行数:17,代码来源:AuthenticatedRestTemplateTest.java


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