Permalink
Browse files

Tidy meta data and re-org test

  • Loading branch information...
1 parent 90bc79c commit 5766bc386fc79bcafbb7eb1818701d6aba32e9b8 @dsyer dsyer committed Feb 16, 2011
View
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry kind="src" path="src/test/resources"/>
- <classpathentry kind="src" path="src/test/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="org.eclipse.jst.component.nondependency" value=""/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
View
@@ -1,2 +1,6 @@
/target
/bin
+.project
+.classpath
+.settings
+
View
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.springframework.tenancy</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.wst.common.project.facet.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- </natures>
-</projectDescription>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,57 +0,0 @@
-#Mon Nov 22 10:42:40 PST 2010
-eclipse.preferences.version=1
-editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
-formatter_profile=_ProjectFormatting
-formatter_settings_version=11
-sp_cleanup.add_default_serial_version_id=true
-sp_cleanup.add_generated_serial_version_id=false
-sp_cleanup.add_missing_annotations=true
-sp_cleanup.add_missing_deprecated_annotations=true
-sp_cleanup.add_missing_methods=false
-sp_cleanup.add_missing_nls_tags=false
-sp_cleanup.add_missing_override_annotations=true
-sp_cleanup.add_missing_override_annotations_interface_methods=true
-sp_cleanup.add_serial_version_id=false
-sp_cleanup.always_use_blocks=true
-sp_cleanup.always_use_parentheses_in_expressions=false
-sp_cleanup.always_use_this_for_non_static_field_access=false
-sp_cleanup.always_use_this_for_non_static_method_access=false
-sp_cleanup.convert_to_enhanced_for_loop=false
-sp_cleanup.correct_indentation=false
-sp_cleanup.format_source_code=true
-sp_cleanup.format_source_code_changes_only=false
-sp_cleanup.make_local_variable_final=false
-sp_cleanup.make_parameters_final=false
-sp_cleanup.make_private_fields_final=true
-sp_cleanup.make_type_abstract_if_missing_method=false
-sp_cleanup.make_variable_declarations_final=true
-sp_cleanup.never_use_blocks=false
-sp_cleanup.never_use_parentheses_in_expressions=true
-sp_cleanup.on_save_use_additional_actions=false
-sp_cleanup.organize_imports=true
-sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
-sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
-sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
-sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
-sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
-sp_cleanup.remove_private_constructors=true
-sp_cleanup.remove_trailing_whitespaces=false
-sp_cleanup.remove_trailing_whitespaces_all=true
-sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
-sp_cleanup.remove_unnecessary_casts=true
-sp_cleanup.remove_unnecessary_nls_tags=false
-sp_cleanup.remove_unused_imports=false
-sp_cleanup.remove_unused_local_variables=false
-sp_cleanup.remove_unused_private_fields=true
-sp_cleanup.remove_unused_private_members=false
-sp_cleanup.remove_unused_private_methods=true
-sp_cleanup.remove_unused_private_types=true
-sp_cleanup.sort_members=false
-sp_cleanup.sort_members_all=false
-sp_cleanup.use_blocks=false
-sp_cleanup.use_blocks_only_for_return_and_throw=false
-sp_cleanup.use_parentheses_in_expressions=false
-sp_cleanup.use_this_for_non_static_field_access=false
-sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
-sp_cleanup.use_this_for_non_static_method_access=false
-sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
@@ -1,4 +0,0 @@
-#Tue Jan 25 13:20:32 PST 2011
-eclipse.preferences.version=1
-project.repository.kind=com.tasktop.alm.tasks
-project.repository.url=http\://q.tasktop.com/alm/s/code2cloud/tasks
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-modules id="moduleCoreId" project-version="1.5.0">
- <wb-module deploy-name="org.springframework.tenancy">
- <wb-resource deploy-path="/" source-path="/src/main/java"/>
- <wb-resource deploy-path="/" source-path="/src/test/resources"/>
- <wb-resource deploy-path="/" source-path="/src/test/java"/>
- </wb-module>
-</project-modules>
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<faceted-project>
- <installed facet="java" version="1.6"/>
- <installed facet="jst.utility" version="1.0"/>
-</faceted-project>
View
90 pom.xml
@@ -2,37 +2,42 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>org.springframework</groupId>
+ <groupId>org.springframework.tenancy</groupId>
<artifactId>spring-tenancy</artifactId>
- <version>3.0.6-SNAPSHOT</version>
+ <version>1.0.0.BUILD-SNAPSHOT</version>
<packaging>jar</packaging>
- <name>multi tenant framework</name>
-
+ <name>Spring Multi Tenant Framework</name>
+
<properties>
<spring.framework.version>3.0.5.RELEASE</spring.framework.version>
</properties>
-
- <repositories>
+
+ <profiles>
+ <profile>
+ <id>bootstrap</id>
+ <repositories>
+ <repository>
+ <id>spring-tenancy</id>
+ <name>Spring Tenancy</name>
+ <url>http://code2cloud.tasktop.com/alm/s/spring-tenancy/maven/</url>
+ </repository>
+ <repository>
+ <id>EclipseLink Repo</id>
+ <name>EclipseLink Repository</name>
+ <url>http://mirror.csclub.uwaterloo.ca/eclipse/rt/eclipselink/maven.repo/</url>
+ </repository>
+ </repositories>
+ </profile>
+ </profiles>
+
+ <distributionManagement>
<repository>
- <id>spring-tenancy</id>
- <name>Spring Tenancy</name>
- <url>http://code2cloud.tasktop.com/alm/s/spring-tenancy/maven/</url>
+ <id>code2cloud-spring-tenacy</id>
+ <name>Spring Tenancy Code2Cloud Repo</name>
+ <url>dav:http://code2cloud.tasktop.com/alm/s/spring-tenancy/maven/</url>
</repository>
- <repository>
- <id>EclipseLink Repo</id>
- <name>EclipseLink Repository</name>
- <url>http://mirror.csclub.uwaterloo.ca/eclipse/rt/eclipselink/maven.repo/</url>
- </repository>
- </repositories>
-
- <distributionManagement>
- <repository>
- <id>code2cloud-spring-tenacy</id>
- <name>Spring Tenancy Code2Cloud Repo</name>
- <url>dav:http://code2cloud.tasktop.com/alm/s/spring-tenancy/maven/</url>
- </repository>
- </distributionManagement>
-
+ </distributionManagement>
+
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
@@ -56,9 +61,15 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.7</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -109,9 +120,18 @@
<version>2.0.0</version>
<scope>test</scope>
</dependency>
-
</dependencies>
-
+
+ <url>http://code2cloud.tasktop.com/alm/#projects/spring-tenancy</url>
+ <issueManagement>
+ <system>Code2Cloud</system>
+ <url>http://code2cloud.tasktop.com/alm/#projects/spring-tenancy</url>
+ </issueManagement>
+ <scm>
+ <developerConnection>git@github.com:SpringSource/spring-tenancy.git</developerConnection>
+ <url>http://github.com/SpringSource/spring-tenancy</url>
+ </scm>
+
<build>
<plugins>
<plugin>
@@ -123,13 +143,13 @@
</configuration>
</plugin>
</plugins>
- <extensions>
- <extension>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-webdav-jackrabbit</artifactId>
- <version>1.0-beta-6</version>
- </extension>
- </extensions>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-webdav-jackrabbit</artifactId>
+ <version>1.0-beta-6</version>
+ </extension>
+ </extensions>
</build>
-
+
</project>
@@ -1,7 +1,5 @@
package org.springframework.tenancy.datasource;
-import java.sql.SQLException;
-
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@@ -10,14 +8,20 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.annotation.Rollback;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.transaction.BeforeTransaction;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration({ "/applicationContext-testDBSwitching.xml" })
-@Transactional()
+@ContextConfiguration
+@Transactional
+@DirtiesContext
public class DatabaseSwitchingDataSourceTest {
@PersistenceContext
@@ -27,50 +31,47 @@
private BasicDataSource dataSource;
@Autowired
+ private PlatformTransactionManager transactionManager;
+
+ @Autowired
private ThreadlocalDatabaseSwitchingDataSource switchingDataSource;
+ private static boolean initialized;
+
private final String DB1 = "DB1";
private final String DB2 = "DB2";
private final String CREATE_TABLE_STMT = "CREATE TABLE DOMAINOBJECT (ID INTEGER PRIMARY KEY, STRING CHAR(50)) GRANT ALL ON DOMAINOBJECT TO SA;";
- // I don't really want this to be a test, just a before that does not run under a transaction, however, I can't make
- // that work (@BeforeTransaction). This means that we must run all tests in the class.
- @Rollback(false)
- @Test
- public void setupDB1() throws SQLException {
- dataSource.getConnection().createStatement().execute("create schema " + DB1 + " " + CREATE_TABLE_STMT);
+ @BeforeTransaction
+ public void setUpDatabases() throws Exception {
- switchingDataSource.setDatabaseName(DB1);
- DomainObject do1 = getMockDomainObject("db1");
- entityManager.persist(do1);
- DomainObject result = (DomainObject) entityManager.createQuery("select do from DomainObject do;")
- .getResultList().get(0);
- Assert.assertNotNull(result);
- Assert.assertEquals("db1", result.getString());
- entityManager.flush();
+ if (!initialized) {
- }
+ initialized = true;
- // I don't really want this to be a test, just a before that does not run under a transaction, however, I can't make
- // that work (@BeforeTransaction). This means that we must run all tests in the class.
- @Rollback(false)
- @Test
- public void setupDB2() throws SQLException {
- dataSource.getConnection().createStatement().execute("create schema " + DB2 + " " + CREATE_TABLE_STMT);
+ dataSource.getConnection().createStatement().execute("create schema " + DB1 + " " + CREATE_TABLE_STMT);
+ dataSource.getConnection().createStatement().execute("create schema " + DB2 + " " + CREATE_TABLE_STMT);
- switchingDataSource.setDatabaseName(DB2);
- entityManager.persist(getMockDomainObject("db2"));
- DomainObject result = (DomainObject) entityManager.createQuery("select do from DomainObject do;")
- .getResultList().get(0);
- Assert.assertNotNull(result);
- Assert.assertEquals("db2", result.getString());
- entityManager.flush();
+ new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
+ public Void doInTransaction(TransactionStatus status) {
+ setUpData(DB1, "db1");
+ return null;
+ }
+ });
+ new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
+ public Void doInTransaction(TransactionStatus status) {
+ setUpData(DB2, "db2");
+ return null;
+ }
+ });
+
+ }
}
@Test
- public void testGetFromD2() {
+ public void testGetFromDB2() {
switchingDataSource.setDatabaseName(DB2);
DomainObject result = (DomainObject) entityManager.createQuery("select do from DomainObject do;")
.getResultList().get(0);
@@ -89,6 +90,19 @@ public void testGetFromDB1() {
private static long nextId = 1;
+ private void setUpData(String databaseName, String objectName) {
+
+ switchingDataSource.setDatabaseName(databaseName);
+ DomainObject do1 = getMockDomainObject(objectName);
+ entityManager.persist(do1);
+ DomainObject result = (DomainObject) entityManager.createQuery("select do from DomainObject do;")
+ .getResultList().get(0);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(objectName, result.getString());
+ entityManager.flush();
+
+ }
+
private DomainObject getMockDomainObject(String data) {
DomainObject result = new DomainObject();
result.setId(nextId++);
Oops, something went wrong.

0 comments on commit 5766bc3

Please sign in to comment.