Search in sources :

Example 1 with FatalStartupException

use of com.github.tomakehurst.wiremock.common.FatalStartupException in project devonfw-testing by devonfw.

the class DriverManagerTest method testWiremockServerStartTwoServersWithTheSameHttpPort.

@Test
public void testWiremockServerStartTwoServersWithTheSameHttpPort() {
    System.setProperty("mock_http_port", "8081");
    RuntimeParameters.MOCK_HTTP_PORT.refreshParameterValue();
    RuntimeParameters.MOCK_HTTPS_PORT.refreshParameterValue();
    WireMockServer driver1 = null;
    WireMockServer driver2 = null;
    DriverManager.closeDriverVirtualServer();
    try {
        // Start #1 server
        driver1 = DriverManager.getDriverVirtualService();
        assertTrue("Mock server does not run", driver1.isRunning());
        assertEquals("Mock server for http does not run o port 8081", 8081, driver1.port());
        assertTrue("Mock server for https does not run on random port", (Integer) driver1.httpsPort() instanceof Integer);
        // Enable to add new server instances in this thread. Simulation of multithread and bind to the same port
        DriverManager.clearAllDrivers();
        // Start #2 server
        driver2 = DriverManager.getDriverVirtualService();
        assertTrue("Mock server does not run", driver2.isRunning());
        assertEquals("Mock server for http does not run o port 8081", 8081, driver2.port());
        assertTrue("Mock server for https does not run on random port", (Integer) driver2.httpsPort() instanceof Integer);
    } catch (FatalStartupException e) {
        assertTrue("No information about bind error", e.getMessage().contains("Address already in use: bind"));
    } finally {
        // Close all drivers
        try {
            driver1.stop();
            driver2.stop();
        } catch (Exception e) {
        }
    }
}
Also used : FatalStartupException(com.github.tomakehurst.wiremock.common.FatalStartupException) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) FatalStartupException(com.github.tomakehurst.wiremock.common.FatalStartupException) Test(org.junit.Test)

Example 2 with FatalStartupException

use of com.github.tomakehurst.wiremock.common.FatalStartupException in project wiremock by wiremock.

the class WireMockServerRunner method run.

public void run(String... args) {
    CommandLineOptions options = new CommandLineOptions(args);
    if (options.help()) {
        out.println(options.helpText());
        return;
    }
    FileSource fileSource = options.filesRoot();
    fileSource.createIfNecessary();
    FileSource filesFileSource = fileSource.child(FILES_ROOT);
    filesFileSource.createIfNecessary();
    FileSource mappingsFileSource = fileSource.child(MAPPINGS_ROOT);
    mappingsFileSource.createIfNecessary();
    wireMockServer = new WireMockServer(options);
    if (options.recordMappingsEnabled()) {
        wireMockServer.enableRecordMappings(mappingsFileSource, filesFileSource);
    }
    if (options.specifiesProxyUrl()) {
        addProxyMapping(options.proxyUrl());
    }
    try {
        wireMockServer.start();
        boolean https = options.httpsSettings().enabled();
        if (!options.getHttpDisabled()) {
            options.setActualHttpPort(wireMockServer.port());
        }
        if (https) {
            options.setActualHttpsPort(wireMockServer.httpsPort());
        }
        if (!options.bannerDisabled()) {
            out.println(BANNER);
            out.println();
        } else {
            out.println();
            out.println("The WireMock server is started .....");
        }
        out.println(options);
    } catch (FatalStartupException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource) FatalStartupException(com.github.tomakehurst.wiremock.common.FatalStartupException) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer)

Aggregations

WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)2 FatalStartupException (com.github.tomakehurst.wiremock.common.FatalStartupException)2 FileSource (com.github.tomakehurst.wiremock.common.FileSource)1 Test (org.junit.Test)1