Permalink
Browse files

Enable the mysql profile and fix unit tests to work with mysql

  • Loading branch information...
1 parent e949642 commit b7df8658dc195d458d0dccafc1d2e5a404a604ba @joeldsa joeldsa committed Mar 14, 2013
Showing with 145 additions and 87 deletions.
  1. +16 −0 README.md
  2. +2 −2 common/src/test/java/org/cloudfoundry/identity/uaa/audit/JdbcAuditServiceTests.java
  3. +1 −1 ...n/src/test/java/org/cloudfoundry/identity/uaa/audit/JdbcFailedLoginCountingAuditServiceTests.java
  4. +1 −1 common/src/test/java/org/cloudfoundry/identity/uaa/oauth/JdbcScimClientDetailsServiceTests.java
  5. +1 −1 common/src/test/java/org/cloudfoundry/identity/uaa/oauth/UserManagedAuthzApprovalHandlerTests.java
  6. +1 −1 common/src/test/java/org/cloudfoundry/identity/uaa/oauth/approval/ApprovalsAdminEndpointsTests.java
  7. +20 −13 common/src/test/java/org/cloudfoundry/identity/uaa/oauth/approval/JdbcApprovalStoreTests.java
  8. +1 −1 common/src/test/java/org/cloudfoundry/identity/uaa/user/JdbcUaaUserDatabaseTests.java
  9. +4 −0 common/src/test/resources/mysql.properties
  10. +1 −1 scim/src/test/java/org/cloudfoundry/identity/uaa/scim/JdbcUaaUserDatabaseTests.java
  11. +8 −7 scim/src/test/java/org/cloudfoundry/identity/uaa/scim/bootstrap/ScimGroupBootstrapTests.java
  12. +3 −3 scim/src/test/java/org/cloudfoundry/identity/uaa/scim/endpoints/ScimGroupEndpointsTests.java
  13. +12 −11 scim/src/test/java/org/cloudfoundry/identity/uaa/scim/jdbc/JdbcPagingListTests.java
  14. +17 −16 scim/src/test/java/org/cloudfoundry/identity/uaa/scim/jdbc/JdbcScimGroupMembershipManagerTests.java
  15. +9 −8 scim/src/test/java/org/cloudfoundry/identity/uaa/scim/jdbc/JdbcScimGroupProvisioningTests.java
  16. +20 −21 scim/src/test/java/org/cloudfoundry/identity/uaa/scim/jdbc/JdbcScimUserProvisioningTests.java
  17. +4 −0 scim/src/test/resources/mysql.properties
  18. +24 −0 uaa/src/test/resources/test/profiles/mysql/uaa.yml
