Also fixed several bugs in SpringComponent.
<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>
<artifactId>wamblee-hibernate-jpa</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
-
+
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
-
+
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
-
+
</dependencies>
</project>
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
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;
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.
--- /dev/null
+/*
+ * 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;
+ }
+
+
+}
<?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>