You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/12/11 21:52:56 UTC

[03/10] incubator-usergrid git commit: Finished rule for use in tests and completed ExportServiceIT migration to the rule

Finished rule for use in tests and completed ExportServiceIT migration to the rule


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

Branch: refs/heads/UG-rest-test-framework-overhaul
Commit: cfff0cce4faeeeee8dfbe3add8e622809db0c7bd
Parents: 5baf6cd
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Dec 10 13:05:37 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Dec 10 13:06:10 2014 -0700

----------------------------------------------------------------------
 .../org/apache/usergrid/NewOrgAppAdminRule.java | 160 +++++++++++++++++++
 .../management/cassandra/ExportServiceIT.java   |  48 +++---
 .../org/apache/usergrid/UUIDTestHelper.java     |  38 +++++
 3 files changed, 228 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cfff0cce/stack/services/src/test/java/org/apache/usergrid/NewOrgAppAdminRule.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/NewOrgAppAdminRule.java b/stack/services/src/test/java/org/apache/usergrid/NewOrgAppAdminRule.java
new file mode 100644
index 0000000..71a4740
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/NewOrgAppAdminRule.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.usergrid;
+
+
+import java.util.UUID;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.management.ApplicationInfo;
+import org.apache.usergrid.management.OrganizationInfo;
+import org.apache.usergrid.management.OrganizationOwnerInfo;
+import org.apache.usergrid.management.UserInfo;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import static org.apache.usergrid.UUIDTestHelper.newUUIDString;
+
+
+/**
+ * Creates a new org and admin for every method in the class.  Also creates an application
+ */
+public class NewOrgAppAdminRule implements TestRule {
+
+    private final static Logger LOG = LoggerFactory.getLogger( CoreApplication.class );
+
+    public static final String ADMIN_NAME = "Test Admin";
+    public static final String ADMIN_PASSWORD = "password";
+
+    private final ServiceITSetup setup;
+
+    private OrganizationOwnerInfo organizationOwnerInfo;
+    private ApplicationInfo applicationInfo;
+
+
+    public NewOrgAppAdminRule( final ServiceITSetup setup ) {
+        this.setup = setup;
+    }
+
+
+    @Override
+    public Statement apply( final Statement base, final Description description ) {
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                before( description );
+
+                try {
+                    base.evaluate();
+                }
+                finally {
+                    after( description );
+                }
+            }
+        };
+    }
+
+
+    protected void after( Description description ) {
+        LOG.info( "Test {}: finish with application", description.getDisplayName() );
+    }
+
+
+    /**
+     * Get the org and admin user info
+     * @return
+     */
+    public OrganizationOwnerInfo getOrganizationOwnerInfo() {
+        return organizationOwnerInfo;
+    }
+
+
+    /**
+     * Get the applicationInfo
+     * @return
+     */
+    public ApplicationInfo getApplicationInfo() {
+        return applicationInfo;
+    }
+
+
+    /**
+     * Get the organization info
+     * @return
+     */
+    public OrganizationInfo getOrganizationInfo(){
+        return getOrganizationOwnerInfo().getOrganization();
+    }
+
+
+    /**
+     * Get the admin info
+     * @return
+     */
+    public UserInfo getAdminInfo(){
+        return getOrganizationOwnerInfo().getOwner();
+    }
+
+
+    /**
+     * Create the org admin and application
+     */
+    protected void before( Description description ) throws Exception {
+        final String className = description.getClassName();
+        final String methodName = description.getMethodName();
+        final String uuidString = newUUIDString();
+
+        final String orgName = className + uuidString;
+        final String appName = methodName;
+        final String adminUsername = uuidString;
+        final String email = uuidString + "@apache.org";
+
+        organizationOwnerInfo = createOwnerAndOrganization( orgName, adminUsername, email, ADMIN_NAME, ADMIN_PASSWORD );
+        applicationInfo = createApplication( organizationOwnerInfo.getOrganization().getUuid(), appName );
+    }
+
+
+    /**
+     * Create the org and the admin that owns it
+     */
+    public OrganizationOwnerInfo createOwnerAndOrganization( final String orgName, final String adminUsername,
+                                                             final String adminEmail, final String adminName,
+                                                             final String adminPassword ) throws Exception {
+        return setup.getMgmtSvc()
+                    .createOwnerAndOrganization( orgName, adminUsername, adminName, adminEmail, adminPassword, false,
+                            false );
+    }
+
+
+    /**
+     * Create the new application
+     */
+    public ApplicationInfo createApplication( final UUID organizationId, final String applicationName )
+            throws Exception {
+        return setup.getMgmtSvc().createApplication( organizationId, applicationName );
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cfff0cce/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ExportServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ExportServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ExportServiceIT.java
index a5b499b..2c64836 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ExportServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ExportServiceIT.java
@@ -35,7 +35,7 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule;
 import org.jclouds.netty.config.NettyPayloadModule;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
-import org.junit.BeforeClass;
+import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Ignore;
 import org.junit.Rule;
@@ -43,6 +43,7 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.apache.usergrid.NewOrgAppAdminRule;
 import org.apache.usergrid.ServiceITSetup;
 import org.apache.usergrid.ServiceITSetupImpl;
 import org.apache.usergrid.batch.JobExecution;
@@ -65,6 +66,7 @@ import org.apache.usergrid.persistence.index.impl.ElasticSearchResource;
 import com.google.common.collect.ImmutableSet;
 import com.google.inject.Module;
 
+import static org.apache.usergrid.UUIDTestHelper.newUUIDString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -88,24 +90,33 @@ public class ExportServiceIT {
     @ClassRule
     public static ElasticSearchResource elasticSearchResource = new ElasticSearchResource();
 
-    // app-level data generated only once
-    private static UserInfo adminUser;
-    private static OrganizationInfo organization;
-    private static UUID applicationId;
+
+    @ClassRule
+    public static final ServiceITSetup setup = new ServiceITSetupImpl( cassandraResource, elasticSearchResource );
 
     @Rule
     public ClearShiroSubject clearShiroSubject = new ClearShiroSubject();
 
-    @ClassRule
-    public static final ServiceITSetup setup = new ServiceITSetupImpl( cassandraResource, elasticSearchResource );
+
+    @Rule
+    public NewOrgAppAdminRule orgAppAdminRule = new NewOrgAppAdminRule( setup );
 
 
-    @BeforeClass
-    public static void setup() throws Exception {
+    // app-level data generated only once
+    private UserInfo adminUser;
+    private OrganizationInfo organization;
+    private UUID applicationId;
+
+
+
+    @Before
+    public void setup() throws Exception {
         LOG.info( "in setup" );
-        adminUser = setup.getMgmtSvc().createAdminUser( "grey", "George Reyes", "george@reyes.com", "test", false, false );
-        organization = setup.getMgmtSvc().createOrganization( "george-organization", adminUser, true );
-        applicationId = setup.getMgmtSvc().createApplication( organization.getUuid(), "george-application" ).getId();
+
+
+        adminUser = orgAppAdminRule.getAdminInfo();
+        organization = orgAppAdminRule.getOrganizationInfo();
+        applicationId = orgAppAdminRule.getApplicationInfo().getId();
 
         setup.getEmf().refreshIndex();
     }
@@ -288,8 +299,9 @@ public class ExportServiceIT {
         catch ( Exception e ) {
             //consumed because this checks to see if the file exists. If it doesn't then don't do anything and carry on.
         }
-        setup.getMgmtSvc()
-             .createOwnerAndOrganization( "noExport", "junkUserName", "junkRealName", "ugExport@usergrid.com",
+
+        //create another org to ensure we don't export it
+        orgAppAdminRule.createOwnerAndOrganization( "noExport"+newUUIDString(), "junkUserName"+newUUIDString(), "junkRealName"+newUUIDString(), newUUIDString()+"ugExport@usergrid.com",
                      "123456789" );
 
         S3Export s3Export = new MockS3ExportImpl("exportOneOrg.json");
@@ -334,8 +346,8 @@ public class ExportServiceIT {
     public void testExportOneAppOnCollectionEndpoint() throws Exception {
 
         File f = null;
-        String orgName = "george-organization";
-        String appName = "testAppCollectionTestNotExported";
+        String orgName = "george-organization"+newUUIDString();
+        String appName = "testAppCollectionTestNotExported"+newUUIDString();
 
         try {
             f = new File( "exportOneApp.json" );
@@ -607,8 +619,8 @@ public class ExportServiceIT {
         OrganizationInfo orgMade = null;
         ApplicationInfo appMade = null;
         for ( int i = 0; i < 10; i++ ) {
-            orgMade = setup.getMgmtSvc().createOrganization( "superboss" + i, adminUser, true );
-            appMade = setup.getMgmtSvc().createApplication( orgMade.getUuid(), "superapp" + i );
+            orgMade = setup.getMgmtSvc().createOrganization( "superboss"+ newUUIDString() + i, adminUser, true );
+            appMade = setup.getMgmtSvc().createApplication( orgMade.getUuid(), "superapp" +newUUIDString() + i );
 
             EntityManager customMaker = setup.getEmf().getEntityManager( appMade.getId() );
             customMaker.createApplicationCollection( "superappCol" + i );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cfff0cce/stack/test-utils/src/main/java/org/apache/usergrid/UUIDTestHelper.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/UUIDTestHelper.java b/stack/test-utils/src/main/java/org/apache/usergrid/UUIDTestHelper.java
new file mode 100644
index 0000000..dffe826
--- /dev/null
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/UUIDTestHelper.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.usergrid;
+
+
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+
+/**
+ * Simple class to manipulate UUIDs into strings for unique strings when testing
+ */
+public class UUIDTestHelper {
+
+    /**
+     * Generate a new UUID, and remove all the '-' characters from the resulting string.
+     * @return
+     */
+    public static String newUUIDString() {
+        return UUIDGenerator.newTimeUUID().toString().replace( "-", "" );
+    }
+}