Started work on componentizing the current user management.
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Mon, 12 May 2008 22:50:02 +0000 (22:50 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Mon, 12 May 2008 22:50:02 +0000 (22:50 +0000)
Also fixed several bugs in SpringComponent.

security/pom.xml
security/src/test/java/org/wamblee/usermgt/hibernate/ExternalDatasourceComponent.java [new file with mode: 0644]
security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java [new file with mode: 0644]
security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java
security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java [new file with mode: 0644]
security/src/test/resources/spring/test.org.wamblee.security.datasource.xml

index 140a904bcb6626cc7eaa0cefe36c54b4ed5f7bc9..d213638c672a04713efb2b7ec131ff9de7bfead1 100644 (file)
@@ -15,7 +15,7 @@
   <name>wamblee.org security</name>
   <url>http://wamblee.org</url>
   <dependencies>
-    
+
     <dependency>
       <groupId>org.wamblee</groupId>
       <artifactId>wamblee-support-general</artifactId>
       <type>test-jar</type>
       <version>0.2-SNAPSHOT</version>
     </dependency>
-   <dependency>
+    <dependency>
+      <groupId>org.wamblee</groupId>
+      <artifactId>wamblee-system-spring</artifactId>
+      <version>0.2-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.wamblee</groupId>
+      <artifactId>wamblee-system-spring</artifactId>
+      <type>test-jar</type>
+      <version>0.2-SNAPSHOT</version>
+    </dependency>
+    <dependency>
       <groupId>org.wamblee</groupId>
       <artifactId>wamblee-support-spring</artifactId>
       <version>0.2-SNAPSHOT</version>
@@ -44,7 +55,7 @@
       <artifactId>wamblee-hibernate-jpa</artifactId>
       <version>0.2-SNAPSHOT</version>
     </dependency>
-    
+
     <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
@@ -53,7 +64,7 @@
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
     </dependency>
-   
+
     <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-beans</artifactId>
@@ -78,7 +89,7 @@
       <version>1.1</version>
       <scope>test</scope>
     </dependency>
+
   </dependencies>
 
 </project>
diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/ExternalDatasourceComponent.java b/security/src/test/java/org/wamblee/usermgt/hibernate/ExternalDatasourceComponent.java
new file mode 100644 (file)
index 0000000..490c230
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2008 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.usermgt.hibernate;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+
+import javax.sql.DataSource;
+
+import org.springframework.core.io.ClassPathResource;
+import org.wamblee.system.core.DefaultProvidedInterface;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.spring.SpringComponent;
+
+public class ExternalDatasourceComponent extends SpringComponent {
+
+    private static final String DATABASE_PROPERTIES = "properties/test.org.wamblee.security.database.properties";
+    private static final String DATASOURCE_SPRING_CONFIG = "spring/test.org.wamblee.security.datasource.xml";
+
+    public ExternalDatasourceComponent(String aName) throws IOException {
+        super(
+                aName,
+                new String[] { DATASOURCE_SPRING_CONFIG },
+                createProvidedMap(), new TreeMap<RequiredInterface, String>());
+        Properties props = new Properties(); 
+        props.load(new ClassPathResource(DATABASE_PROPERTIES).getInputStream());
+        for (Object key: props.keySet()) { 
+            System.out.println("Key " + key + " value " + props.getProperty((String)key));
+        }
+        addProperties(props);
+    }
+
+    private static Map<String, ProvidedInterface> createProvidedMap() {
+        Map<String, ProvidedInterface> provided = new TreeMap<String, ProvidedInterface>();
+        provided.put("dataSource", new DefaultProvidedInterface("datasource",
+                DataSource.class));
+        return provided;
+    }
+
+}
diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java
new file mode 100644 (file)
index 0000000..b4c69ea
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2008 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package org.wamblee.usermgt.hibernate;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+
+import javax.sql.DataSource;
+
+import org.hibernate.SessionFactory;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.orm.hibernate3.HibernateTemplate;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.wamblee.system.core.DefaultProvidedInterface;
+import org.wamblee.system.core.DefaultRequiredInterface;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.spring.SpringComponent;
+
+public class HibernateComponent extends SpringComponent {
+
+    private static final String HIBERNATE_PROPERTIES = "properties/test.org.wamblee.security.hibernate.properties";
+    private static final String HIBERNATE_SPRING_CONFIG = "spring/test.org.wamblee.security.database.xml";
+
+    public HibernateComponent(String aName) throws IOException { 
+        super(aName, new String[] { HIBERNATE_SPRING_CONFIG}, 
+                createProvided(), createRequired()); 
+        
+        Properties props = new Properties(); 
+        props.load(new ClassPathResource(HIBERNATE_PROPERTIES).getInputStream());
+        addProperties(props);
+    }
+
+    private static Map<RequiredInterface, String> createRequired() {
+        Map<RequiredInterface,String> required = new TreeMap<RequiredInterface, String>();
+        required.put(new DefaultRequiredInterface("datasource", DataSource.class), "datasource");
+        return required;
+    }
+
+    private static Map<String, ProvidedInterface> createProvided() {
+        Map<String,ProvidedInterface> provided = new TreeMap<String,ProvidedInterface>(); 
+        
+        provided.put("transactionManager", new DefaultProvidedInterface(
+                "transactionMgr", PlatformTransactionManager.class));
+        provided.put("sessionFactory", new DefaultProvidedInterface(
+                "sessionFactory", SessionFactory.class));
+        provided.put("org.springframework.orm.hibernate3.HibernateTemplate", new DefaultProvidedInterface(
+                "hibernateTemplate", HibernateTemplate.class));
+        return provided;
+    }
+}
index 9d5e80b6f82d42408eb73b5eaae4b956becfd352..23403cc8f505f2aa429795088dbc63c7ea933b3b 100644 (file)
@@ -20,8 +20,14 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Set;
 
+import javax.sql.DataSource;
+
 import org.wamblee.cache.Cache;
 import org.wamblee.general.BeanKernel;
+import org.wamblee.system.adapters.DefaultContainer;
+import org.wamblee.system.adapters.ObjectConfiguration;
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.Scope;
 import org.wamblee.usermgt.Group;
 import org.wamblee.usermgt.GroupSet;
 import org.wamblee.usermgt.InMemoryUserSetTest;
@@ -48,14 +54,42 @@ public class HibernateUserSetTest extends InMemoryUserSetTest {
         super(UsermgtSpringConfigFiles.class, UsermgtHibernateMappingFiles.class);
     }
     
+    private DefaultContainer _container;
+    private Scope _scope;
+    
+    private DataSource _datasource; 
+    
     /* (non-Javadoc)
      * @see org.wamblee.usermgt.InMemoryUserSetTest#setUp()
      */
     @Override
     protected void setUp() throws Exception {
         super.setUp();
+        
+        _container = new DefaultContainer("top");
+        Component ds = new ExternalDatasourceComponent("datasource");
+        _container.addComponent(ds);
+        
+        ObjectConfiguration config = new ObjectConfiguration(HibernateUserSetTest.class); 
+        config.getSetterConfig().clear().add("datasource");
+        _container.addComponent("testcase", this, config);
+        _scope = _container.start();
+        
+        Object my = _scope.getInterfaceImplementation(ds.getProvidedInterfaces()[0], Object.class);
+        
         clearUserCache();
     }
+    
+    public void setDatasource(DataSource aDatasource) { 
+        _datasource = aDatasource; 
+    }
+    
+    
+    @Override
+    protected void tearDown() throws Exception {
+        _container.stop(_scope);
+        super.tearDown();
+    }
 
     /**
      * Clears the user cache.  
diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java b/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java
new file mode 100644 (file)
index 0000000..3c406ea
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2008 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package org.wamblee.usermgt.hibernate;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.hibernate.SessionFactory;
+import org.wamblee.system.core.DefaultProvidedInterface;
+import org.wamblee.system.core.DefaultRequiredInterface;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.spring.SpringComponent;
+import org.wamblee.usermgt.GroupSet;
+import org.wamblee.usermgt.UserSet;
+
+public class UserGroupRepositoryComponent extends SpringComponent {
+
+    public UserGroupRepositoryComponent(String aName) { 
+        super(aName, new String[] { "spring/test.org.wamblee.security.usermgt-repositories.xml" } , 
+                createProvided(), createRequired()); 
+        
+    }
+
+    private static Map<RequiredInterface, String> createRequired() {
+        Map<RequiredInterface, String> required = new TreeMap<RequiredInterface, String>();
+        required.put(new DefaultRequiredInterface("sessionFactory", SessionFactory.class), "sessionFactory");
+        return required;
+    }
+
+    private static Map<String, ProvidedInterface> createProvided() {
+        Map<String,ProvidedInterface> provided = new TreeMap<String,ProvidedInterface>(); 
+        provided.put(UserSet.class.getName(), new DefaultProvidedInterface("userset", UserSet.class));
+        provided.put(GroupSet.class.getName(), new DefaultProvidedInterface("groupset", GroupSet.class));
+        return provided; 
+    }
+    
+    
+}
index ec3d26aa300780ac04e789c5742ab305da6fddeb..5a75178e1d4c8d3a2615fe50c0a72145f373f64e 100644 (file)
@@ -1,15 +1,23 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.springframework.org/schema/beans
+    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
-<!-- This is the Spring configuration to define the database-related stuff for the
+    <!-- This is the Spring configuration to define the database-related stuff for the
     all persistence tests.  -->
-    <beans>
-        <bean id="dataSource" 
-            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
-            <property name="driverClassName"><value>${database.driver}</value></property>
-            <property name="url"><value>${database.url}</value></property>
-            <property name="username"><value>${database.username}</value></property>
-            <property name="password"><value>${database.password}</value></property>
-        </bean>
-    </beans>
-    
\ No newline at end of file
+    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+        <property name="driverClassName">
+            <value>${database.driver}</value>
+        </property>
+        <property name="url">
+            <value>${database.url}</value>
+        </property>
+        <property name="username">
+            <value>${database.username}</value>
+        </property>
+        <property name="password">
+            <value>${database.password}</value>
+        </property>
+    </bean>
+</beans>