package org.agoncal.book.javaee7.chapter02.ex19;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import static org.junit.Assert.assertTrue;
/**
* @author Antonio Goncalves
* APress Book - Beginning Java EE 7 with Glassfish 4
* http://www.apress.com/
* http://www.antoniogoncalves.org
* --
*/
public class DerbyPingService19IT {
// ======================================
// = Attributes =
// ======================================
protected static Weld weld;
protected static WeldContainer container;
// ======================================
// = Lifecycle Methods =
// ======================================
@BeforeClass
public static void init() {
weld = new Weld();
container = weld.initialize();
}
@AfterClass
public static void close() {
weld.shutdown();
}
// ======================================
// = Methods =
// ======================================
@Test
public void shouldPingDatabase() throws Exception {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:derby:memory:chapter02DB;create=true", "APP2", "APP");
conn.createStatement().executeQuery("SELECT 1 FROM SYSIBM.SYSDUMMY1");
conn.close();
}
@Test
public void shouldPingDatabaseWithDispose() throws Exception {
DerbyPingService19 pingService = container.instance().select(DerbyPingService19.class).get();
pingService.ping();
}
}