本文整理匯總了Java中com.github.tomakehurst.wiremock.WireMockServer類的典型用法代碼示例。如果您正苦於以下問題:Java WireMockServer類的具體用法?Java WireMockServer怎麽用?Java WireMockServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WireMockServer類屬於com.github.tomakehurst.wiremock包,在下文中一共展示了WireMockServer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setup
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的package包/類
@BeforeEach
void setup() throws Exception {
// Look for free port for SUT instantiation
int port;
try (ServerSocket socket = new ServerSocket(0)) {
port = socket.getLocalPort();
}
remoteFileService = new RemoteFileService("http://localhost:" + port);
// Mock server
wireMockServer = new WireMockServer(options().port(port));
wireMockServer.start();
configureFor("localhost", wireMockServer.port());
// Stubbing service
stubFor(post(urlEqualTo("/api/v1/paths/" + filename + "/open-file"))
.willReturn(aResponse().withStatus(200).withBody(streamId)));
stubFor(post(urlEqualTo("/api/v1/streams/" + streamId + "/read"))
.willReturn(aResponse().withStatus(200).withBody(contentFile)));
stubFor(post(urlEqualTo("/api/v1/streams/" + streamId + "/close"))
.willReturn(aResponse().withStatus(200)));
}
示例2: customize
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的package包/類
@Override
public void customize(WireMockServer server) {
String uuid = UUID.randomUUID().toString();
server.stubFor(
post(urlPathEqualTo("/ticket"))
.willReturn(aResponse()
.withStatus(201)
.withHeader(
"Location",
format("http://localhost:%s/ticket/%s", server.port(), uuid)
)
.withHeader(X_TICKET_ID_HEADER, uuid))
);
server.stubFor(
get(urlPathEqualTo("/ticket/" + uuid))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withHeader(X_TICKET_ID_HEADER, uuid)
.withBody(format("{ \"uuid\": \"%s\" }", uuid))
)
);
}
示例3: before
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的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: beforeTestMethod
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的package包/類
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
if(wireMockAnnotation == null) {
return;
}
WireMockTest methodAnnotation = testContext.getTestMethod().getAnnotation(WireMockTest.class);
String stubPath = "";
if(this.wireMockAnnotation.stubPath() != null) {
stubPath = this.wireMockAnnotation.stubPath();
}
if (methodAnnotation != null && methodAnnotation.stubPath() != null) {
stubPath += "/" + methodAnnotation.stubPath();
}
ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) testContext
.getApplicationContext();
WireMockServer server = applicationContext.getBean(WireMockServer.class);
server.resetMappings();
if(! stubPath.isEmpty()) {
server.loadMappingsUsing(new JsonFileMappingsSource(new ClasspathFileSource(stubPath)));
}
}
示例5: startServers
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的package包/類
@PostConstruct
public void startServers() throws IOException {
WireMockConfiguration eurekaServerConfig = wireMockConfig()
.notifier(new ConsoleNotifier(true))
.port(HTTP_PORT)
.fileSource(new SingleRootFileSource("src/test/resources/mocks/default/eureka"));
eurekaServer = new WireMockServer(eurekaServerConfig);
eurekaServer.start();
WireMockConfiguration secureConfig = wireMockConfig()
.notifier(new ConsoleNotifier(true))
.httpsPort(HTTPS_PORT)
.fileSource(new SingleRootFileSource("src/test/resources/mocks/default/secure"));
secureServer = new WireMockServer(secureConfig);
secureServer.start();
}
示例6: testGet
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的package包/類
@Test
public void testGet() throws Exception {
WireMockServer server = startWireMockServer(WIRE_MOCK_PORT);
String maxJSON = "\"14\"";
stubFor(get(urlEqualTo("/api/visits/max")).willReturn(aResponse().withBody(maxJSON)));
Query query = getQueryFrom("rest-tests/sample.yaml", "Query2");
json.execute(query);
Assert.assertFalse(query.failed());
Assert.assertEquals(query.getResult().getColumns().size(), 1);
List<TypedObject> max = query.getResult().getColumn("max").getValues();
Assert.assertEquals(max.size(), 1);
Assert.assertEquals(max.get(0).data, 14L);
Assert.assertEquals(max.get(0).type, TypeSystem.Type.LONG);
server.stop();
}
示例7: addMappings
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的package包/類
private void addMappings(final WireMockServer wireMockServer) {
wireMockServer.addStubMapping(
get(urlPathMatching("/patients/[a-zA-Z0-9]+"))
.willReturn(
aResponse()
.withBody("Empty patient response")
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withHeader("Cache-Control", "no-cache")
.withTransformers(PatientResponseTransformer.PATIENT_RESPONSE_TRANSFORMER)
)
.build()
);
wireMockServer.addStubMapping(
post(urlPathMatching("/patients/[a-zA-Z0-9]+"))
.withHeader("Content-Type", matching("application/json"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Cache-Control", "no-cache")
)
.build()
);
}
示例8: testDeleteMonitoringCheck
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的package包/類
/**
* Test for {@link ModuleMonitoring#deleteMonitoringCheck(int)}.
*/
@TestTemplate
void testDeleteMonitoringCheck(WireMockServer wireMock, JiffyBoxApi api) {
wireMock.stubFor(delete(urlPathEqualTo("/00000000000000000000000000000000/v1.0/monitoring/1234")).willReturn
(aResponse()
.withHeaders(WireMockHelper.headers())
.withStatus(200)
.withBodyFile("modules/monitoring/testDeleteMonitoringCheck.json")));
Response<Boolean> response = api.monitoring().deleteMonitoringCheck(1234);
List<Message> messages = response.getMessages();
Message message = messages.get(0);
boolean result = response.getResult();
assertEquals("Der Monitoring-Check Test(M1234) wird geloescht", message.getMessageText());
assertEquals(MessageType.SUCCESS, message.getType());
assertTrue(result);
}
示例9: testGetStatus
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的package包/類
/**
* Test for {@link ModuleMonitoring#getStatus(int)}.
*/
@TestTemplate
void testGetStatus(WireMockServer wireMock, JiffyBoxApi api) {
wireMock.stubFor(get(urlPathEqualTo("/00000000000000000000000000000000/v1.0/monitoring/1234/status"))
.willReturn(aResponse()
.withHeaders(WireMockHelper.headers())
.withStatus(200)
.withBodyFile("modules/monitoring/testGetStatus.json")));
Response<Map<String, MonitoringStatus>> response = api.monitoring().getStatus(1234);
List<Message> messages = response.getMessages();
MonitoringStatus result = response.getResult().get("1234");
assertTrue(messages.isEmpty());
assertEquals(0, result.getCode());
assertEquals("OK - 123.45.67.89: rta 0.313ms, lost 0%", result.getResponse());
}
示例10: testGetStatuses
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的package包/類
/**
* Test for {@link ModuleMonitoring#getStatuses(String)}.
*/
@TestTemplate
void testGetStatuses(WireMockServer wireMock, JiffyBoxApi api) {
wireMock.stubFor(get(urlPathEqualTo("/00000000000000000000000000000000/v1.0/monitoring/123.45.67.89/status"))
.willReturn(aResponse()
.withHeaders(WireMockHelper.headers())
.withStatus(200)
.withBodyFile("modules/monitoring/testGetStatuses.json")));
Response<Map<String, MonitoringStatus>> response = api.monitoring().getStatuses("123.45.67.89");
List<Message> messages = response.getMessages();
Map<String, MonitoringStatus> result = response.getResult();
MonitoringStatus monitoringStatus1 = result.get("1234");
MonitoringStatus monitoringStatus2 = result.get("5678");
assertTrue(messages.isEmpty());
assertEquals(0, monitoringStatus1.getCode());
assertEquals("OK - 123.45.67.89: rta 0.313ms, lost 0%", monitoringStatus1.getResponse());
assertEquals(0, monitoringStatus2.getCode());
assertEquals("HTTP OK: Status line output matched "200" " + "-3827 bytes in 0.003 second response "
+ "time", monitoringStatus2
.getResponse());
}
示例11: testCreatePeriodicalBackups
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的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());
}
示例12: testUpdatePeriodicalBackups
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的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());
}
示例13: testDeletePeriodicalBackups
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的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);
}
示例14: testCreateManualBackup
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的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);
}
示例15: testDeleteBackup
import com.github.tomakehurst.wiremock.WireMockServer; //導入依賴的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);
}