本文整理汇总了Java中com.github.tomakehurst.wiremock.client.WireMock.configureFor方法的典型用法代码示例。如果您正苦于以下问题:Java WireMock.configureFor方法的具体用法?Java WireMock.configureFor怎么用?Java WireMock.configureFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.tomakehurst.wiremock.client.WireMock
的用法示例。
在下文中一共展示了WireMock.configureFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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"))));
}
示例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/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"))));
}
示例3: 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);
}
示例4: 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"))));
}
示例5: 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-stored-connector/actions/io.syndesis:sql-stored-connector:latest"))//
.withHeader("Accept", containing("application/json"))//
.withRequestBody(
equalToJson("{\"template\":null,\"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-stored-connector/actions/io.syndesis:sql-stored-connector:latest"))//
.withHeader("Accept", equalTo("application/json"))//
.withRequestBody(
equalToJson("{\"template\":null,\"user\":\"sa\",\"procedureName\":\"DEMO_ADD\"}"))
.willReturn(aResponse()//
.withStatus(200)//
.withHeader("Content-Type", "application/json")//
.withBody(read("/verifier-response-sql-stored-demo-add-metadata.json"))));
}
示例6: createWithWireMock
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
public static void createWithWireMock(MockSteps mockSteps) {
WireMockServer wireMockServer = new WireMockServer(wireMockConfig().port(8888)); //<-- Strange
wireMockServer.start();
WireMock.configureFor("localhost", 8888); //<-- Repetition of PORT
// TODO - Check wiremock APIs to whether it supports method as a paramater or direct JSON
mockSteps.getMocks().forEach(mockStep -> {
String jsonBodyRequest = mockStep.getResponse().get("body").toString();
if("GET".equals(mockStep.getOperation())){
givenThat(WireMock.get(urlEqualTo(mockStep.getUrl()))
.willReturn(aResponse()
.withStatus(mockStep.getResponse().get("status").asInt())
.withHeader("Content-Type", APPLICATION_JSON)
.withBody(jsonBodyRequest)));
}
else if("POST".equals(mockStep.getOperation())){
givenThat(WireMock.post(urlEqualTo(mockStep.getUrl()))
.willReturn(aResponse()
.withStatus(mockStep.getResponse().get("status").asInt())
.withHeader("Content-Type", APPLICATION_JSON)
.withBody(jsonBodyRequest)));
}
else if("PUT".equals(mockStep.getOperation())){
givenThat(WireMock.put(urlEqualTo(mockStep.getUrl()))
.willReturn(aResponse()
.withStatus(mockStep.getResponse().get("status").asInt())
.withHeader("Content-Type", APPLICATION_JSON)
.withBody(jsonBodyRequest)));
}
});
}
示例7: willMockASimpleGetEndPoint
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
@Test
public void willMockASimpleGetEndPoint() throws Exception{
// WireMockRule rule = new WireMockRule(9073);
// WireMock wireMock = new WireMock(9073);
// WireMock.configureFor(9073);
String jsonDocumentAsString = smartUtils.getJsonDocumentAsString("10_mocking_endpoints/01_wire_mock_end_point_will_respond_to_get_call.json");
ScenarioSpec flowDeserialized = mapper.readValue(jsonDocumentAsString, ScenarioSpec.class);
MockSteps mockSteps = smartUtils.getMapper().readValue(flowDeserialized.getSteps().get(0).getRequest().toString(), MockSteps.class);
final MockStep mockStep = mockSteps.getMocks().get(0);
String jsonBodyRequest = mockStep.getResponse().get("body").toString();
WireMock.configureFor(9073);
givenThat(WireMock.get(urlEqualTo(mockStep.getUrl()))
.willReturn(aResponse()
.withStatus(mockStep.getResponse().get("status").asInt())
.withHeader("Content-Type", APPLICATION_JSON)
.withBody(jsonBodyRequest)));
ApacheHttpClientExecutor httpClientExecutor = new ApacheHttpClientExecutor();
ClientRequest clientExecutor = httpClientExecutor.createRequest("http://localhost:9073" + mockStep.getUrl());
clientExecutor.setHttpMethod("GET");
ClientResponse serverResponse = clientExecutor.execute();
final String respBodyAsString = (String)serverResponse.getEntity(String.class);
JSONAssert.assertEquals(jsonBodyRequest, respBodyAsString, true);
System.out.println("### zerocode: \n" + respBodyAsString);
}
示例8: setUp
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
@Before
public void setUp() {
final WireMockConfiguration config = new WireMockConfiguration();
config.port(8089);
config.extensions(new VelocityResponseTransformer());
server = new WireMockServer(config);
WireMock.configureFor("localhost", 8089);
server.start();
client = new WireMockTestClient(8089);
}
示例9: doWithWireMock
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
public static <T> T doWithWireMock(final WithWireMock<T> command) throws Exception {
final int wireMockPort = WireMockHelper.instance().getFreePort();
final WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().port(wireMockPort));
wireMockServer.start();
WireMock.configureFor("localhost", wireMockPort);
try {
return command.execute(wireMockServer);
} finally {
wireMockServer.shutdown();
while (wireMockServer.isRunning()) {
Thread.sleep(1);
}
}
}
示例10: setUp
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
@BeforeMethod(groups = {"standAloneTest"},enabled = false)
public void setUp() throws Exception {
Properties properties = new Properties();
String property = System.getProperty("integration.test.newspaper.properties");
if (property != null) {
File file = new File(property);
if (file.exists()) {
properties.load(new FileReader(file));
}
}
String username = properties.getProperty(ConfigConstants.DOMS_USERNAME, "fedoraAdmin");
System.out.println(username);
Client client = Client.create();
String password = properties.getProperty(ConfigConstants.DOMS_PASSWORD, "fedoraAdmin");
client.addFilter(
new HTTPBasicAuthFilter(
username, password));
wireMockServer
= new WireMockServer(wireMockConfig().port(8089)); //No-args constructor will start on port 8080, no HTTPS
wireMockServer.start();
WireMock.configureFor("localhost", wireMockServer.port());
givenThat(
WireMock.get(
urlEqualTo(
"/fedora/objects/" + PID + "/relationships?format=ntriples&subject=info:fedora/" + PID +
"/CONTENTS&predicate=http%3A%2F%2Fdoms.statsbiblioteket.dk%2Frelations%2Fdefault%2F0%2F1%2F%23hasMD5"))
.withHeader(
"Authorization", equalTo(encode(username, password.getBytes())))
.willReturn(
aResponse().withBody(
"<info:fedora/" + PID + "/CONTENTS> <http://doms.statsbiblioteket.dk/relations/default/0/1/#hasMD5> \"" + checksum + "\" .")));
WebResource resource = client.resource("http://localhost:" + wireMockServer.port() + "/fedora");
objectResource = resource.path("/objects/").path(PID);
}
开发者ID:statsbiblioteket,项目名称:newspaper-batch-event-framework,代码行数:37,代码来源:JerseyContentsAttributeParsingEventTestWireMocked.java
示例11: setUpReplay
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
@BeforeMethod(groups = {"standAloneTest"})
public void setUpReplay() throws Exception {
/*Generate these replay files by doing this
wget http://repo1.maven.org/maven2/com/github/tomakehurst/wiremock/1.42/wiremock-1.42-standalone.jar
java -jar wiremock-1.42-standalone.jar --proxy-all="http://achernar:7880/" --record-mappings --verbose
Do the test you need to get the recording
Stop the recording server with Ctrl-C when you have sufficient material
It will generate two folders, mapping and __files. Copy these to src/test/resources/fedoraIteratorReplay
*/
if (replay) {
File file = new File(
Thread.currentThread().getContextClassLoader().getResource("ITconfig.properties").toURI());
File srcTestResources = file.getParentFile();
File fedoraIteratorReplay = new File(srcTestResources, "fedoraIteratorReplay");
File mappings = new File(fedoraIteratorReplay, "mappings");
wireMockServer = new WireMockServer(8089, new SingleRootFileSource(fedoraIteratorReplay), false);
wireMockServer.start();
wireMockServer.loadMappingsUsing(
new JsonFileMappingsLoader(
new SingleRootFileSource(
mappings.getAbsolutePath())));
WireMock.configureFor("localhost", wireMockServer.port());
}
}
开发者ID:statsbiblioteket,项目名称:newspaper-batch-event-framework,代码行数:31,代码来源:IteratorForFedora3TestWireMocked.java
示例12: setUp
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
wireMockServer = new WireMockServer(wireMockConfig().port(8089));
wireMockServer.start();
WireMock.configureFor("localhost", 8089);
// Stub server response for access token
stubFor(post(urlEqualTo("/accesstoken.srf"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", MediaType.APPLICATION_JSON)
.withBody("{\"access_token\":\"access_token\",\"token_type\":\"token_type\",\"expires_in\":9999}")));
}
示例13: startWiremockServer
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
/**
* Method to start the wiremock server
* Note: we dont actually stop the server as we want the server to be available to requests can be mocked
*/
private void startWiremockServer() {
WireMock.configureFor("localhost", wireMockRule.port());
wireMockRule.start();
//Formatted with https://www.freeformatter.com/json-formatter.html
//Setup the identities stubs
String identitiesFolder = "Identities";
String identitiesGetMethod = "get";
String identitiesCreateMethod = "create";
String identitiesUpdateMethod = "update";
String identitiesDeleteMethod = "delete";
setUpStub(IDENTITIES_URL, identitiesFolder, identitiesGetMethod);
setUpStub(IDENTITIES_URL, identitiesFolder, identitiesCreateMethod);
setUpStub(IDENTITIES_URL, identitiesFolder, identitiesUpdateMethod);
setUpStub(IDENTITIES_URL, identitiesFolder, identitiesDeleteMethod);
//Setup the tokens stubs
String tokensFolder = "Tokens";
String tokensGetMethod = "get";
String tokensGetBalanceMethod = "getBalance";
setUpStub(TOKENS_URL, tokensFolder, tokensGetMethod);
setUpStub(TOKENS_URL, tokensFolder, tokensGetBalanceMethod);
//Setup the TransactionRequests stubs
String transactionRequestsFolder = "TransactionRequests";
String transactionRequestsGetMethod = "get";
String transactionRequestsCreateMethod = "create";
String transactionRequestsCancelMethod = "cancel";
setUpStub(TRANSACTION_REQUESTS_URL, transactionRequestsFolder, transactionRequestsGetMethod);
setUpStub(TRANSACTION_REQUESTS_URL, transactionRequestsFolder, transactionRequestsCreateMethod);
setUpStub(TRANSACTION_REQUESTS_URL, transactionRequestsFolder, transactionRequestsCancelMethod);
//Setup the events stubs
String eventsFolder = "Events";
String eventsGetMethod = "get";
setUpStub(EVENTS_URL, eventsFolder, eventsGetMethod);
//Setup the platform stubs
String platformFolder = "Platform";
String platformGetAuthMethod = "auth";
setUpStub(PLATFORM_URL, platformFolder, platformGetAuthMethod);
}
示例14: startWireMockServer
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
public static void startWireMockServer() {
WIRE_MOCK.start();
WireMock.configureFor(WIRE_MOCK.port());
}
示例15: setupServer
import com.github.tomakehurst.wiremock.client.WireMock; //导入方法依赖的package包/类
@BeforeClass
public static void setupServer() {
setupWireMockConnection();
WireMock.configureFor(scheme, host, port, context);
WireMock.reset();
}