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

[07/27] incubator-usergrid git commit: Committing tests, may be some bugs still

Committing tests, may be some bugs still


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

Branch: refs/heads/two-dot-o
Commit: 8bab4e71aab2e8d9dcc85ccbe0b9e204c1c9dcc8
Parents: d4ecbe1
Author: Todd Nine <tn...@apigee.com>
Authored: Fri Nov 7 09:44:35 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Fri Nov 7 09:44:35 2014 -0700

----------------------------------------------------------------------
 .../index/impl/ElasticSearchResource.java       | 113 ++++++++++---------
 .../java/org/apache/usergrid/rest/ITSetup.java  |  16 +--
 .../rest/management/RegistrationIT.java         |  61 +++++-----
 .../usergrid/cassandra/CassandraResource.java   |  18 +--
 4 files changed, 108 insertions(+), 100 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8bab4e71/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchResource.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchResource.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchResource.java
index 4145e32..661547a 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchResource.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchResource.java
@@ -92,62 +92,65 @@ public class ElasticSearchResource extends EnvironResource {
 
 
     public synchronized ElasticSearchResource startEs(){
-        if ( node != null ) {
-            return this;
-        }
-
-
-        //override the system properties in the Archiaus env
-        port = AvailablePortFinder.getNextAvailable( 9300 );
-
-        final String host = "127.0.0.1";
-        System.setProperty( IndexFig.ELASTICSEARCH_HOSTS, host );
-        System.setProperty( IndexFig.ELASTICSEARCH_PORT, port + "" );
-
-        //we have to create this AFTER we set our system properties, or they won't get picked upt
-        Injector injector = Guice.createInjector( new GuicyFigModule( IndexFig.class ) );
-        IndexFig indexFig = injector.getInstance( IndexFig.class );
-
-
-        final String clusterName = indexFig.getClusterName();
-
-        File tempDir;
-        try {
-            tempDir = getTempDirectory();
-        }
-        catch ( Exception ex ) {
-            throw new RuntimeException( "Fatal error unable to create temp dir, start embedded ElasticSearch", ex );
-        }
-
-
-        Settings settings = ImmutableSettings.settingsBuilder()
-                .put("cluster.name", clusterName)
-                .put("network.publish_host", host)
-                .put("transport.tcp.port", port)
-                .put("discovery.zen.ping.multicast.enabled", "false")
-                .put("node.http.enabled", false)
-                .put("path.logs", tempDir.toString())
-                .put("path.data", tempDir.toString())
-                .put("index.store.type", "default")
-                .put("index.number_of_shards", 1)
-                .put("index.number_of_replicas", 1)
-                .build();
-
-
-        log.info( "-----------------------------------------------------------------------" );
-        log.info( "Starting ElasticSearch embedded server settings: \n" + settings.getAsMap() );
-        log.info( "-----------------------------------------------------------------------" );
-
-
-        node = NodeBuilder.nodeBuilder().settings( settings ).clusterName( indexFig.getClusterName() ).client( false ).data( true ).build().start();
-
-        Runtime.getRuntime().addShutdownHook( new Thread() {
-            @Override
-            public void run() {
-                shutdown();
-            }
-        } );
 
+//
+//        if ( node != null ) {
+//            return this;
+//        }
+//
+//
+//        //override the system properties in the Archiaus env
+//        port = AvailablePortFinder.getNextAvailable( 9300 );
+//
+//        final String host = "127.0.0.1";
+//        System.setProperty( IndexFig.ELASTICSEARCH_HOSTS, host );
+//        System.setProperty( IndexFig.ELASTICSEARCH_PORT, port + "" );
+//
+//        //we have to create this AFTER we set our system properties, or they won't get picked upt
+//        Injector injector = Guice.createInjector( new GuicyFigModule( IndexFig.class ) );
+//        IndexFig indexFig = injector.getInstance( IndexFig.class );
+//
+//
+//        final String clusterName = indexFig.getClusterName();
+//
+//        File tempDir;
+//        try {
+//            tempDir = getTempDirectory();
+//        }
+//        catch ( Exception ex ) {
+//            throw new RuntimeException( "Fatal error unable to create temp dir, start embedded ElasticSearch", ex );
+//        }
+//
+//
+//        Settings settings = ImmutableSettings.settingsBuilder()
+//                .put("cluster.name", clusterName)
+//                .put("network.publish_host", host)
+//                .put("transport.tcp.port", port)
+//                .put("discovery.zen.ping.multicast.enabled", "false")
+//                .put("node.http.enabled", false)
+//                .put("path.logs", tempDir.toString())
+//                .put("path.data", tempDir.toString())
+//                .put("index.store.type", "default")
+//                .put("index.number_of_shards", 1)
+//                .put("index.number_of_replicas", 1)
+//                .build();
+//
+//
+//        log.info( "-----------------------------------------------------------------------" );
+//        log.info( "Starting ElasticSearch embedded server settings: \n" + settings.getAsMap() );
+//        log.info( "-----------------------------------------------------------------------" );
+//
+//
+//        node = NodeBuilder.nodeBuilder().settings( settings ).clusterName( indexFig.getClusterName() ).client( false ).data( true ).build().start();
+//
+//        Runtime.getRuntime().addShutdownHook( new Thread() {
+//            @Override
+//            public void run() {
+//                shutdown();
+//            }
+//        } );
+//
+//        return this;
         return this;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8bab4e71/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
index 0d6a957..112899e 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
@@ -55,7 +55,7 @@ public class ITSetup extends ExternalResource {
     private SignInProviderFactory providerFactory;
     private Properties properties;
 
-    private boolean setupCalled = false;
+//    private boolean setupCalled = false;
     private boolean ready = false;
     private URI uri;
 
@@ -78,7 +78,9 @@ public class ITSetup extends ExternalResource {
         tomcatResource = TomcatResource.instance;
         tomcatResource.setWebAppsPath( "src/main/webapp" );
 
-        elasticSearchResource = new ElasticSearchResource().startEs();
+//        elasticSearchResource = new ElasticSearchResource().startEs();
+
+        elasticSearchResource = new ElasticSearchResource();
 
     }
 
@@ -100,12 +102,12 @@ public class ITSetup extends ExternalResource {
             tokenService =       cassandraResource.getBean( TokenService.class );
             providerFactory =    cassandraResource.getBean( SignInProviderFactory.class );
             applicationCreator = cassandraResource.getBean( ApplicationCreator.class );
-            managementService =  cassandraResource.getBean( ManagementService.class );
+//            managementService =  cassandraResource.getBean( ManagementService.class );
 
-            if ( !setupCalled ) {
-                managementService.setup();
-                setupCalled = true;
-            }
+//            if ( !setupCalled ) {
+//                managementService.setup();
+//                setupCalled = true;
+//            }
 
             String esStartup = properties.getProperty("elasticsearch.startup");
             if ( "embedded".equals(esStartup)) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8bab4e71/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
index 580be03..aca33ba 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
@@ -32,13 +32,20 @@ import javax.mail.internet.MimeMultipart;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 
+import com.eaio.uuid.UUIDGen;
 import com.fasterxml.jackson.databind.JsonNode;
+
+import org.junit.Rule;
 import org.junit.Test;
 import org.jvnet.mock_javamail.Mailbox;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.usergrid.management.UserInfo;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import org.apache.usergrid.rest.AbstractRestIT;
+import org.apache.usergrid.rest.TestContextSetup;
+import org.apache.usergrid.rest.test.security.TestAppUser;
+import org.apache.usergrid.rest.test.security.TestUser;
 
 import org.apache.commons.lang.StringUtils;
 
@@ -64,6 +71,9 @@ public class RegistrationIT extends AbstractRestIT {
 
     private static final Logger logger = LoggerFactory.getLogger( RegistrationIT.class );
 
+    @Rule
+    public TestContextSetup context = new TestContextSetup( this );
+
 
     @Test
     public void postCreateOrgAndAdmin() throws Exception {
@@ -76,22 +86,32 @@ public class RegistrationIT extends AbstractRestIT {
             setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
             setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
 
-            JsonNode node = postCreateOrgAndAdmin( "test-org-1", "test-user-1", "Test User", 
-                    "test-user-1@mockserver.com", "testpassword" );
+//            JsonNode node = postCreateOrgAndAdmin( "test-org-1", "test-user-1", "Test User",
+//                    "test-user-1@mockserver.com", "testpassword" );
 
-            if (true ) return;
-            
-            refreshIndex("test-organization", "test-app");
 
-            UUID owner_uuid =
-                    UUID.fromString( node.findPath( "data" ).findPath( "owner" ).findPath( "uuid" ).textValue() );
+            final String username = "registrationUser"+UUIDGenerator.newTimeUUID();
+            final String email = username+"@usergrid.com" ;
+            final String password = "password";
+
+            final TestUser user1 = new TestAppUser(username , password, email);
+
+            context.withOrg( "org" + UUIDGenerator.newTimeUUID() ).withApp( "app" + UUIDGenerator.newTimeUUID() ).withUser( user1 ).createNewOrgAndUser();
+            context.createAppForOrg();
+
+            final UUID owner_uuid = context.getActiveUser().getUuid();
+            
+//            refreshIndex("test-organization", "test-app");
+//
+//            UUID owner_uuid =
+//                    UUID.fromString( node.findPath( "data" ).findPath( "owner" ).findPath( "uuid" ).textValue() );
 
             List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( "test-user-1@mockserver.com" );
 
             assertFalse( inbox.isEmpty() );
 
             Message account_confirmation_message = inbox.get( 0 );
-            assertEquals( "User Account Confirmation: test-user-1@mockserver.com",
+            assertEquals( "User Account Confirmation: " + email,
                     account_confirmation_message.getSubject() );
 
             String token = getTokenFromMessage( account_confirmation_message );
@@ -99,11 +119,11 @@ public class RegistrationIT extends AbstractRestIT {
 
             setup.getMgmtSvc().disableAdminUser( owner_uuid );
 
-            refreshIndex("test-organization", "test-app");
+            refreshIndex(context.getOrgName(), context.getAppName());
 
             try {
                 resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-                        .queryParam( "username", "test-user-1" ).queryParam( "password", "testpassword" )
+                        .queryParam( "username", username ).queryParam( "password", password )
                         .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
                         .get( String.class );
                 fail( "request for disabled user should fail" );
@@ -117,7 +137,7 @@ public class RegistrationIT extends AbstractRestIT {
             setup.getMgmtSvc().deactivateUser( setup.getEmf().getManagementAppId(), owner_uuid );
             try {
                 resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-                        .queryParam( "username", "test-user-1" ).queryParam( "password", "testpassword" )
+                        .queryParam( "username", username ).queryParam( "password", password)
                         .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
                         .get( String.class );
                 fail( "request for deactivated user should fail" );
@@ -156,25 +176,6 @@ public class RegistrationIT extends AbstractRestIT {
     }
 
 
-    public JsonNode postCreateOrgAndAdmin( String organizationName, String username, String name, 
-            String email, String password ) throws IOException {
-
-        JsonNode node = null;
-        Map<String, String> payload = hashMap( "email", email )
-                .map( "username", username )
-                .map( "name", name ).map( "password", password )
-                .map( "organization", organizationName );
-
-        node = mapper.readTree( resource().path( "/management/organizations" )
-                .accept( MediaType.APPLICATION_JSON )
-                .type( MediaType.APPLICATION_JSON_TYPE )
-                .post( String.class, payload ));
-
-        assertNotNull( node );
-        logNode( node );
-        return node;
-    }
-
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public JsonNode postAddAdminToOrg( String organizationName, String email, String password, String token ) throws IOException {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8bab4e71/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java b/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java
index 5643710..401e026 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java
@@ -58,6 +58,8 @@ import org.apache.commons.lang.math.RandomUtils;
  * The following property expansion macro should be placed in this project.properties file:
  * <p/>
  * target.directory=${pom.build.directory}
+ *
+ * TODO this class does 2 things.  It loads spring and starts cassandra.  We should separate these concerns.
  */
 public class CassandraResource extends ExternalResource {
     public static final Logger LOG = LoggerFactory.getLogger( CassandraResource.class );
@@ -293,14 +295,14 @@ public class CassandraResource extends ExternalResource {
                 return;
             }
             
-            if ( forkCassandra ) {
-                startCassandraForked();
-            } else if (externalCassandra) {
-              startCassandraExternal();
-            }else {
-              
-                startCassandraEmbedded();
-            }
+//            if ( forkCassandra ) {
+//                startCassandraForked();
+//            } else if (externalCassandra) {
+//              startCassandraExternal();
+//            }else {
+//
+//                startCassandraEmbedded();
+//            }
         }
     }
     private void addShutdownHook(){