本文整理匯總了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")));
}
示例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"))));
}
示例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"))));
}
示例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")));
}
示例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)));
}
示例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());
}
示例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))));
}
示例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"));
}
示例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));
}
示例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)));
}
示例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));
}
示例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;
}
示例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);
}