You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2013/11/17 09:31:57 UTC
svn commit: r1542660 - in /cayenne/main/trunk:
cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ConnectionProperties.java
cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataSourceInfoProvider.java
pom.xml
Author: aadamchik
Date: Sun Nov 17 08:31:56 2013
New Revision: 1542660
URL: http://svn.apache.org/r1542660
Log:
refactoring garbage test bootstrap code, fixing pom arguments formatting
Modified:
cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ConnectionProperties.java
cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataSourceInfoProvider.java
cayenne/main/trunk/pom.xml
Modified: cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ConnectionProperties.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ConnectionProperties.java?rev=1542660&r1=1542659&r2=1542660&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ConnectionProperties.java (original)
+++ cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ConnectionProperties.java Sun Nov 17 08:31:56 2013
@@ -32,13 +32,17 @@ import java.util.Map;
import org.apache.cayenne.conn.DataSourceInfo;
import org.apache.commons.collections.ExtendedProperties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
- * ConnectionProperties handles a set of DataSourceInfo objects using information stored
- * in $HOME/.cayenne/connection.properties. As of now this is purely a utility class. Its
- * features are not used in deployment.
+ * ConnectionProperties handles a set of DataSourceInfo objects using
+ * information stored in $HOME/.cayenne/connection.properties. As of now this is
+ * purely a utility class. Its features are not used in deployment.
*/
class ConnectionProperties {
+
+ private static final Log logger = LogFactory.getLog(ConnectionProperties.class);
public static final String EMBEDDED_DATASOURCE = "internal_embedded_datasource";
public static final String EMBEDDED_DATASOURCE_DBADAPTER = "org.apache.cayenne.dba.hsqldb.HSQLDBAdapter";
@@ -76,7 +80,8 @@ class ConnectionProperties {
return sharedInstance;
}
- // CayenneUserDir is defined in the Modeler, not accessible here, so hardcoding it for
+ // CayenneUserDir is defined in the Modeler, not accessible here, so
+ // hardcoding it for
// the tests
private static File cayenneUserDir() {
File homeDir = new File(System.getProperty("user.home"));
@@ -98,76 +103,59 @@ class ConnectionProperties {
String url = System.getProperty(URL_KEY_MAVEN);
String driver = System.getProperty(DRIVER_KEY_MAVEN);
+ String connectionKey = System.getProperty(ServerCaseDataSourceInfoProvider.CONNECTION_NAME_KEY);
File f = new File(cayenneUserDir(), PROPERTIES_FILE);
try {
if (f.exists()) {
+
+ logger.info("Found connection properties at " + f.getAbsolutePath());
- ConnectionProperties cp = new ConnectionProperties(
- new ExtendedProperties(f.getAbsolutePath()));
+ ConnectionProperties cp = new ConnectionProperties(new ExtendedProperties(f.getAbsolutePath()));
- if (((adapter != null && !adapter.startsWith("$"))
- || (usr != null && !usr.startsWith("$"))
- || (pass != null && !pass.startsWith("$"))
- || (url != null && !url.startsWith("$")) || (driver != null && !driver
- .startsWith("$")))
- && (System.getProperty("cayenneTestConnection") != null && !System
- .getProperty("cayenneTestConnection")
- .equals("null"))) {
+ if (((adapter != null && !adapter.startsWith("$")) || (usr != null && !usr.startsWith("$"))
+ || (pass != null && !pass.startsWith("$")) || (url != null && !url.startsWith("$")) || (driver != null && !driver
+ .startsWith("$"))) && (connectionKey != null && !connectionKey.equals("null"))) {
DataSourceInfo dsiOld = null;
- if (connectionInfos.get(System.getProperty("cayenneTestConnection")) != null) {
- dsiOld = connectionInfos.get(System
- .getProperty("cayenneTestConnection"));
- connectionInfos.remove(System
- .getProperty("cayenneTestConnection"));
+ if (connectionInfos.get(connectionKey) != null) {
+ dsiOld = connectionInfos.get(connectionKey);
+ connectionInfos.remove(connectionKey);
}
if (adapter != null && !adapter.startsWith("$")) {
dsi.setAdapterClassName(adapter);
- }
- else if (dsiOld != null) {
+ } else if (dsiOld != null) {
dsi.setAdapterClassName(dsiOld.getAdapterClassName());
}
if (usr != null && !usr.startsWith("$")) {
dsi.setUserName(usr);
- }
- else if (dsiOld != null) {
+ } else if (dsiOld != null) {
dsi.setUserName(dsiOld.getUserName());
}
if (pass != null && !pass.startsWith("$")) {
dsi.setPassword(pass);
- }
- else if (dsiOld != null) {
+ } else if (dsiOld != null) {
dsi.setPassword(dsiOld.getPassword());
}
if (url != null && !url.startsWith("$")) {
dsi.setDataSourceUrl(url);
- }
- else if (dsiOld != null) {
+ } else if (dsiOld != null) {
dsi.setDataSourceUrl(dsiOld.getDataSourceUrl());
}
if (driver != null && !driver.startsWith("$")) {
dsi.setJdbcDriver(driver);
- }
- else if (dsiOld != null) {
+ } else if (dsiOld != null) {
dsi.setJdbcDriver(dsiOld.getJdbcDriver());
}
- connectionInfos.put(System.getProperty("cayenneTestConnection"), dsi);
- }
- else {
+ connectionInfos.put(connectionKey, dsi);
+ } else {
return cp;
}
- }
- else {
- if (((adapter != null && !adapter.startsWith("$"))
- || (usr != null && !usr.startsWith("$"))
- || (pass != null && !pass.startsWith("$"))
- || (url != null && !url.startsWith("$")) || (driver != null && !driver
- .startsWith("$")))
- && (System.getProperty("cayenneTestConnection") != null && !System
- .getProperty("cayenneTestConnection")
- .equals("null"))) {
+ } else {
+ if (((adapter != null && !adapter.startsWith("$")) || (usr != null && !usr.startsWith("$"))
+ || (pass != null && !pass.startsWith("$")) || (url != null && !url.startsWith("$")) || (driver != null && !driver
+ .startsWith("$"))) && (connectionKey != null && !connectionKey.equals("null"))) {
if (adapter != null && !adapter.startsWith("$")) {
dsi.setAdapterClassName(adapter);
@@ -184,15 +172,15 @@ class ConnectionProperties {
if (driver != null && !driver.startsWith("$")) {
dsi.setJdbcDriver(driver);
}
- connectionInfos.put(System.getProperty("cayenneTestConnection"), dsi);
+ connectionInfos.put(connectionKey, dsi);
}
- // lets touch this file so that users would get a clue of what it is
+ // lets touch this file so that users would get a clue of what
+ // it is
createSamplePropertiesFile(f);
}
- }
- catch (IOException e) {
+ } catch (IOException e) {
// ignoring
}
@@ -213,9 +201,7 @@ class ConnectionProperties {
out.write("#");
out.newLine();
- out.write("# example1."
- + ADAPTER_KEY
- + " = org.apache.cayenne.dba.mysql.MySQLAdapter");
+ out.write("# example1." + ADAPTER_KEY + " = org.apache.cayenne.dba.mysql.MySQLAdapter");
out.newLine();
out.write("# example1." + USER_NAME_KEY + " = some_user");
out.newLine();
@@ -229,9 +215,7 @@ class ConnectionProperties {
// example 2
out.write("#");
out.newLine();
- out.write("# example2."
- + ADAPTER_KEY
- + " = org.apache.cayenne.dba.mysql.MySQLAdapter");
+ out.write("# example2." + ADAPTER_KEY + " = org.apache.cayenne.dba.mysql.MySQLAdapter");
out.newLine();
out.write("# example2." + USER_NAME_KEY + " = some_user");
out.newLine();
@@ -241,8 +225,7 @@ class ConnectionProperties {
out.newLine();
out.write("# example2." + DRIVER_KEY + " = com.mysql.jdbc.Driver");
out.newLine();
- }
- finally {
+ } finally {
out.close();
}
}
@@ -258,8 +241,8 @@ class ConnectionProperties {
}
/**
- * Returns DataSourceInfo object for a symbolic name. If name does not match an
- * existing object, returns null.
+ * Returns DataSourceInfo object for a symbolic name. If name does not match
+ * an existing object, returns null.
*/
public DataSourceInfo getConnectionInfo(String name) {
Modified: cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataSourceInfoProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataSourceInfoProvider.java?rev=1542660&r1=1542659&r2=1542660&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataSourceInfoProvider.java (original)
+++ cayenne/main/trunk/cayenne-core/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataSourceInfoProvider.java Sun Nov 17 08:31:56 2013
@@ -26,29 +26,24 @@ import org.apache.commons.logging.LogFac
public class ServerCaseDataSourceInfoProvider implements Provider<DataSourceInfo> {
- private static final String CONNECTION_NAME_KEY = "cayenneTestConnection";
+ static final String CONNECTION_NAME_KEY = "cayenneTestConnection";
private static final String DEFAULT_CONNECTION_KEY = "internal_embedded_datasource";
private static Log logger = LogFactory.getLog(ServerCaseDataSourceInfoProvider.class);
+ @Override
public DataSourceInfo get() throws ConfigurationException {
String connectionKey = System.getProperty(CONNECTION_NAME_KEY);
- DataSourceInfo connectionInfo = ConnectionProperties
- .getInstance()
- .getConnectionInfo(connectionKey);
+ DataSourceInfo connectionInfo = ConnectionProperties.getInstance().getConnectionInfo(connectionKey);
// attempt default if invalid key is specified
if (connectionInfo == null) {
- logger.info("Invalid connection key '"
- + connectionKey
- + "', trying default: "
- + DEFAULT_CONNECTION_KEY);
+ logger.info("Invalid connection key '" + connectionKey + "', trying default: " + DEFAULT_CONNECTION_KEY);
- connectionInfo = ConnectionProperties.getInstance().getConnectionInfo(
- DEFAULT_CONNECTION_KEY);
+ connectionInfo = ConnectionProperties.getInstance().getConnectionInfo(DEFAULT_CONNECTION_KEY);
}
if (connectionInfo == null) {
Modified: cayenne/main/trunk/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/pom.xml?rev=1542660&r1=1542659&r2=1542660&view=diff
==============================================================================
--- cayenne/main/trunk/pom.xml (original)
+++ cayenne/main/trunk/pom.xml Sun Nov 17 08:31:56 2013
@@ -735,9 +735,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
- -DcayenneTestConnection=${cayenneTestConnection}
- -Djava.net.preferIPv4Stack=true
- -Dcayenne.runtime.db.collation.assume.ci=${collationCi}
+ -DcayenneTestConnection=${cayenneTestConnection} -Djava.net.preferIPv4Stack=true -Dcayenne.runtime.db.collation.assume.ci=${collationCi}
</argLine>
<systemPropertyVariables>
<property>