View
@@ -268,6 +268,22 @@ will look for an environment variable (or system property)
used to expose `UAA_ADMIN_CLIENT_SECRET` etc. in the standard
configuration.
+### Using Maven with to test with postgresql or mysql
+
+The default uaa unit tests (mvn test) use hsqldb.
+
+To run the unit tests using postgresql:
+
+ $ SPRING_PROFILES_ACTIVE=test,postgresql CLOUD_FOUNDRY_CONFIG_PATH=src/test/resources/test/profiles/postgresql mvn test
+
+To run the unit tests using mysql:
+
+ $ SPRING_PROFILES_ACTIVE=test,mysql CLOUD_FOUNDRY_CONFIG_PATH=src/test/resources/test/profiles/mysql mvn test
+
+The database configuration for the common and scim modules is located at:
+common/src/test/resources/(mysql|postgresql).properties
+scim/src/test/resources/(mysql|postgresql).properties
+
## Inventory
There are actually several projects here, the main `uaa` server application and some samples:
@@ -37,7 +37,7 @@
*/
@ContextConfiguration ("classpath:/test-data-source.xml")
@RunWith (SpringJUnit4ClassRunner.class)
-@IfProfileValue (name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql" })
+@IfProfileValue (name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql", "test,mysql" })
@ProfileValueSourceConfiguration (NullSafeSystemProfileValueSource.class)
public class JdbcAuditServiceTests {
@@ -95,7 +95,7 @@ public void findMethodOnlyReturnsEventsWithinRequestedPeriod() {
private AuditEvent getAuditEvent(AuditEventType type, String principal) {
return getAuditEvent(type, principal, null);
}
-
+
private AuditEvent getAuditEvent(AuditEventType type, String principal, String data) {
return new AuditEvent(type, principal, authDetails, data, System.currentTimeMillis());
}
@@ -38,7 +38,7 @@
*/
@ContextConfiguration ("classpath:/test-data-source.xml")
@RunWith (SpringJUnit4ClassRunner.class)
-@IfProfileValue (name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql" })
+@IfProfileValue (name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql", "test,mysql" })
@ProfileValueSourceConfiguration (NullSafeSystemProfileValueSource.class)
public class JdbcFailedLoginCountingAuditServiceTests {
@@ -20,7 +20,7 @@
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb"})
+@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb", "test,mysql"})
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcScimClientDetailsServiceTests {
@@ -51,7 +51,7 @@
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb" })
+@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb", "test,mysql" })
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class UserManagedAuthzApprovalHandlerTests {
@@ -48,7 +48,7 @@
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb"})
+@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb", "test,mysql"})
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class ApprovalsAdminEndpointsTests {
@Autowired
@@ -40,7 +40,7 @@
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb"})
+@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb", "test,mysql"})
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcApprovalStoreTests {
@Autowired
@@ -92,8 +92,8 @@ public void testAddAndGetApproval() {
Approval approval = approvals.get(0);
assertEquals(clientId, approval.getClientId());
assertEquals(userName, approval.getUserName());
- assertEquals(expiresAt.getTime(), approval.getExpiresAt().getTime());
- assertEquals(lastUpdatedAt.getTime(), approval.getLastUpdatedAt().getTime());
+ assertEquals(Math.round(expiresAt.getTime() / 1000), Math.round(approval.getExpiresAt().getTime() / 1000));
+ assertEquals(Math.round(lastUpdatedAt.getTime() / 1000), Math.round(approval.getLastUpdatedAt().getTime() / 1000));
assertEquals(scope, approval.getScope());
assertEquals(status, approval.getStatus());
}
@@ -128,22 +128,23 @@ public void canRevokeApprovals() {
public void addSameApprovalRepeatedlyUpdatesExpiry() {
assertTrue(dao.addApproval(new Approval("u2", "c2", "dash.user", 6000, APPROVED)));
Approval app = dao.getApprovals("u2", "c2").iterator().next();
- assertTrue(app.getExpiresAt().before(new Date(new Date().getTime() + 6000)));
+ assertEquals(Math.round(app.getExpiresAt().getTime() / 1000), Math.round((new Date().getTime() + 6000) / 1000));
assertTrue(dao.addApproval(new Approval("u2", "c2", "dash.user", 8000, APPROVED)));
app = dao.getApprovals("u2", "c2").iterator().next();
- assertTrue(app.getExpiresAt().after(new Date(new Date().getTime() + 6000)));
+ assertEquals(Math.round(app.getExpiresAt().getTime() / 1000), Math.round((new Date().getTime() + 8000) / 1000));
}
@Test
public void addSameApprovalDifferentStatusRepeatedlyOnlyUpdatesStatus() {
assertTrue(dao.addApproval(new Approval("u2", "c2", "dash.user", 6000, APPROVED)));
Approval app = dao.getApprovals("u2", "c2").iterator().next();
- assertTrue(app.getExpiresAt().before(new Date(new Date().getTime() + 6000)));
+ assertEquals(Math.round(app.getExpiresAt().getTime() / 1000), Math.round((new Date().getTime() + 6000) / 1000));
- assertTrue(dao.addApproval(new Approval("u2", "c2", "dash.user", 8000, APPROVED)));
+ assertTrue(dao.addApproval(new Approval("u2", "c2", "dash.user", 8000, DENIED)));
app = dao.getApprovals("u2", "c2").iterator().next();
- assertTrue(app.getExpiresAt().after(new Date(new Date().getTime() + 6000)));
+ assertEquals(Math.round(app.getExpiresAt().getTime() / 1000), Math.round((new Date().getTime() + 6000) / 1000));
+ assertEquals(DENIED, app.getStatus());
}
@Test
@@ -153,19 +154,25 @@ public void canRefreshApproval() {
dao.refreshApproval(new Approval(app.getUserName(), app.getClientId(), app.getScope(), now, APPROVED));
app = dao.getApprovals("u1", "c1").iterator().next();
- assertEquals(now, app.getExpiresAt());
+ assertEquals(Math.round(now.getTime() / 1000), Math.round(app.getExpiresAt().getTime() / 1000));
}
@Test
- public void canPurgeExpiredApprovals() {
- assertEquals(3, dao.getApprovals("userName pr").size());
+ public void canPurgeExpiredApprovals() throws InterruptedException {
+ List<Approval> approvals = dao.getApprovals("userName pr");
+ assertEquals(3, approvals.size());
addApproval("u3", "c3", "test1", 0, APPROVED);
addApproval("u3", "c3", "test2", 0, DENIED);
addApproval("u3", "c3", "test3", 0, APPROVED);
- assertEquals(6, dao.getApprovals("userName pr").size());
+ List<Approval> newApprovals = dao.getApprovals("userName pr");
+ assertEquals(6, newApprovals.size());
+ // On mysql, the expiry is rounded off to the nearest second so
+ // the following assert could randomly fail.
+ Thread.sleep(500);
dao.purgeExpiredApprovals();
- assertEquals(3, dao.getApprovals("userName pr").size());
+ List<Approval> remainingApprovals = dao.getApprovals("userName pr");
+ assertEquals(3, remainingApprovals.size());
}
}
@@ -43,7 +43,7 @@
*/
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql" })
+@IfProfileValue(name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql", "test,mysql" })
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcUaaUserDatabaseTests {
@@ -0,0 +1,4 @@
+database.driverClassName: com.mysql.jdbc.Driver
+database.url: jdbc:mysql://localhost:3306/uaa
+database.username: root
+database.password:
@@ -45,7 +45,7 @@
*/
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql" })
+@IfProfileValue(name = "spring.profiles.active", values = { "" , "hsqldb", "test,postgresql", "test,mysql" })
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcUaaUserDatabaseTests {
@@ -1,5 +1,12 @@
package org.cloudfoundry.identity.uaa.scim.bootstrap;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Arrays;
+
+import javax.sql.DataSource;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cloudfoundry.identity.uaa.scim.ScimGroupMember;
@@ -20,15 +27,9 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import javax.sql.DataSource;
-import java.util.Arrays;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb"})
+@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb", "test,mysql"})
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class ScimGroupBootstrapTests {
@@ -58,7 +58,7 @@
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb"})
+@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb", "test,mysql"})
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class ScimGroupEndpointsTests {
@@ -355,9 +355,9 @@ public void testUpdateWrongVersionFails() {
expectedEx.expect(ScimException.class);
endpoints.updateGroup(g1, g1.getId(), String.valueOf(g1.getVersion() + 23));
}
-
+
@Test
- public void testUpdateGroupWithNoMembers() {
+ public void testUpdateGroupWithNoMembers() {
ScimGroup g = new ScimGroup("", "clients.read");
g.setMembers(Arrays.asList(createMember(ScimGroupMember.Type.USER, ScimGroupMember.GROUP_ADMIN)));
g = endpoints.createGroup(g);
@@ -12,6 +12,17 @@
*/
package org.cloudfoundry.identity.uaa.scim.jdbc;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.sql.DataSource;
+
import org.cloudfoundry.identity.uaa.rest.jdbc.JdbcPagingList;
import org.cloudfoundry.identity.uaa.test.NullSafeSystemProfileValueSource;
import org.junit.After;
@@ -26,23 +37,13 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import javax.sql.DataSource;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
/**
* @author Luke Taylor
* @author Dave Syer
*/
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb" })
+@IfProfileValue(name = "spring.profiles.active", values = { "", "test,postgresql", "hsqldb", "test,mysql" })
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcPagingListTests {
@@ -1,5 +1,21 @@
package org.cloudfoundry.identity.uaa.scim.jdbc;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.sql.DataSource;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cloudfoundry.identity.uaa.scim.ScimGroup;
@@ -20,24 +36,9 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import javax.sql.DataSource;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb"})
+@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb", "test,mysql"})
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcScimGroupMembershipManagerTests {
@@ -1,5 +1,13 @@
package org.cloudfoundry.identity.uaa.scim.jdbc;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.sql.DataSource;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cloudfoundry.identity.uaa.scim.ScimGroup;
@@ -19,16 +27,9 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
-import javax.sql.DataSource;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
@ContextConfiguration("classpath:/test-data-source.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb"})
+@IfProfileValue(name = "spring.profiles.active", values = {"", "test,postgresql", "hsqldb", "test,mysql"})
@ProfileValueSourceConfiguration(NullSafeSystemProfileValueSource.class)
public class JdbcScimGroupProvisioningTests {
Oops, something went wrong.

0 comments on commit b7df865

Please sign in to comment.