com.github.tomakehurst.wiremock.core.WireMockConfiguration Java Examples
The following examples show how to use
com.github.tomakehurst.wiremock.core.WireMockConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllureRestAssuredTest.java From allure-java with Apache License 2.0 | 6 votes |
protected final AllureResults execute() { RestAssured.replaceFiltersWith(new AllureRestAssured()); final WireMockServer server = new WireMockServer(WireMockConfiguration.options().dynamicPort()); return runWithinTestContext(() -> { server.start(); WireMock.configureFor(server.port()); WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/hello")).willReturn(WireMock.aResponse().withBody("some body"))); try { RestAssured.when().get(server.url("/hello")).then().statusCode(200); } finally { server.stop(); RestAssured.replaceFiltersWith(ImmutableList.of()); } }); }
Example #2
Source File: AllureRestTemplateTest.java From allure-java with Apache License 2.0 | 6 votes |
protected final AllureResults execute() { final RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); restTemplate.setInterceptors(Collections.singletonList(new AllureRestTemplate())); final WireMockServer server = new WireMockServer(WireMockConfiguration.options().dynamicPort()); return runWithinTestContext(() -> { server.start(); WireMock.configureFor(server.port()); WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/hello")).willReturn(WireMock.aResponse().withBody("some body"))); try { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<JsonNode> entity = new HttpEntity<>(headers); ResponseEntity<String> result = restTemplate.exchange(server.url("/hello"), HttpMethod.GET, entity, String.class); Assertions.assertEquals(result.getStatusCode(), HttpStatus.OK); } finally { server.stop(); } }); }
Example #3
Source File: WireMockAutoConfiguration.java From restdocs-wiremock with Apache License 2.0 | 6 votes |
@Bean @ConditionalOnMissingBean public WireMockConfiguration wireMockConfiguration(WireMockProperties properties) { WireMockConfiguration config = WireMockConfiguration.options(); if(properties.getPort() > 0) { log.info("Starting WireMock on port " + properties.getPort()); config.port(properties.getPort()); } else { log.info("Starting WireMock on dynamic port"); config.dynamicPort(); } if(properties.getStubPath() != null) { config.fileSource(new ClasspathFileSource(properties.getStubPath())); } config.extensions(new ResponseTemplateTransformer(false)); return config; }
Example #4
Source File: WireMockSpring.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
public static WireMockConfiguration options() { if (!initialized) { if (ClassUtils.isPresent("org.apache.http.conn.ssl.NoopHostnameVerifier", null)) { HttpsURLConnection .setDefaultHostnameVerifier(NoopHostnameVerifier.INSTANCE); try { HttpsURLConnection.setDefaultSSLSocketFactory(SSLContexts.custom() .loadTrustMaterial(null, TrustSelfSignedStrategy.INSTANCE) .build().getSocketFactory()); } catch (Exception e) { throw new AssertionError("Cannot install custom socket factory: [" + e.getMessage() + "]"); } } initialized = true; } return new WireMockConfiguration(); }
Example #5
Source File: WireMockBaseTest.java From parsec-libraries with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupServer() throws IOException { String rootDirPath = "parsec_wiremock_test"; File root = Files.createTempDirectory(rootDirPath).toFile(); new File(root, WireMockApp.MAPPINGS_ROOT).mkdirs(); new File(root, WireMockApp.FILES_ROOT).mkdirs(); wireMockServer = new WireMockServer( WireMockConfiguration.options() .dynamicPort() .fileSource(new SingleRootFileSource(rootDirPath)) ); wireMockServer.start(); wireMockBaseUrl = "http://localhost:"+wireMockServer.port(); WireMock.configureFor(wireMockServer.port()); }
Example #6
Source File: WireMockInitializer.java From blog-tutorials with MIT License | 6 votes |
@Override public void initialize(ConfigurableApplicationContext configurableApplicationContext) { WireMockServer wireMockServer = new WireMockServer(new WireMockConfiguration().dynamicPort()); wireMockServer.start(); configurableApplicationContext.getBeanFactory().registerSingleton("wireMockServer", wireMockServer); configurableApplicationContext.addApplicationListener(applicationEvent -> { if (applicationEvent instanceof ContextClosedEvent) { wireMockServer.stop(); } }); TestPropertyValues .of("todo_url:http://localhost:" + wireMockServer.port() + "/todos") .applyTo(configurableApplicationContext); }
Example #7
Source File: NettyClientTlsAuthTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws IOException { ClientTlsAuthTestBase.setUp(); // Will be used by both client and server to trust the self-signed // cert they present to each other System.setProperty("javax.net.ssl.trustStore", serverKeyStore.toAbsolutePath().toString()); System.setProperty("javax.net.ssl.trustStorePassword", STORE_PASSWORD); System.setProperty("javax.net.ssl.trustStoreType", "jks"); mockProxy = new WireMockServer(new WireMockConfiguration() .dynamicHttpsPort() .needClientAuth(true) .keystorePath(serverKeyStore.toAbsolutePath().toString()) .keystorePassword(STORE_PASSWORD)); mockProxy.start(); mockProxy.stubFor(get(urlPathMatching(".*")).willReturn(aResponse().withStatus(200).withBody("hello"))); proxyCfg = ProxyConfiguration.builder() .scheme("https") .host("localhost") .port(mockProxy.httpsPort()) .build(); keyManagersProvider = FileStoreTlsKeyManagersProvider.create(clientKeyStore, CLIENT_STORE_TYPE, STORE_PASSWORD); }
Example #8
Source File: WireMockHttpServerStub.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private WireMockConfiguration config() { if (ClassUtils.isPresent( "org.springframework.cloud.contract.wiremock.WireMockSpring", null)) { return WireMockSpring.options().extensions(responseTransformers()); } return new WireMockConfiguration().extensions(responseTransformers()); }
Example #9
Source File: AutoConfigureWireMockConfigurationCustomizerTests.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@Bean WireMockConfigurationCustomizer optionsCustomizer() { return new WireMockConfigurationCustomizer() { @Override public void customize(WireMockConfiguration options) { // end::customizer_1[] assertThat(options.portNumber()).isGreaterThan(0); Config.this.executed = true; // tag::customizer_2[] } }; }
Example #10
Source File: SetupTestsListener.java From heat with Apache License 2.0 | 5 votes |
/** * Starts a Wiremock server with specified configuration parameters. * @param bindAddress wiremock bind-address * @param wmRoot wiremock root directory that contains /mappings and /__files * @param wmPort wiremock exposed port */ public void runNewServer(String bindAddress, String wmRoot, String wmPort) { WireMockConfiguration config = options() .bindAddress(bindAddress) .withRootDirectory(wmRoot); if (wmPort != null && !"".equals(wmPort)) { Integer wmPortInt = Integer.valueOf(wmPort); config.port(wmPortInt); } wmServer = new WireMockServer(config); wmServer.start(); }
Example #11
Source File: MockOriginServer.java From styx with Apache License 2.0 | 5 votes |
private static HttpHandler mockHandler(String originId, WireMockApp wireMockApp, WireMockConfiguration defaultConfig) { return newHandler(originId, new StubRequestHandler( wireMockApp, new StubResponseRenderer( defaultConfig.filesRoot().child(FILES_ROOT), wireMockApp.getGlobalSettingsHolder(), new ProxyResponseRenderer( defaultConfig.proxyVia(), defaultConfig.httpsSettings().trustStore(), defaultConfig.shouldPreserveHostHeader(), defaultConfig.proxyHostHeader() ) ) )); }
Example #12
Source File: MockOriginServer.java From styx with Apache License 2.0 | 5 votes |
public static MockOriginServer create(String appId, String originId, int adminPort, HttpsConnectorConfig httpsConfig) { WireMockApp wireMockApp = wireMockApp(); InetServer adminServer = createAdminServer(originId, adminPort, wireMockApp); InetServer mockServer = HttpServers.createHttpsServer( "mock-stub-" + originId, httpsConfig, mockHandler(originId, wireMockApp, new WireMockConfiguration())); int serverPort = httpsConfig.port(); return new MockOriginServer(appId, originId, adminPort, serverPort, adminServer, mockServer); }
Example #13
Source File: MockOriginServer.java From styx with Apache License 2.0 | 5 votes |
public static MockOriginServer create(String appId, String originId, int adminPort, HttpConnectorConfig httpConfig) { WireMockApp wireMockApp = wireMockApp(); InetServer adminServer = createAdminServer(originId, adminPort, wireMockApp); InetServer mockServer = HttpServers.createHttpServer( "mock-stub-" + originId, httpConfig, mockHandler(originId, wireMockApp, new WireMockConfiguration())); int serverPort = httpConfig.port(); return new MockOriginServer(appId, originId, adminPort, serverPort, adminServer, mockServer); }
Example #14
Source File: FakeHttpServer.java From styx with Apache License 2.0 | 5 votes |
private FakeHttpServer(String appId, String originId, WireMockConfiguration wireMockConfiguration) { this.appId = appId; this.originId = originId; httpsSettings = wireMockConfiguration.httpsSettings(); server = new WireMockServer(wireMockConfiguration); if (httpsSettings.enabled()) { this.adminPort = wireMockConfiguration.portNumber(); this.serverPort = httpsSettings.port(); } else { this.adminPort = wireMockConfiguration.portNumber(); this.serverPort = wireMockConfiguration.portNumber(); } }
Example #15
Source File: FakeHttpServer.java From styx with Apache License 2.0 | 5 votes |
private static WireMockConfiguration wireMockPort(int port) { if (port == 0) { return wireMockConfig().dynamicPort(); } else { return wireMockConfig().port(port); } }
Example #16
Source File: TestHelper.java From synthea with Apache License 2.0 | 4 votes |
public static WireMockConfiguration wiremockOptions() { return WireMockConfiguration.options().port(5566); }
Example #17
Source File: FakeHttpServer.java From styx with Apache License 2.0 | 4 votes |
public static FakeHttpServer newHttpServer(String appId, String originId, WireMockConfiguration wireMockConfiguration) { return new FakeHttpServer(appId, originId, wireMockConfiguration); }
Example #18
Source File: FakeHttpServer.java From styx with Apache License 2.0 | 4 votes |
public static FakeHttpServer newHttpServer(String appId, String originId, WireMockConfiguration wireMockConfiguration) { return new FakeHttpServer(appId, originId, wireMockConfiguration); }
Example #19
Source File: WireMockHttpServerStubConfigurer.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
@Override public boolean isAccepted(Object httpStubConfiguration) { return httpStubConfiguration instanceof WireMockConfiguration; }
Example #20
Source File: FakeHttpServer.java From styx with Apache License 2.0 | 4 votes |
private FakeHttpServer(String appId, String originId, WireMockConfiguration wireMockConfiguration) { this.appId = appId; this.originId = originId; httpsSettings = wireMockConfiguration.httpsSettings(); server = new WireMockServer(wireMockConfiguration); }
Example #21
Source File: WireMockAutoConfiguration.java From restdocs-wiremock with Apache License 2.0 | 4 votes |
@Bean public WireMockServer wireMockServer(WireMockConfiguration config) { return new WireMockServer(config); }
Example #22
Source File: JSONTest.java From validatar with Apache License 2.0 | 4 votes |
private WireMockServer startWireMockServer(int port) { WireMockServer server = new WireMockServer(WireMockConfiguration.wireMockConfig().port(port)); server.start(); WireMock.configureFor(port); return server; }
Example #23
Source File: WireMockExtension.java From spring-data-dev-tools with Apache License 2.0 | 4 votes |
public WireMockExtension(WireMockConfiguration configuration) { super(configuration); this.configuration = configuration; }
Example #24
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 4 votes |
@BeforeClass private void setUpWireMockServer() throws IOException { this.wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()); this.wireMockServer.start(); this.serverPort = wireMockServer.port(); WireMock.configureFor(this.serverPort); String pathFile = FileUtils.readFileToString(new File("src/test/resources/valid_oas3.yaml")); WireMock.stubFor(get(urlPathMatching("/valid/yaml")) .willReturn(aResponse() .withStatus(HttpURLConnection.HTTP_OK) .withHeader("Content-type", "application/yaml") .withBody(pathFile .getBytes(StandardCharsets.UTF_8)))); pathFile = FileUtils.readFileToString(new File("src/test/resources/invalid_oas3.yaml")); WireMock.stubFor(get(urlPathMatching("/invalid/yaml")) .willReturn(aResponse() .withStatus(HttpURLConnection.HTTP_OK) .withHeader("Content-type", "application/yaml") .withBody(pathFile .getBytes(StandardCharsets.UTF_8)))); pathFile = FileUtils.readFileToString(new File("src/test/resources/valid_swagger2.yaml")); WireMock.stubFor(get(urlPathMatching("/validswagger/yaml")) .willReturn(aResponse() .withStatus(HttpURLConnection.HTTP_OK) .withHeader("Content-type", "application/yaml") .withBody(pathFile .getBytes(StandardCharsets.UTF_8)))); pathFile = FileUtils.readFileToString(new File("src/test/resources/invalid_swagger2.yaml")); WireMock.stubFor(get(urlPathMatching("/invalidswagger/yaml")) .willReturn(aResponse() .withStatus(HttpURLConnection.HTTP_OK) .withHeader("Content-type", "application/yaml") .withBody(pathFile .getBytes(StandardCharsets.UTF_8)))); }