Java Code Examples for com.github.tomakehurst.wiremock.WireMockServer#port()

The following examples show how to use com.github.tomakehurst.wiremock.WireMockServer#port() . 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: WireMockBaseTest.java    From parsec-libraries with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: AuthenticatedRestTemplateTest.java    From mojito with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: VersionUtilTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCurrentVersion() throws Exception {
  //given
  final WireMockServer wireMockServer = new WireMockServer();
  wireMockServer
    .stubFor(
      get(urlMatching("/currentVersion.*"))
      .willReturn(aResponse()
      .withStatus(200)
      .withBody("currentVersion=1.2.3\n".getBytes()))
    );
  wireMockServer.start();

  final int port = wireMockServer.port();
  final VersionUtil versionUtil = new VersionUtil("http://localhost:" + port+"/currentVersion");
  final OtrosApplication otrosApplication = new OtrosApplication();
  otrosApplication.setConfiguration(new DataConfiguration(new BaseConfiguration()));
  otrosApplication.getConfiguration().setProperty(ConfKeys.UUID,"C9457787-AF59-4B9F-B4E8-FB75334EBEF8");

  //when
  final Optional<String> currentVersion = versionUtil.getCurrentVersion("1.2.3", Proxy.NO_PROXY, otrosApplication);
  wireMockServer.stop();

  //then
  assertEquals(currentVersion,Optional.of("1.2.3"));

}
 
Example 4
Source File: BaseHttpClientTest.java    From junit-servers with MIT License 5 votes vote down vote up
@BeforeEach
void setUp(WireMockServer wireMockServer) {
	scheme = "http";
	host = "localhost";
	port = wireMockServer.port();
	server = new EmbeddedServerMockBuilder()
		.withScheme(scheme)
		.withHost(host)
		.withPort(port)
		.build();
}
 
Example 5
Source File: ClientIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Before
public void setup() {
    wireMockServer = new WireMockServer(wireMockConfig().dynamicPort());
    wireMockServer.start();
    configureFor("localhost", wireMockServer.port());
    client = new Client("http://localhost:" + wireMockServer.port());
}
 
Example 6
Source File: WireMockConfiguration.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
private int port(WireMockServer server) {
	return server.isRunning() ? (server.getOptions().httpsSettings().enabled()
			? server.httpsPort() : server.port()) : -1;
}