Search in sources :

Example 1 with JdbiFactory

use of io.dropwizard.jdbi3.JdbiFactory 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)

Example 2 with JdbiFactory

use of io.dropwizard.jdbi3.JdbiFactory in project irontest by zheng-wang.

the class IronTestApplication method createSampleResources.

private void createSampleResources(IronTestConfiguration configuration, Environment environment) {
    final JdbiFactory jdbiFactory = new JdbiFactory();
    final Jdbi jdbi = jdbiFactory.build(environment, configuration.getSampleDatabase(), "sampleDatabase");
    // create DAO objects
    final ArticleDAO articleDAO = jdbi.onDemand(ArticleDAO.class);
    // create database tables
    articleDAO.createTableIfNotExists();
    articleDAO.insertArticle1IfNotExists();
    // register APIs
    environment.jersey().register(new ArticleResource(articleDAO));
    // register SOAP web services
    jaxWsBundle.publishEndpoint(new EndpointBuilder("/article", new ArticleSOAP(articleDAO)));
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) JdbiFactory(io.dropwizard.jdbi3.JdbiFactory) EndpointBuilder(com.roskart.dropwizard.jaxws.EndpointBuilder) ArticleSOAP(io.irontest.ws.ArticleSOAP)

Aggregations

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