Permalink
Browse files

CFID-283: Add env and scripts to enable postgres testing easily from …

…command line

Change-Id: I62b9520b9a2253759080b16d688a4cceb4e46626
  • Loading branch information...
1 parent 76cb4b8 commit 445be969db80dca7afac0ccf3fbb8983118e7395 @dsyer dsyer committed May 10, 2012
Showing with 113 additions and 101 deletions.
  1. +13 −0 .travis.yml
  2. +3 −0 common/pom.xml
  3. +5 −1 common/src/main/java/org/cloudfoundry/identity/uaa/ParentContextLoader.java
  4. +15 −7 common/src/main/java/org/cloudfoundry/identity/uaa/TestUtils.java
  5. +2 −1 common/src/main/java/org/cloudfoundry/identity/uaa/config/YamlProcessor.java
  6. +19 −14 common/src/main/java/org/cloudfoundry/identity/uaa/integration/TestProfileEnvironment.java
  7. +7 −7 common/src/test/java/org/cloudfoundry/identity/uaa/audit/JdbcAuditServiceTests.java
  8. +1 −1 common/src/test/java/org/cloudfoundry/identity/uaa/scim/JdbcPagingListTests.java
  9. +1 −1 common/src/test/java/org/cloudfoundry/identity/uaa/scim/JdbcScimUserProvisioningTests.java
  10. +1 −1 common/src/test/java/org/cloudfoundry/identity/uaa/user/JdbcUaaUserDatabaseTests.java
  11. +3 −14 common/src/test/resources/log4j.properties
  12. +1 −1 common/src/test/resources/test-data-source.xml
  13. +1 −2 uaa/.springBeans
  14. +1 −1 uaa/pom.xml
  15. +1 −0 uaa/src/main/resources/log4j.properties
  16. +12 −13 uaa/src/test/java/org/cloudfoundry/identity/uaa/scim/jobs/AbstractJobIntegrationTests.java
  17. +5 −6 uaa/src/test/java/org/cloudfoundry/identity/uaa/scim/jobs/BackwardMigrationJobIntegrationTests.java
  18. +0 −2 uaa/src/test/java/org/cloudfoundry/identity/uaa/scim/jobs/UserMigrationJobIntegrationTests.java
  19. +22 −0 uaa/src/test/resources/org/cloudfoundry/identity/uaa/cloud-controller-schema-postgresql.sql
  20. +0 −28 uaa/src/test/resources/test-data-source.xml
  21. +0 −1 uaa/src/test/resources/test/profiles/postgresql/uaa.yml
