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 2015/02/27 00:23:49 UTC

[02/27] incubator-usergrid git commit: [USERGRID-327] Bringing DuplicateNameIT inline with the new REST test framework

[USERGRID-327] Bringing DuplicateNameIT inline with the new REST test framework


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

Branch: refs/heads/USERGRID-273-indexbuffer
Commit: 6e45b459acb6f7e7e8290095bf1ac1da0ff23cd4
Parents: 198f479
Author: ryan bridges <rb...@apigee.com>
Authored: Mon Jan 12 14:40:02 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Thu Feb 5 11:59:55 2015 -0500

----------------------------------------------------------------------
 .../collection/DuplicateNameIT.java             | 64 +++++++-------------
 1 file changed, 23 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e45b459/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java
index 5c98785..d01c533 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java
@@ -16,57 +16,39 @@
 
 package org.apache.usergrid.rest.applications.collection;
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import java.io.IOException;
-import java.util.Map;
-import org.apache.usergrid.corepersistence.TestGuiceModule;
-import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.resource.CustomCollection;
-import org.apache.usergrid.utils.MapUtils;
-import static org.junit.Assert.fail;
-import org.junit.Rule;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 
-public class DuplicateNameIT extends AbstractRestIT {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
-    private static final Logger logger = LoggerFactory.getLogger( DuplicateNameIT.class );
 
-    @Rule
-    public TestContextSetup context = new TestContextSetup( this );
+public class DuplicateNameIT extends AbstractRestIT {
 
+    /**
+     * Test to ensure that an error is returned when
+     * attempting to POST multiple entities to the
+     * same collection with the same name
+     */
     @Test
     public void duplicateNamePrevention() {
 
-        CustomCollection things = context.application().customCollection( "things" );
-
-        Map<String, String> entity = MapUtils.hashMap( "name", "enzo" );
-
-        try {
-            things.create( entity );
-        } catch (IOException ex) {
-            logger.error("Cannot create entity", ex);
-        }
-
-        refreshIndex( context.getAppUuid() );
-
-        Injector injector = Guice.createInjector( new TestGuiceModule( null ) ); 
-        SerializationFig sfig = injector.getInstance( SerializationFig.class );
-
-        // wait for any temporary unique value records to timeout
-        try { Thread.sleep( sfig.getTimeout() * 1100 ); } catch (InterruptedException ignored) {} 
-
+        String collectionName = "things";
+        Entity entity = new Entity();
+        entity.put("name", "enzo");
+        //Create an entity named "enzo" in the "things" collection
+        entity = this.app().collection(collectionName).post(entity);
+        refreshIndex();
         try {
-            things.create( entity );
+            // Try to create a second entity in "things" with the name "enzo".
+            this.app().collection(collectionName).post(entity);
+            // fail if the POST did not return an exception
             fail("Should not have created duplicate entity");
-            
-        } catch (Exception ex) {
-            // good
+        } catch (UniformInterfaceException uie) {
+            //Check for an exception
+            assertEquals(400, uie.getResponse().getStatus());
         }
     }
 }