src/test/java/ru/indvdum/jpa/tests/AbstractJPATest.java
changeset 5 ccb029c396aa
parent 2 f692598b3742
child 6 180decac2433
     1.1 --- a/src/test/java/ru/indvdum/jpa/tests/AbstractJPATest.java	Fri Nov 09 03:22:29 2012 +0400
     1.2 +++ b/src/test/java/ru/indvdum/jpa/tests/AbstractJPATest.java	Sat Nov 10 22:54:48 2012 +0400
     1.3 @@ -1,15 +1,8 @@
     1.4  package ru.indvdum.jpa.tests;
     1.5  
     1.6 -import java.util.ResourceBundle;
     1.7 -
     1.8 -import javax.naming.InitialContext;
     1.9 -import javax.naming.NamingException;
    1.10 -
    1.11 -import org.apache.commons.dbcp.BasicDataSource;
    1.12  import org.junit.BeforeClass;
    1.13  
    1.14 -import ru.indvdum.jpa.dao.PropertySelector;
    1.15 -import ru.indvdum.jpa.props.Props;
    1.16 +import ru.indvdum.jpa.init.DatabaseInitializer;
    1.17  
    1.18  /**
    1.19   * @author indvdum (gotoindvdum[at]gmail[dot]com)
    1.20 @@ -20,52 +13,7 @@
    1.21  
    1.22  	@BeforeClass
    1.23  	public static void setUpClass() throws Exception {
    1.24 -		if ("true".equalsIgnoreCase(System.getProperty("JPA.realDatabaseConnection"))) {
    1.25 -			initRealDatabase();
    1.26 -		} else {
    1.27 -			initDerby();
    1.28 -		}
    1.29 -	}
    1.30 -
    1.31 -	protected static String dataSource = null;
    1.32 -
    1.33 -	protected static String getDataSourceName() {
    1.34 -		if (dataSource != null)
    1.35 -			return dataSource;
    1.36 -
    1.37 -		if (dataSource == null)
    1.38 -			dataSource = System.getProperty(Props.DATA_SOURCE_PROPERTY);
    1.39 -		if (dataSource == null)
    1.40 -			dataSource = ResourceBundle.getBundle(Props.JPADAO_PROPERTY_FILE).getString(Props.DATA_SOURCE_PROPERTY);
    1.41 -		if (dataSource == null)
    1.42 -			dataSource = "jdbc/database";
    1.43 -		return dataSource;
    1.44 -	}
    1.45 -
    1.46 -	private static void initDerby() throws NamingException {
    1.47 -		System.setProperty("derby.stream.error.field", "java.lang.System.err");
    1.48 -
    1.49 -		InitialContext context = new InitialContext();
    1.50 -		BasicDataSource datasource = (BasicDataSource) context.lookup(getDataSourceName());
    1.51 -
    1.52 -		if (datasource == null) {
    1.53 -			datasource = new BasicDataSource();
    1.54 -			datasource.setUrl("jdbc:derby:memory:myDb;create=true");
    1.55 -			datasource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    1.56 -			datasource.setUsername("");
    1.57 -			datasource.setPassword("");
    1.58 -			datasource.setMaxActive(2);
    1.59 -
    1.60 -			context.bind(getDataSourceName(), datasource);
    1.61 -		}
    1.62 -
    1.63 -		PropertySelector.setSystemProperty(PropertySelector.RUNTIMEENHANCEMENT, "supported");
    1.64 -		PropertySelector.setSystemProperty(PropertySelector.SHOWSQL, "true");
    1.65 -		PropertySelector.setSystemProperty(PropertySelector.SYNCHRONIZEDB, "true");
    1.66 -	}
    1.67 -
    1.68 -	private static void initRealDatabase() throws NamingException {
    1.69 -		// TODO: need realize
    1.70 +		DatabaseInitializer.init();
    1.71  	}
    1.72  
    1.73  }