View
@@ -1,2 +1,15 @@
language: java
+
+before_script:
+ - if [ "$CLOUD_FOUNDRY_CONFIG_PATH" != "" ]; then psql -c 'create database cloud_controller;' -U postgres; fi
+ - if [ "$CLOUD_FOUNDRY_CONFIG_PATH" != "" ]; then psql -c 'create database uaa;' -U postgres; fi
+ - if [ "$CLOUD_FOUNDRY_CONFIG_PATH" != "" ]; then psql -c 'create role root NOSUPERUSER LOGIN INHERIT CREATEDB;' -U postgres; fi
+ - if [ "$CLOUD_FOUNDRY_CONFIG_PATH" != "" ]; then psql -c "alter role root with password 'changeme';" -U postgres; fi
+
install: mvn -U install --quiet -DskipTests=true
+script: mvn clean test
+
+env:
+ -
+ - CLOUD_FOUNDRY_CONFIG_PATH=src/test/resources/test/profiles/postgresql SPRING_PROFILES_ACTIVE=test,postgresql
+
View
@@ -71,6 +71,9 @@
<excludes>
<exclude>**/Abstract*.java</exclude>
</excludes>
+ <systemPropertyVariables>
+ <spring.profiles.active>${SPRING_PROFILES_ACTIVE}</spring.profiles.active>
+ </systemPropertyVariables>
</configuration>
</plugin>
</plugins>
@@ -13,6 +13,7 @@
package org.cloudfoundry.identity.uaa;
+import org.cloudfoundry.identity.uaa.integration.TestProfileEnvironment;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.test.context.support.GenericXmlContextLoader;
@@ -35,7 +36,10 @@
@Override
protected void customizeContext(GenericApplicationContext context) {
- GenericXmlApplicationContext parent = new GenericXmlApplicationContext(parentLocation);
+ GenericXmlApplicationContext parent = new GenericXmlApplicationContext();
+ parent.setEnvironment(TestProfileEnvironment.getEnvironment());
+ parent.load(parentLocation);
+ parent.refresh();
super.customizeContext(context);
context.setParent(parent);
}
@@ -18,6 +18,8 @@
import javax.sql.DataSource;
+import org.cloudfoundry.identity.uaa.integration.TestProfileEnvironment;
+import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceUtils;
@@ -26,21 +28,28 @@
/**
* Common methods for DB manipulation and so on.
- *
+ *
* @author Luke Taylor
+ * @author Dave Syer
+ *
*/
public class TestUtils {
- private static String platform = System.getProperty("PLATFORM", "hsqldb");
+
+ private static Environment environment = TestProfileEnvironment.getEnvironment();
+
+ private static String platform = environment.acceptsProfiles("postgresql") ? "postgresql" : "hsqldb";
public static void runScript(DataSource dataSource, String stem) throws Exception {
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.addScript(new ClassPathResource(stem + "-" + platform + ".sql", TestUtils.class));
Connection connection = dataSource.getConnection();
try {
populator.populate(connection);
- } catch (ScriptStatementFailedException e) {
+ }
+ catch (ScriptStatementFailedException e) {
// ignore
- } finally {
+ }
+ finally {
DataSourceUtils.releaseConnection(connection, dataSource);
}
}
@@ -55,13 +64,12 @@ public static void dropSchema(DataSource dataSource) throws Exception {
public static void deleteFrom(DataSource dataSource, String... tables) throws Exception {
for (String table : tables) {
- new JdbcTemplate(dataSource).update("delete from " + table);
+ new JdbcTemplate(dataSource).update("delete from " + table);
}
}
public static void assertNoSuchUser(JdbcTemplate template, String column, String value) {
- assertEquals(0, template.queryForInt("select count(id) from users where " + column +"='"+value+"'"));
+ assertEquals(0, template.queryForInt("select count(id) from users where " + column + "='" + value + "'"));
}
-
}
@@ -132,12 +132,13 @@ protected void process(MatchCallback callback) {
logger.info("Loading from YAML: " + resource);
for (Object object : yaml.loadAll(resource.getInputStream())) {
if (resolutionMethod != ResolutionMethod.FIRST_FOUND || !found) {
+ int count = 0;
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) object;
if (map != null) {
process(map, callback);
found = true;
- logger.debug("Loaded from YAML: " + map);
+ logger.debug("Loaded " + (count++) + " documents from YAML: " + resource);
}
}
}
@@ -12,7 +12,10 @@
*/
package org.cloudfoundry.identity.uaa.integration;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -21,7 +24,7 @@
import org.cloudfoundry.identity.uaa.config.EnvironmentPropertiesFactoryBean;
import org.cloudfoundry.identity.uaa.config.YamlProcessor.ResolutionMethod;
import org.cloudfoundry.identity.uaa.config.YamlPropertiesFactoryBean;
-import org.springframework.core.env.Environment;
+import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.DefaultResourceLoader;
@@ -47,21 +50,23 @@
private TestProfileEnvironment() {
- Resource resource = null;
-
- Properties properties = new Properties();
+ List<Resource> resources = new ArrayList<Resource>();
for (String location : DEFAULT_PROFILE_CONFIG_FILE_LOCATIONS) {
location = environment.resolvePlaceholders(location);
- resource = recourceLoader.getResource(location);
+ Resource resource = recourceLoader.getResource(location);
if (resource != null && resource.exists()) {
- YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
- factory.setResources(new Resource[] {resource});
- factory.setResolutionMethod(ResolutionMethod.OVERRIDE_AND_IGNORE);
- properties.putAll(factory.getObject());
+ resources.add(resource);
}
}
+ YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
+ factory.setResources(resources.toArray(new Resource[resources.size()]));
+ factory.setDocumentMatchers(Collections.singletonMap("platform",
+ environment.acceptsProfiles("postgresql") ? "postgresql" : "hsqldb"));
+ factory.setResolutionMethod(ResolutionMethod.OVERRIDE_AND_IGNORE);
+ Properties properties = factory.getObject();
+
logger.debug("Decoding environment properties: " + properties.size());
if (!properties.isEmpty()) {
for (Enumeration<?> names = properties.propertyNames(); names.hasMoreElements();) {
@@ -79,17 +84,17 @@ private TestProfileEnvironment() {
environment.getPropertySources().addLast(new PropertiesPropertySource("uaa.yml", properties));
}
- EnvironmentPropertiesFactoryBean factory = new EnvironmentPropertiesFactoryBean();
- factory.setEnvironment(environment);
- factory.setDefaultProperties(properties);
- Map<String, ?> debugProperties = factory.getObject();
+ EnvironmentPropertiesFactoryBean environmentProperties = new EnvironmentPropertiesFactoryBean();
+ environmentProperties.setEnvironment(environment);
+ environmentProperties.setDefaultProperties(properties);
+ Map<String, ?> debugProperties = environmentProperties.getObject();
logger.debug("Environment properties: " + debugProperties);
}
/**
* @return the environment
*/
- public static Environment getEnvironment() {
+ public static ConfigurableEnvironment getEnvironment() {
return instance.environment;
}
@@ -12,16 +12,16 @@
*/
package org.cloudfoundry.identity.uaa.audit;
-import java.sql.Timestamp;
-import java.util.List;
-import javax.sql.DataSource;
-
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.sql.Timestamp;
+import java.util.List;
+
+import javax.sql.DataSource;
+
import org.cloudfoundry.identity.uaa.NullSafeSystemProfileValueSource;
-import org.cloudfoundry.identity.uaa.TestUtils;
import org.cloudfoundry.identity.uaa.authentication.UaaAuthenticationDetails;
import org.cloudfoundry.identity.uaa.user.UaaUser;
import org.junit.Before;
@@ -40,7 +40,7 @@
*/
@ContextConfiguration ("classpath:/test-data-source.xml")
@RunWith (SpringJUnit4ClassRunner.class)
-@IfProfileValue (name = "spring.profiles.active", values = { "" , "hsqldb" })
+@IfProfileValue (name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql" })
@ProfileValueSourceConfiguration (NullSafeSystemProfileValueSource.class)
public class JdbcAuditServiceTests {
@@ -56,8 +56,8 @@
@Before
public void createService() throws Exception {
template = new JdbcTemplate(dataSource);
- TestUtils.createSchema(dataSource);
auditService = new JdbcAuditService(dataSource);
+ template.execute("DELETE FROM SEC_AUDIT WHERE principal_id='1' or principal_id='clientA' or principal_id='clientB'");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("1.1.1.1");
@@ -42,7 +42,7 @@
*/
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb", "empty,postgresql" })
+@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb" })
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcPagingListTests {
@@ -42,7 +42,7 @@
*/
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb", "empty,postgresql" })
+@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb" })
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcScimUserProvisioningTests {
@@ -39,7 +39,7 @@
*/
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql", "empty,postgresql" })
+@IfProfileValue(name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql" })
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcUaaUserDatabaseTests {
@@ -11,31 +11,20 @@
# subcomponent's license, as noted in the LICENSE file.
#
-log4j.rootCategory=INFO, CONSOLE, FILE
+log4j.rootCategory=INFO, CONSOLE
PID=????
-catalina.base=/tmp
-LOG_PATH=${catalina.base}/logs
-LOG_FILE=${LOG_PATH}/uaa.log
LOG_PATTERN=[%d{yyyy-MM-dd HH:mm:ss.SSS}] uaa - ${PID} [%t] .... %5p --- %c{1}: %m%n
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN}
-log4j.appender.FILE=org.apache.log4j.RollingFileAppender
-log4j.appender.FILE.File=${LOG_FILE}
-log4j.appender.FILE.MaxFileSize=10MB
-log4j.appender.FILE.layout = org.apache.log4j.PatternLayout
-log4j.appender.FILE.layout.ConversionPattern=${LOG_PATTERN}
-
log4j.category.org.springframework.security=DEBUG
log4j.category.org.cloudfoundry.identity=DEBUG
-log4j.category.org.springframework.web=DEBUG
+log4j.category.org.springframework.web=INFO
log4j.category.org.springframework.jdbc.datasource=DEBUG
log4j.category.org.springframework.jdbc.datasource.DataSourceUtils=INFO
-#log4j.category.UAA.Audit=TRACE
-#log4j.category.org.springframework.beans.factory.support=DEBUG
+log4j.category.org.springframework.beans.factory.support=DEBUG
log4j.category.org.springframework.web.context.support.StandardServletEnvironment=INFO
-# log4j.category.org.apache.http.wire=DEBUG
@@ -42,7 +42,7 @@
</beans>
<beans profile="postgresql">
- <context:property-placeholder location="postgresql.properties"/>
+ <context:property-placeholder location="${POSTGRESQL_PROPERTIES:postgresql.properties}"/>
<bean id="platform" class="java.lang.String">
<constructor-arg value="postgresql" />
</bean>
View
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
- <pluginVersion><![CDATA[2.8.0.201110170010-RELEASE]]></pluginVersion>
+ <pluginVersion><![CDATA[2.9.1.201203220057-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
@@ -12,7 +12,6 @@
<config>src/main/webapp/WEB-INF/oauth-clients.xml</config>
<config>src/main/webapp/WEB-INF/spring-data-source.xml</config>
<config>src/main/webapp/WEB-INF/spring-scim.xml</config>
- <config>src/test/resources/test-data-source.xml</config>
<config>src/test/resources/test/config/test-override.xml</config>
</configs>
<configSets>
View
@@ -18,7 +18,6 @@
<properties>
<m2eclipse.wtp.contextRoot>/uaa</m2eclipse.wtp.contextRoot>
<uaa.path>/uaa</uaa.path>
- <CLOUD_FOUNDRY_CONFIG_PATH></CLOUD_FOUNDRY_CONFIG_PATH>
<!-- Brain dead install plugin (Maven 3) cannot extract this stuff from its own configuration -->
<file>target/${project.artifactId}-${project.version}.war</file>
<groupId>${project.groupId}</groupId>
@@ -150,6 +149,7 @@
<exclude>**/Abstract*.java</exclude>
</excludes>
<systemPropertyVariables>
+ <spring.profiles.active>${SPRING_PROFILES_ACTIVE}</spring.profiles.active>
<CLOUD_FOUNDRY_CONFIG_PATH>${CLOUD_FOUNDRY_CONFIG_PATH}</CLOUD_FOUNDRY_CONFIG_PATH>
</systemPropertyVariables>
</configuration>
@@ -33,6 +33,7 @@ log4j.appender.FILE.layout.ConversionPattern=${LOG_PATTERN}
log4j.category.org.springframework.security=DEBUG
log4j.category.org.cloudfoundry.identity=DEBUG
log4j.category.org.springframework.web=DEBUG
+log4j.category.org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping=INFO
log4j.category.org.springframework.jdbc.datasource=DEBUG
log4j.category.org.springframework.jdbc.datasource.DataSourceUtils=INFO
log4j.category.org.springframework.jdbc.datasource.DataSourceTransactionManager=INFO
@@ -39,7 +39,7 @@
@ContextConfiguration(locations = { "file:./src/main/webapp/WEB-INF/applicationContext.xml",
"file:./src/main/webapp/WEB-INF/batch-servlet.xml", "classpath*:/META-INF/spring/batch/jobs/jobs.xml" }, loader = ParentContextLoader.class)
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb", "empty,postgresql" })
+@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb" })
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public abstract class AbstractJobIntegrationTests {
@@ -77,22 +77,21 @@ public void setJobRepository(JobRepository jobRepository) throws Exception {
@Before
public void setUpData() throws Exception {
TestUtils.runScript(cloudControllerDataSource, "cloud-controller-schema");
- TestUtils.runScript(uaaDataSource, "schema");
- new JdbcTemplate(cloudControllerDataSource)
- .update("insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)",
- 0, true, "marissa@test.org", "ENCRYPT_ME", new Date(), new Date());
- new JdbcTemplate(cloudControllerDataSource)
- .update("insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)",
- 1, true, "vcap_tester@vmware.com", "ENCRYPT_ME", new Date(), new Date());
- new JdbcTemplate(cloudControllerDataSource)
- .update("insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)",
- 2, true, "dale@test.org", "ENCRYPT_ME", new Date(), new Date());
+ new JdbcTemplate(cloudControllerDataSource).update(
+ "insert into users (active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?)",
+ true, "marissa@test.org", "ENCRYPT_ME", new Date(), new Date());
+ new JdbcTemplate(cloudControllerDataSource).update(
+ "insert into users (active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?)",
+ true, "vcap_tester@vmware.com", "ENCRYPT_ME", new Date(), new Date());
+ new JdbcTemplate(cloudControllerDataSource).update(
+ "insert into users (active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?)",
+ true, "dale@test.org", "ENCRYPT_ME", new Date(), new Date());
}
@After
public void clearUp() {
- new JdbcTemplate(cloudControllerDataSource).update("delete from users");
- new JdbcTemplate(uaaDataSource).update("delete from users");
+ new JdbcTemplate(cloudControllerDataSource).update("delete from users where crypted_password='ENCRYPT_ME'");
+ new JdbcTemplate(uaaDataSource).update("delete from users where password='ENCRYPT_ME'");
}
}
Oops, something went wrong.

0 comments on commit 445be96

Please sign in to comment.