當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。