當前位置: 首頁>>代碼示例>>Java>>正文


Java WireMockServer類代碼示例

本文整理匯總了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)));
}
 
開發者ID:bonigarcia,項目名稱:mastering-junit5,代碼行數:23,代碼來源:RemoteFileTest.java

示例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))
                    )
    );
}
 
開發者ID:lanwen,項目名稱:wiremock-junit5,代碼行數:26,代碼來源:TicketEndpoint.java

示例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);
}
 
開發者ID:box,項目名稱:mojito,代碼行數:17,代碼來源:AuthenticatedRestTemplateTest.java

示例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)));
	}
}
 
開發者ID:ePages-de,項目名稱:restdocs-wiremock,代碼行數:25,代碼來源:WireMockListener.java

示例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();

}
 
開發者ID:ordina-jworks,項目名稱:microservices-dashboard-server,代碼行數:18,代碼來源:InMemoryDefaultWireMock.java

示例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();
}
 
開發者ID:yahoo,項目名稱:validatar,代碼行數:20,代碼來源:JSONTest.java

示例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()
    );
}
 
開發者ID:webdizz,項目名稱:web-scale-perf-testing,代碼行數:25,代碼來源:PatientApiServer.java

示例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);
}
 
開發者ID:jschlichtholz,項目名稱:jiffybox,代碼行數:23,代碼來源:ModuleMonitoringTest.java

示例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());
}
 
開發者ID:jschlichtholz,項目名稱:jiffybox,代碼行數:21,代碼來源:ModuleMonitoringTest.java

示例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 &quot;200&quot; " + "-3827 bytes in 0.003 second response "
            + "time", monitoringStatus2
            .getResponse());
}
 
開發者ID:jschlichtholz,項目名稱:jiffybox,代碼行數:29,代碼來源:ModuleMonitoringTest.java

示例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());
}
 
開發者ID:jschlichtholz,項目名稱:jiffybox,代碼行數:22,代碼來源:ModuleBackupsTest.java

示例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());
}
 
開發者ID:jschlichtholz,項目名稱:jiffybox,代碼行數:22,代碼來源:ModuleBackupsTest.java

示例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);
}
 
開發者ID:jschlichtholz,項目名稱:jiffybox,代碼行數:19,代碼來源:ModuleBackupsTest.java

示例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);
}
 
開發者ID:jschlichtholz,項目名稱:jiffybox,代碼行數:21,代碼來源:ModuleBackupsTest.java

示例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);
}
 
開發者ID:jschlichtholz,項目名稱:jiffybox,代碼行數:20,代碼來源:ModuleBackupsTest.java


注:本文中的com.github.tomakehurst.wiremock.WireMockServer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。