USERGRID-1200: bug fixes and tests

1. Fix copying of Properties object (requires constructor + putAll() )
2. Fix property retrieval for org-configurable properties (take from org 
properties first,
then config file properties, then org property defaults.
3. Added 2 tests for new org config functionality.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/34f7d713
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/34f7d713
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/34f7d713

Branch: refs/heads/master
Commit: 34f7d7139a2e8561da6c232eab17f2216bcd2cee
Parents: a33698b
Author: Mike Dunker <mdun...@apigee.com>
Authored: Tue Jan 19 16:56:47 2016 -0800
Committer: Mike Dunker <mdun...@apigee.com>
Committed: Tue Jan 19 16:56:47 2016 -0800

----------------------------------------------------------------------
 .../src/test/resources/usergrid-test.properties |   1 +
 .../cassandra/OrganizationConfigPropsImpl.java  |  18 +++-
 .../management/OrganizationConfigIT.java        | 108 ++++++++++++++++++-
 3 files changed, 121 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/34f7d713/stack/config/src/test/resources/usergrid-test.properties
----------------------------------------------------------------------
diff --git a/stack/config/src/test/resources/usergrid-test.properties 
b/stack/config/src/test/resources/usergrid-test.properties
index 4693f8d..29bb332 100644
--- a/stack/config/src/test/resources/usergrid-test.properties
+++ b/stack/config/src/test/resources/usergrid-test.properties
@@ -144,6 +144,7 @@ usergrid.recaptcha.public=
 usergrid.recaptcha.private=
 
 usergrid.sysadmin.email=
+usergrid.admin.sysadmin.email=testad...@usergrid.com
 
 usergrid.management.admin_users_require_confirmation=false
 usergrid.management.admin_users_require_activation=false

http://git-wip-us.apache.org/repos/asf/usergrid/blob/34f7d713/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
----------------------------------------------------------------------
diff --git 
a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
 
b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
index 1063000..56c1e12 100644
--- 
a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
+++ 
b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
@@ -68,6 +68,7 @@ public class OrganizationConfigPropsImpl implements 
OrganizationConfigProps {
 
     public OrganizationConfigPropsImpl(Properties properties, Map<String, 
String> map) {
         this.properties = new Properties(properties);
+        this.properties.putAll(properties);
 
         this.defaultProperties = new HashMap<>(noConfigDefaults);
         // add any corresponding properties to default props map
@@ -101,7 +102,9 @@ public class OrganizationConfigPropsImpl implements 
OrganizationConfigProps {
 
     @Override
     public Properties getPropertiesMap() {
-        return new Properties(properties);
+        Properties ret = new Properties(properties);
+        ret.putAll(properties);
+        return ret;
     }
 
     @Override
@@ -125,9 +128,16 @@ public class OrganizationConfigPropsImpl implements 
OrganizationConfigProps {
         String propertyValue;
 
         if (orgPropertyNameValid(name)) {
-            // return from org-specific properties, if set
-            propertyValue = orgProperties.containsKey(name) ?
-                    orgProperties.get(name) : defaultProperties.get(name);
+            if (orgProperties.containsKey(name)) {
+                // return from org-specific properties
+                propertyValue = orgProperties.get(name);
+            } else if (properties.containsKey(name)) {
+                // return from properties file
+                propertyValue = (String)properties.get(name);
+            } else {
+                // return the default
+                propertyValue = defaultProperties.get(name);
+            }
         } else {
             // not an org config item, return from properties
             propertyValue = properties.getProperty(name);

http://git-wip-us.apache.org/repos/asf/usergrid/blob/34f7d713/stack/services/src/test/java/org/apache/usergrid/management/OrganizationConfigIT.java
----------------------------------------------------------------------
diff --git 
a/stack/services/src/test/java/org/apache/usergrid/management/OrganizationConfigIT.java
 
b/stack/services/src/test/java/org/apache/usergrid/management/OrganizationConfigIT.java
index fc1a0f4..6424dbd 100644
--- 
a/stack/services/src/test/java/org/apache/usergrid/management/OrganizationConfigIT.java
+++ 
b/stack/services/src/test/java/org/apache/usergrid/management/OrganizationConfigIT.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.management;
 
 
+import org.apache.shiro.authc.ExcessiveAttemptsException;
 import org.apache.usergrid.NewOrgAppAdminRule;
 import org.apache.usergrid.ServiceITSetup;
 import org.apache.usergrid.ServiceITSetupImpl;
@@ -103,7 +104,110 @@ public class OrganizationConfigIT {
     }
 
     @Test
-    public void testOrganizationConfigInvalidKeys() throws Exception {
-        // TODO: add test
+    public void testWorkflowUrls() throws Exception {
+
+        final String orgName =  uniqueOrg();
+
+        UserInfo user = setup.getMgmtSvc().createAdminUser(null, 
uniqueUsername(), "Org Config Admin", uniqueEmail(), "test", true, false );
+        assertNotNull( user );
+
+        OrganizationInfo org = setup.getMgmtSvc().createOrganization( orgName, 
user, true );
+        assertNotNull( org );
+
+        setup.getEmf().getEntityManager( setup.getSmf().getManagementAppId() );
+
+        OrganizationConfig orgConfig = 
setup.getMgmtSvc().getOrganizationConfigByName(orgName);
+        assertNotNull(orgConfig);
+
+        String userActivationPath = "/%s/%s/users/%s/activate";
+        String defaultApiUrlBase = "http://localhost:8080";;
+        String userActivationUrlTemplate = 
orgConfig.getFullUrlTemplate(OrganizationConfigProps.WorkflowUrl.USER_ACTIVATION_URL);
+        assertTrue(userActivationUrlTemplate.equals(defaultApiUrlBase + 
userActivationPath));
+
+        // insert a new URL base for the org
+        Map<String, Object> propMap = new HashMap<>();
+        String baseKey = OrganizationConfigProps.ORGPROPERTIES_API_URL_BASE;
+        String newApiUrlBase = "http://example.org";;
+        propMap.put(baseKey, newApiUrlBase);
+        orgConfig.addProperties(propMap, false);
+        setup.getMgmtSvc().updateOrganizationConfig(orgConfig);
+
+        setup.getEmf().getEntityManager( setup.getSmf().getManagementAppId() );
+
+        // get org config again
+        OrganizationConfig orgConfigUpdated = 
setup.getMgmtSvc().getOrganizationConfigByUuid(org.getUuid());
+        assertNotNull(orgConfigUpdated);
+        String updatedValue = 
orgConfigUpdated.getProperty(OrganizationConfigProps.ORGPROPERTIES_API_URL_BASE);
+        assertTrue(updatedValue.equals(newApiUrlBase));
+
+        // get new URL
+        String newUserActivationUrlTemplate = 
orgConfigUpdated.getFullUrlTemplate(OrganizationConfigProps.WorkflowUrl.USER_ACTIVATION_URL);
+        assertTrue(newUserActivationUrlTemplate.equals(newApiUrlBase + 
userActivationPath));
+    }
+
+    @Test
+    public void testNonOrgProperty() throws Exception {
+        String testNonOrgProperty = "usergrid.sysadmin.login.name";
+        String testOrgProperty = "usergrid.admin.sysadmin.email";
+
+        // get properties directly
+        String nonOrgPropsValue = 
setup.getProps().getProperty(testNonOrgProperty);
+        String orgPropsValue = setup.getProps().getProperty(testOrgProperty);
+        assertNotNull(nonOrgPropsValue);
+        assertNotNull(orgPropsValue);
+
+        final String orgName =  uniqueOrg();
+
+        UserInfo user = setup.getMgmtSvc().createAdminUser(null, 
uniqueUsername(), "Org Config Admin", uniqueEmail(), "test", true, false );
+        assertNotNull( user );
+
+        OrganizationInfo org = setup.getMgmtSvc().createOrganization( orgName, 
user, true );
+        assertNotNull( org );
+
+        setup.getEmf().getEntityManager( setup.getSmf().getManagementAppId() );
+
+        OrganizationConfig orgConfig = 
setup.getMgmtSvc().getOrganizationConfigByUuid(org.getUuid());
+        assertNotNull(orgConfig);
+
+        // get properties from orgConfig, should equal
+        String nonOrgCfgValue = orgConfig.getProperty(testNonOrgProperty);
+        String orgCfgValue = orgConfig.getProperty(testOrgProperty);
+        assertNotNull(nonOrgCfgValue);
+        assertNotNull(orgCfgValue);
+        assertTrue(nonOrgPropsValue.equals(nonOrgCfgValue));
+        assertTrue(orgPropsValue.equals(orgCfgValue));
+
+        // try to set the org properties (one is org configurable, one is not)
+        String newNonOrgPropertyValue = "testNonOrgLoginName";
+        String newOrgPropertyValue = "testnonorgprope...@usergrid.com";
+
+        Map<String, Object> propMap = new HashMap<>();
+        propMap.put(testNonOrgProperty, newNonOrgPropertyValue);
+        propMap.put(testOrgProperty, newOrgPropertyValue);
+        try {
+            // true validates that all passed in properties are 
org-configurable
+            orgConfig.addProperties(propMap, true);
+            fail("Validation of orgConfig.addProperties should have thrown 
exception");
+        }
+        catch (IllegalArgumentException e) {
+            // expected
+        }
+        catch (Exception e) {
+            fail("Validation of orgConfig.addProperties should have thrown 
IllegalArgumentException");
+        }
+
+        // false doesn't validate, ignores invalid org config items
+        orgConfig.addProperties(propMap, false);
+
+        String nonOrgCfgValue2 = orgConfig.getProperty(testNonOrgProperty);
+        String orgCfgValue2 = orgConfig.getProperty(testOrgProperty);
+
+        assertNotNull(nonOrgCfgValue2);
+        assertNotNull(orgCfgValue2);
+        // only org config item should have been updated
+        assertFalse(nonOrgCfgValue2.equals(newNonOrgPropertyValue));
+        assertTrue(nonOrgCfgValue2.equals(nonOrgCfgValue));
+        assertTrue(orgCfgValue2.equals(newOrgPropertyValue));
+
     }
 }
\ No newline at end of file

Reply via email to