Search in sources :

Example 1 with ResponseTemplateTransformer

use of com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer in project irontest by zheng-wang.

the class IronTestApplication method run.

@Override
public void run(IronTestConfiguration configuration, Environment environment) throws IOException {
    final JdbiFactory jdbiFactory = new JdbiFactory();
    final Jdbi systemDBJdbi = jdbiFactory.build(environment, configuration.getSystemDatabase(), "systemDatabase");
    // compare system database version with uber jar version to see whether an upgrade is needed
    Integer versionTableCount = systemDBJdbi.withHandle(handle -> handle.createQuery("select count(*) from information_schema.tables where table_name = 'VERSION'").mapTo(Integer.class).findOnly());
    if (versionTableCount == 1) {
        // VERSION table exists in the system database (i.e. we are not starting a brand new Iron Test build)
        if (!checkVersion(systemDBJdbi)) {
            System.out.println("Press Enter to exit.");
            System.in.read();
            System.exit(0);
        }
    }
    // by 'new SSLContextBuilder().loadTrustMaterial').
    if (new File(configuration.getSslTrustStorePath()).exists()) {
        System.setProperty("javax.net.ssl.trustStore", configuration.getSslTrustStorePath());
        System.setProperty("javax.net.ssl.trustStorePassword", configuration.getSslTrustStorePassword());
    }
    // start WireMock server (in the same JVM)
    WireMockServer wireMockServer = new WireMockServer(options().extensions(new ResponseTemplateTransformer(true)).port(Integer.parseInt(configuration.getWireMock().get("port"))).maxRequestJournalEntries(Integer.parseInt(configuration.getWireMock().get("maxRequestJournalEntries"))).notifier(new WireMockFileNotifier()));
    wireMockServer.start();
    createSystemResources(configuration, environment, systemDBJdbi, wireMockServer);
    createSampleResources(configuration, environment);
    environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() {

        @Override
        public void serverStarted(Server server) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Iron Test started with UI address http://localhost:" + +getLocalPort(server) + "/ui");
            System.out.println();
        }
    });
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) JdbiFactory(io.dropwizard.jdbi3.JdbiFactory) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) Server(org.eclipse.jetty.server.Server) ServerLifecycleListener(io.dropwizard.lifecycle.ServerLifecycleListener) File(java.io.File) ResponseTemplateTransformer(com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer)

Aggregations

WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 ResponseTemplateTransformer (com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer)1 JdbiFactory (io.dropwizard.jdbi3.JdbiFactory)1 ServerLifecycleListener (io.dropwizard.lifecycle.ServerLifecycleListener)1 File (java.io.File)1 Server (org.eclipse.jetty.server.Server)1 Jdbi (org.jdbi.v3.core.Jdbi)1