You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by ro...@apache.org on 2015/01/12 19:19:09 UTC
[01/13] incubator-usergrid git commit: fixing ownershipResourceIT
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o 1ef432545 -> 8b338b184
fixing ownershipResourceIT
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/d2faf43e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/d2faf43e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/d2faf43e
Branch: refs/heads/two-dot-o
Commit: d2faf43eae7ba8d41d73d953205c9258061a98a6
Parents: 1404292
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Jan 5 21:19:09 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Jan 5 21:19:09 2015 -0700
----------------------------------------------------------------------
.../users/ConnectionResourceTest.java | 125 ++++-----
.../collection/users/OwnershipResourceIT.java | 275 +++++++++----------
2 files changed, 196 insertions(+), 204 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2faf43e/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
index 21b30d3..0e18b13 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
@@ -24,11 +24,13 @@ import java.util.UUID;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.CollectionEndpoint;
+import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.Collection;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
import org.junit.Rule;
import org.junit.Test;
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.resource.CustomCollection;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
@@ -47,61 +49,53 @@ import static org.apache.usergrid.utils.MapUtils.hashMap;
* @since 4.0
*/
public class ConnectionResourceTest extends AbstractRestIT {
- @Rule
- public TestContextSetup context = new TestContextSetup( this );
+
@Test
public void connectionsQueryTest() throws IOException {
- CustomCollection activities = context.customCollection( "peeps" );
+ CollectionEndpoint activities = this.app().collection("peeps");
- Map stuff = hashMap( "type", "chicken" );
+ Entity stuff = new Entity().chainPut("type", "chicken");
- activities.create( stuff );
+ activities.post(stuff);
- Map<String, Object> payload = new LinkedHashMap<String, Object>();
+ Entity payload = new Entity();
payload.put( "username", "todd" );
- Map<String, Object> objectOfDesire = new LinkedHashMap<String, Object>();
+ Entity objectOfDesire = new Entity();
objectOfDesire.put( "codingmunchies", "doritoes" );
- resource().path( "/test-organization/test-app/users" ).queryParam( "access_token", access_token )
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .post( String.class, payload );
+ Entity entity = this.app().collection("users").post(payload);
+
payload.put( "username", "scott" );
+ entity = this.app().collection("users").post(payload);
+ refreshIndex();
+
- resource().path( "/test-organization/test-app/users" ).queryParam( "access_token", access_token )
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .post( String.class, payload );
/*finish setting up the two users */
- refreshIndex("test-organization", "test-app");
- ClientResponse toddWant = resource().path( "/test-organization/test-app/users/todd/likes/peeps" )
- .queryParam( "access_token", access_token ).accept( MediaType.TEXT_HTML )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( ClientResponse.class, objectOfDesire );
+ entity = this.app().collection("users").entity("todd").connection("likes").entity("peeps").post();
- assertEquals( 200, toddWant.getStatus() );
+ assertNotNull(entity);
- refreshIndex("test-organization", "test-app");
+ refreshIndex();
- JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/peeps" ).queryParam( "access_token", access_token )
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .get( String.class ));
+ Collection collection = this.app().collection("peeps").get();
- String uuid = node.get( "entities" ).get( 0 ).get( "uuid" ).textValue();
+ String uuid = collection.next().get("uuid").toString();
try {
- node = mapper.readTree( resource().path( "/test-organization/test-app/users/scott/likes/" + uuid )
- .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+ entity = this.app().collection("users").entity("scott").connection("likes").entity(uuid).get();
+
assert ( false );
}
catch ( UniformInterfaceException uie ) {
@@ -113,26 +107,26 @@ public class ConnectionResourceTest extends AbstractRestIT {
@Test
public void connectionsLoopbackTest() throws IOException {
- CustomCollection things = context.customCollection( "things" );
+ CollectionEndpoint things = this.app().collection("things");
- UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
+ UUID thing1Id = things.post( new Entity().chainPut("name", "thing1") ).getUuid();
- UUID thing2Id = getEntityId( things.create( hashMap( "name", "thing2" ) ), 0 );
+ UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
//create the connection
things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
//test we have the "likes" in our connection meta data response
- JsonNode response = things.entity( "thing1" ).get();
+ Entity response = things.entity( "thing1" ).get();
- String url = getEntity( response, 0 ).get( "metadata" ).get( "connections" ).get( "likes" ).asText();
+ String url =((Map) ((Map)response.get( "metadata" )).get( "connections" )).get( "likes" ).toString();
assertNotNull( "Connection url returned in entity", url );
@@ -143,16 +137,17 @@ public class ConnectionResourceTest extends AbstractRestIT {
//now that we know the URl is correct, follow it
- response = context.customCollection( url ).get();
+ Collection collection = this.app().collection(url).get();
- UUID returnedUUID = getEntityId( response, 0 );
+ Entity entity =collection.next();
+ UUID returnedUUID = entity.getUuid();
assertEquals( thing2Id, returnedUUID );
//now follow the loopback, which should be pointers to the other entity
- url = getEntity( response, 0 ).get( "metadata" ).get( "connecting" ).get( "likes" ).asText();
+ url = ((Map) ((Map)entity.get( "metadata" )).get( "connections" )).get("likes").toString();
assertNotNull( "Incoming edge URL provited", url );
@@ -161,9 +156,9 @@ public class ConnectionResourceTest extends AbstractRestIT {
//now we should get thing1 from the loopback url
- response = context.customCollection( url ).get();
+ collection = this.app().collection(url).get();
- UUID returned = getEntityId( response, 0 );
+ UUID returned = collection.next().getUuid();
assertEquals( "Should point to thing1 as an incoming entity connection", thing1Id, returned );
}
@@ -172,26 +167,26 @@ public class ConnectionResourceTest extends AbstractRestIT {
@Test
public void connectionsUUIDTest() throws IOException {
- CustomCollection things = context.customCollection( "things" );
+ CollectionEndpoint things = this.app().collection("things");
- UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
+ UUID thing1Id = things.post( new Entity().chainPut("name", "thing1") ).getUuid();
- UUID thing2Id = getEntityId( things.create( hashMap( "name", "thing2" ) ), 0 );
+ UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
//create the connection
things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
//test we have the "likes" in our connection meta data response
- JsonNode response = things.entity( "thing1" ).get();
+ Entity response = things.entity( "thing1" ).get();
- String url = getEntity( response, 0 ).get( "metadata" ).get( "connections" ).get( "likes" ).asText();
+ String url =((Map) ((Map)response.get( "metadata" )).get( "connections" )).get( "likes" ).toString();
assertNotNull( "Connection url returned in entity", url );
@@ -202,9 +197,9 @@ public class ConnectionResourceTest extends AbstractRestIT {
//now that we know the URl is correct, follow it
- response = context.customCollection( url ).get();
+ Collection collection = this.app().collection(url).get();
- UUID returnedUUID = getEntityId( response, 0 );
+ UUID returnedUUID =collection.next().getUuid();
assertEquals( thing2Id, returnedUUID );
@@ -214,7 +209,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
response = things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).get();
- UUID returned = getEntityId( response, 0 );
+ UUID returned = response.getUuid();
assertEquals( "Should point to thing2 as an entity connection", thing2Id, returned );
}
@@ -222,22 +217,22 @@ public class ConnectionResourceTest extends AbstractRestIT {
@Test //USERGRID-3011
public void connectionsDeleteSecondEntityInConnectionTest() throws IOException {
- CustomCollection things = context.customCollection( "things" );
+ CollectionEndpoint things = this.app().collection("things");
- UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
+ UUID thing1Id = things.post( new Entity().chainPut("name", "thing1") ).getUuid();
- UUID thing2Id = getEntityId( things.create( hashMap( "name", "thing2" ) ), 0 );
+ UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
//create the connection
things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
- JsonNode response = things.entity( "thing2" ).delete();
+ ApiResponse response = things.entity( "thing2" ).delete();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
- JsonNode node = things.entity ( "thing2" ).get();
+ Entity node = things.entity ( "thing2" ).get();
assertNull(node);
@@ -246,22 +241,22 @@ public class ConnectionResourceTest extends AbstractRestIT {
@Test //USERGRID-3011
public void connectionsDeleteFirstEntityInConnectionTest() throws IOException {
- CustomCollection things = context.customCollection( "things" );
+ CollectionEndpoint things = this.app().collection("things");
- UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
+ UUID thing1Id = things.post( new Entity().chainPut("name", "thing1") ).getUuid();
- UUID thing2Id = getEntityId( things.create( hashMap( "name", "thing2" ) ), 0 );
+ UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
//create the connection
things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
- JsonNode response = things.entity( "thing1" ).delete();
+ ApiResponse response = things.entity( "thing1" ).delete();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
- JsonNode node = things.entity ( "thing1" ).get();
+ Entity node = things.entity ( "thing1" ).get();
assertNull(node);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2faf43e/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
index 17d99ec..3e4e94d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
@@ -19,16 +19,15 @@ package org.apache.usergrid.rest.applications.collection.users;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
+
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.CollectionEndpoint;
+import org.apache.usergrid.rest.test.resource2point0.model.*;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.apache.usergrid.cassandra.Concurrent;
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.resource.Connection;
-import org.apache.usergrid.rest.test.resource.CustomCollection;
-import org.apache.usergrid.rest.test.resource.app.queue.DevicesCollection;
-import org.apache.usergrid.rest.test.security.TestAppUser;
-import org.apache.usergrid.rest.test.security.TestUser;
+
import org.apache.usergrid.utils.MapUtils;
import static org.junit.Assert.assertEquals;
@@ -44,35 +43,46 @@ import static org.junit.Assert.fail;
@Concurrent()
public class OwnershipResourceIT extends AbstractRestIT {
- @Rule
- public TestContextSetup context = new TestContextSetup( this );
+ private CollectionEndpoint usersResource;
+ private User user1;
+ private User user2;
+
+ @Before
+ public void setup(){
+ this.usersResource = this.app().collection("users");
+ String email = "testuser1@usergrid.org";
+ String email2 = "testuser2@usergrid.org";
+
+ user2 = new User("testuser2","testuser2", email, "password" );
+ user1 = new User("testuser1","testuser1", email, "password" );
+ user1 = new User(this.usersResource.post(user1));
+ user2 = new User(this.usersResource.post(user2));
+
+ refreshIndex();
+ }
@Test
public void meVerify() throws Exception {
- context.clearUser();
+ this.app().token().clearToken();
- String email = "testuser1@usergrid.org";
- TestUser user1 = new TestAppUser( email, "password", email ).create( context );
- refreshIndex(context.getOrgName(), context.getAppName());
- user1.login( context ).makeActive( context );
+ Token token = this.app().token().post(new Token(user1.getUsername(),"password"));
- refreshIndex(context.getOrgName(), context.getAppName());
+ Entity userNode = usersResource.entity("me").get();
- String token = user1.getToken();
- JsonNode userNode = context.application().users().user( "me" ).get();
assertNotNull( userNode );
- String uuid = userNode.get( "entities" ).get( 0 ).get( "uuid" ).textValue();
+ String uuid = userNode.getUuid().toString();
assertNotNull( uuid );
- setup.getMgmtSvc().revokeAccessTokenForAppUser( token );
+ usersResource.entity(user1).connection("revoketokens").post(new Entity().chainPut("token", token.getAccessToken()));
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
try {
- context.application().users().user( "me" ).get();
+ userNode = usersResource.entity("me").get();
+
fail();
}
catch ( Exception ex ) {
@@ -86,98 +96,93 @@ public class OwnershipResourceIT extends AbstractRestIT {
public void contextualPathOwnership() throws IOException {
// anonymous user
- context.clearUser();
+ this.app().token().clearToken();
- refreshIndex(context.getOrgName(), context.getAppName());
- TestUser user1 = new TestAppUser( "testuser1@usergrid.org", "password", "testuser1@usergrid.org" ).create( context );
- refreshIndex(context.getOrgName(), context.getAppName());
- user1.login( context );
- user1.makeActive( context );
+ Token token = this.app().token().post(new Token(user1.getUsername(),"password"));
- refreshIndex(context.getOrgName(), context.getAppName());
// create device 1 on user1 devices
- context.application().users().user( "me" ).devices()
- .create( MapUtils.hashMap( "name", "device1" ).map( "number", "5551112222" ) );
+ usersResource.entity("me").collection("devices")
+ .post(new Entity( ).chainPut("name", "device1").chainPut("number", "5551112222"));
+ refreshIndex();
// anonymous user
- context.clearUser();
- refreshIndex(context.getOrgName(), context.getAppName());
+ this.app().token().clearToken();
// create device 2 on user 2
- TestUser user2 = new TestAppUser( "testuser2@usergrid.org", "password", "testuser2@usergrid.org" ).create( context );
- refreshIndex(context.getOrgName(), context.getAppName());
- user2.login( context );
- user2.makeActive( context );
-
- refreshIndex(context.getOrgName(), context.getAppName());
-
- context.application().users().user( "me" ).devices()
- .create( MapUtils.hashMap( "name", "device2" ).map( "number", "5552223333" ) );
+ token = this.app().token().post(new Token(user2.getUsername(),"password"));
+ usersResource.entity("me").collection("devices")
+ .post(new Entity( ).chainPut("name", "device2").chainPut("number", "5552223333"));
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
// now query on user 1.
+ token = this.app().token().post(new Token(user1.getUsername(),"password"));
- DevicesCollection devices = context.withUser( user1 ).application().users().user( "me" ).devices();
+ CollectionEndpoint devices = usersResource.entity( user1 ).collection("devices");
- JsonNode data = devices.device( "device1" ).get();
+ Entity data = devices.entity("device1").get();
assertNotNull( data );
- assertEquals( "device1", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals("device1", data.get("name").toString());
// check we can't see device2
- data = devices.device( "device2" ).get();
+ data = devices.entity("device2").get();
assertNull( data );
// do a collection load, make sure we're not loading device 2
- data = devices.get();
+ Collection devicesData = devices.get();
- assertEquals( "device1", getEntity( data, 0 ).get( "name" ).asText() );
- assertNull( getEntity( data, 1 ) );
+ assertEquals("device1", devicesData.next().get("name").toString());
+ assertTrue(!devicesData.hasNext());
// log in as user 2 and check it
- devices = context.withUser( user2 ).application().users().user( "me" ).devices();
+ token = this.app().token().post(new Token(user2.getUsername(),"password"));
- data = devices.device( "device2" ).get();
+ devices = usersResource.entity("me").collection("devices");
+
+ data = devices.entity("device2").get();
assertNotNull( data );
- assertEquals( "device2", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "device2", data.get("name").toString() );
// check we can't see device1
- data = devices.device( "device1" ).get();
+ data = devices.entity("device1").get();
assertNull( data );
// do a collection load, make sure we're not loading device 1
- data = devices.get();
+ devicesData = devices.get();
- assertEquals( "device2", getEntity( data, 0 ).get( "name" ).asText() );
- assertNull( getEntity( data, 1 ) );
+ assertEquals("device2", devicesData.next().get("name").toString());
+ assertTrue(!devicesData.hasNext());
// we should see both devices when loaded from the root application
// test for user 1
+ token = this.app().token().post(new Token(user1.getUsername(),"password"));
- devices = context.withUser( user1 ).application().devices();
- data = devices.device( "device1" ).get();
+ devices = usersResource.entity(user1).collection("devices");
+ data = devices.entity("device1").get();
assertNotNull( data );
- assertEquals( "device1", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "device1", data.get("name").toString() );
- data = devices.device( "device2" ).get();
+ data = devices.entity("device2").get();
assertNotNull( data );
- assertEquals( "device2", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "device2", data.get("name").toString() );
// test for user 2
- data = context.withUser( user2 ).application().devices().device( "device1" ).get();
+ token = this.app().token().post(new Token(user2.getUsername(),"password"));
+
+ data =usersResource.entity(user2).collection("devices").entity( "device1" ).get();
assertNotNull( data );
- assertEquals( "device1", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "device1",data.get( "name" ).toString() );
- data = devices.device( "device2" ).get();
+ data = devices.entity( "device2" ).get();
assertNotNull( data );
- assertEquals( "device2", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "device2",data.get( "name" ).toString() );
}
@@ -185,66 +190,56 @@ public class OwnershipResourceIT extends AbstractRestIT {
public void contextualConnectionOwnership() throws IOException {
// anonymous user
- context.clearUser();
+ this.app().token().clearToken();
- refreshIndex(context.getOrgName(), context.getAppName());
+ this.app().token().post(new Token(user1.getUsername(),"password"));
- String email = "testuser1@usergrid.org";
- TestUser user1 = new TestAppUser( email, "password", email ).create( context );
- refreshIndex(context.getOrgName(), context.getAppName());
- user1.login( context ).makeActive( context );
// create a 4peaks restaurant
- JsonNode data = context.application()
- .customCollection( "restaurants" ).create( MapUtils.hashMap( "name", "4peaks" ) );
+ Entity data = this.app().collection("restaurants").post(new Entity().chainPut("name", "4peaks"));
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
// create our connection
- data = context.application().users().user( "me" )
- .connection( "likes" ).collection( "restaurants" ).entity( "4peaks" ).post();
+ data = usersResource.entity("me")
+ .connection("likes").collection( "restaurants" ).entity( "4peaks" ).post();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
- String peaksId = getEntity( data, 0 ).get( "uuid" ).asText();
+ String peaksId = data.getUuid().toString();
// anonymous user
- context.clearUser();
+ this.app().token().clearToken();
// create a restaurant and link it to user 2
- email = "testuser2@usergrid.org";
- TestUser user2 = new TestAppUser( email, "password", email ).create( context );
- refreshIndex(context.getOrgName(), context.getAppName());
+ this.app().token().post(new Token(user2.getUsername(),"password"));
- user2.login( context ).makeActive( context );
- refreshIndex(context.getOrgName(), context.getAppName());
+ data = this.app().collection("restaurants")
+ .post(new Entity().chainPut("name", "arrogantbutcher"));
+ refreshIndex();
- data = context.application().customCollection( "restaurants" )
- .create( MapUtils.hashMap( "name", "arrogantbutcher" ) );
- refreshIndex(context.getOrgName(), context.getAppName());
-
- data = context.application().users().user( "me" ).connection( "likes" ).collection( "restaurants" )
+ data = usersResource.entity("me").connection( "likes" ).collection( "restaurants" )
.entity( "arrogantbutcher" ).post();
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
- String arrogantButcherId = getEntity( data, 0 ).get( "uuid" ).asText();
+ String arrogantButcherId = data.getUuid().toString();
// now query on user 1.
+ this.app().token().post(new Token(user1.getUsername(),"password"));
- CustomCollection likeRestaurants =
- context.withUser( user1 ).application().users().user( "me" ).connection( "likes" )
+ CollectionEndpoint likeRestaurants =
+ usersResource.entity( "me" ).connection( "likes" )
.collection( "restaurants" );
- refreshIndex(context.getOrgName(), context.getAppName());
// check we can get it via id
- data = likeRestaurants.entity( peaksId ).get();
+ data = likeRestaurants.entity(peaksId).get();
assertNotNull( data );
- assertEquals( "4peaks", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals("4peaks", data.get("name").toString());
// check we can get it by name
data = likeRestaurants.entity( "4peaks" ).get();
assertNotNull( data );
- assertEquals( "4peaks", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "4peaks", data.get("name").toString() );
// check we can't see arrogantbutcher by name or id
data = likeRestaurants.entity( "arrogantbutcher" ).get();
@@ -254,22 +249,24 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertNull( data );
// do a collection load, make sure we're not entities we shouldn't see
- data = likeRestaurants.get();
+ Collection collectionData = likeRestaurants.get();
- assertEquals( "4peaks", getEntity( data, 0 ).get( "name" ).asText() );
- assertNull( getEntity( data, 1 ) );
+ assertEquals("4peaks", collectionData.next().get("name").toString());
+ assertNull( collectionData.next() );
// log in as user 2 and check it
- likeRestaurants = context.withUser( user2 ).application().users().user( "me" ).connection( "likes" )
+ this.app().token().post(new Token(user2.getUsername(),"password"));
+
+ likeRestaurants = usersResource.entity("me").connection( "likes" )
.collection( "restaurants" );
data = likeRestaurants.entity( arrogantButcherId ).get();
assertNotNull( data );
- assertEquals( "arrogantbutcher", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "arrogantbutcher", data.get("name").toString() );
data = likeRestaurants.entity( "arrogantbutcher" ).get();
assertNotNull( data );
- assertEquals( "arrogantbutcher", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "arrogantbutcher", data.get("name").toString() );
// check we can't see 4peaks
data = likeRestaurants.entity( "4peaks" ).get();
@@ -279,37 +276,39 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertNull( data );
// do a collection load, make sure we're not loading device 1
- data = likeRestaurants.get();
+ collectionData = likeRestaurants.get();
- assertEquals( "arrogantbutcher", getEntity( data, 0 ).get( "name" ).asText() );
- assertNull( getEntity( data, 1 ) );
+ assertEquals("arrogantbutcher", collectionData.next().get("name").toString());
+ assertNull( collectionData.next() );
// we should see both devices when loaded from the root application
// test for user 1
+ this.app().token().post(new Token(user1.getUsername(),"password"));
- CustomCollection restaurants = context.withUser( user1 ).application().customCollection( "restaurants" );
+ CollectionEndpoint restaurants = this.app().collection( "restaurants" );
data = restaurants.entity( "4peaks" ).get();
assertNotNull( data );
- assertEquals( "4peaks", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "4peaks", data.get("name").toString() );
data = restaurants.entity( "arrogantbutcher" ).get();
assertNotNull( data );
- assertEquals( "arrogantbutcher", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "arrogantbutcher", data.get("name").toString() );
// test for user 2
- restaurants = context.withUser( user1 ).application().customCollection( "restaurants" );
+ this.app().token().post(new Token(user2.getUsername(),"password"));
+ restaurants = this.app().collection("restaurants");
data = restaurants.entity( "4peaks" ).get();
assertNotNull( data );
- assertEquals( "4peaks", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "4peaks",data.get("name").toString() );
data = restaurants.entity( "arrogantbutcher" ).get();
assertNotNull( data );
- assertEquals( "arrogantbutcher", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "arrogantbutcher",data.get("name").toString() );
}
@@ -317,63 +316,61 @@ public class OwnershipResourceIT extends AbstractRestIT {
public void contextualConnectionOwnershipGuestAccess() throws IOException {
//set up full GET,PUT,POST,DELETE access for guests
- context.application().customCollection( "roles" ).entity( "guest" ).collection( "permissions" )
- .create( MapUtils.hashMap( "permission", "get,put,post,delete:/**" ) );
-
+ this.app().collection("roles").entity( "guest" ).collection( "permissions" )
+ .post(new Entity().chainPut("permission", "get,put,post,delete:/**"));
- // anonymous user
- context.clearUser();
- JsonNode city = context.application().customCollection( "cities" ).create( MapUtils.hashMap( "name", "tempe" ) );
+ Entity city = this.app().collection("cities").post(new Entity().chainPut("name", "tempe"));
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
- String cityId = getEntity( city, 0 ).get( "uuid" ).asText();
+ String cityId = city.get("uuid").toString();
// create a 4peaks restaurant
- JsonNode data = context.application().customCollection( "cities" ).entity( "tempe" ).connection( "likes" )
- .collection( "restaurants" ).create( MapUtils.hashMap( "name", "4peaks" ) );
+ Entity data = this.app().collection("cities").entity( "tempe" ).connection( "likes" )
+ .collection( "restaurants" ).post(new Entity().chainPut("name", "4peaks"));
- String peaksId = getEntity( data, 0 ).get( "uuid" ).asText();
+ String peaksId = data.get("uuid").toString();
- data = context.application().customCollection( "cities" ).entity( "tempe" ).connection( "likes" )
- .collection( "restaurants" ).create( MapUtils.hashMap( "name", "arrogantbutcher" ) );
+ data = this.app().collection("cities").entity( "tempe" ).connection( "likes" )
+ .collection( "restaurants" ).post(new Entity().chainPut("name", "arrogantbutcher"));
- String arrogantButcherId = getEntity( data, 0 ).get( "uuid" ).asText();
+ String arrogantButcherId = data.get("uuid").toString();
// now query on user 1.
+ this.app().token().post(new Token(user1.getUsername(),"password"));
- Connection likeRestaurants =
- context.application().customCollection( "cities" ).entity( "tempe" ).connection( "likes" );
+ CollectionEndpoint likeRestaurants =
+ this.app().collection("cities").entity( "tempe" ).connection( "likes" );
- refreshIndex(context.getOrgName(), context.getAppName());
+ refreshIndex();
// check we can get it via id with no collection name
data = likeRestaurants.entity( peaksId ).get();
assertNotNull( data );
- assertEquals( "4peaks", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "4peaks", data.get("name").toString() );
data = likeRestaurants.entity( arrogantButcherId ).get();
- assertEquals( "arrogantbutcher", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "arrogantbutcher", data.get("name").toString() );
// check we can get it via id with a collection name
data = likeRestaurants.collection( "restaurants" ).entity( peaksId ).get();
assertNotNull( data );
- assertEquals( "4peaks", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "4peaks", data.get("name").toString() );
data = likeRestaurants.collection( "restaurants" ).entity( arrogantButcherId ).get();
- assertEquals( "arrogantbutcher", getEntity( data, 0 ).get( "name" ).asText() );
+ assertEquals( "arrogantbutcher", data.get("name").toString() );
// do a delete either token should work
- data = likeRestaurants.collection( "restaurants" ).entity( peaksId ).delete();
+ ApiResponse deleteResponse = likeRestaurants.collection( "restaurants" ).entity( peaksId ).delete();
- assertNotNull( data );
- assertEquals( "4peaks", getEntity( data, 0 ).get( "name" ).asText() );
+ assertNotNull( deleteResponse );
+ assertEquals( "4peaks", deleteResponse.getEntities().get(0).get("name").toString() );
- data = likeRestaurants.collection( "restaurants" ).entity( arrogantButcherId ).delete();
+ deleteResponse = likeRestaurants.collection( "restaurants" ).entity( arrogantButcherId ).delete();
- assertNotNull( data );
- assertEquals( "arrogantbutcher", getEntity( data, 0 ).get( "name" ).asText() );
+ assertNotNull( deleteResponse );
+ assertEquals( "arrogantbutcher", deleteResponse.getEntities().get(0).get("name").toString() );
}
}
[04/13] incubator-usergrid git commit: finished test
Posted by ro...@apache.org.
finished test
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/01173d9a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/01173d9a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/01173d9a
Branch: refs/heads/two-dot-o
Commit: 01173d9a00b1d013edf1d3fb047ec4b5f1c2852f
Parents: e964551
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jan 6 09:29:10 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jan 6 09:29:10 2015 -0700
----------------------------------------------------------------------
.../collection/users/OwnershipResourceIT.java | 67 +++++++++++++++-----
1 file changed, 50 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/01173d9a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
index 3e4e94d..fc85ca0 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.rest.applications.collection.users;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
+import com.sun.jersey.api.client.UniformInterfaceException;
import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
import org.apache.usergrid.rest.test.resource2point0.endpoints.CollectionEndpoint;
import org.apache.usergrid.rest.test.resource2point0.model.*;
@@ -53,7 +54,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
String email = "testuser1@usergrid.org";
String email2 = "testuser2@usergrid.org";
- user2 = new User("testuser2","testuser2", email, "password" );
+ user2 = new User("testuser2","testuser2", email2, "password" );
user1 = new User("testuser1","testuser1", email, "password" );
user1 = new User(this.usersResource.post(user1));
@@ -127,8 +128,13 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertEquals("device1", data.get("name").toString());
// check we can't see device2
- data = devices.entity("device2").get();
- assertNull( data );
+ int status = 0;
+ try {
+ data = devices.entity("device2").get();
+ }catch (UniformInterfaceException e){
+ status = e.getResponse().getStatus();
+ }
+ assertEquals( status,404 );
// do a collection load, make sure we're not loading device 2
Collection devicesData = devices.get();
@@ -146,8 +152,13 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertEquals( "device2", data.get("name").toString() );
// check we can't see device1
+ status = 0;
+ try{
data = devices.entity("device1").get();
- assertNull( data );
+ }catch (UniformInterfaceException e){
+ status = e.getResponse().getStatus();
+ }
+ assertEquals( status,404 );
// do a collection load, make sure we're not loading device 1
devicesData = devices.get();
@@ -157,15 +168,14 @@ public class OwnershipResourceIT extends AbstractRestIT {
// we should see both devices when loaded from the root application
+ devices = this.app().collection("devices");
// test for user 1
token = this.app().token().post(new Token(user1.getUsername(),"password"));
- devices = usersResource.entity(user1).collection("devices");
data = devices.entity("device1").get();
assertNotNull( data );
assertEquals( "device1", data.get("name").toString() );
-
data = devices.entity("device2").get();
assertNotNull( data );
@@ -174,7 +184,8 @@ public class OwnershipResourceIT extends AbstractRestIT {
// test for user 2
token = this.app().token().post(new Token(user2.getUsername(),"password"));
- data =usersResource.entity(user2).collection("devices").entity( "device1" ).get();
+
+ data = devices.entity( "device1" ).get();
assertNotNull( data );
assertEquals( "device1",data.get( "name" ).toString() );
@@ -242,17 +253,27 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertEquals( "4peaks", data.get("name").toString() );
// check we can't see arrogantbutcher by name or id
- data = likeRestaurants.entity( "arrogantbutcher" ).get();
- assertNull( data );
+ int status = 200;
+ try {
+ data = likeRestaurants.entity("arrogantbutcher").get();
+ }catch (UniformInterfaceException e){
+ status = e.getResponse().getStatus();
+ }
+ assertEquals(status, 404);
- data = likeRestaurants.entity( arrogantButcherId ).get();
- assertNull( data );
+ status = 200;
+ try {
+ data = likeRestaurants.entity( arrogantButcherId ).get();
+ }catch (UniformInterfaceException e){
+ status = e.getResponse().getStatus();
+ }
+ assertEquals(status, 404);
// do a collection load, make sure we're not entities we shouldn't see
Collection collectionData = likeRestaurants.get();
assertEquals("4peaks", collectionData.next().get("name").toString());
- assertNull( collectionData.next() );
+ assertTrue( !collectionData.hasNext() );
// log in as user 2 and check it
this.app().token().post(new Token(user2.getUsername(),"password"));
@@ -269,17 +290,29 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertEquals( "arrogantbutcher", data.get("name").toString() );
// check we can't see 4peaks
- data = likeRestaurants.entity( "4peaks" ).get();
- assertNull( data );
+ status = 200;
+ try {
+ data = likeRestaurants.entity( "4peaks" ).get();
+ }catch (UniformInterfaceException e){
+ status = e.getResponse().getStatus();
+ }
+ assertEquals( status,404 );
- data = likeRestaurants.entity( peaksId ).get();
- assertNull( data );
+
+
+ status = 200;
+ try {
+ data = likeRestaurants.entity( peaksId ).get();
+
+ }catch (UniformInterfaceException e){
+ status = e.getResponse().getStatus();
+ }
// do a collection load, make sure we're not loading device 1
collectionData = likeRestaurants.get();
assertEquals("arrogantbutcher", collectionData.next().get("name").toString());
- assertNull( collectionData.next() );
+ assertTrue( !collectionData.hasNext() );
// we should see both devices when loaded from the root application
[10/13] incubator-usergrid git commit: Added missing comment to tests
in OwnershipResourceIT Added revamped comments and cleaned the tests in
ConnectionResourceTest
Posted by ro...@apache.org.
Added missing comment to tests in OwnershipResourceIT
Added revamped comments and cleaned the tests in ConnectionResourceTest
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/944bcf9b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/944bcf9b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/944bcf9b
Branch: refs/heads/two-dot-o
Commit: 944bcf9b1a480699a8343190a4820161b9f5ee3e
Parents: 0b89441
Author: grey <gr...@apigee.com>
Authored: Thu Jan 8 11:45:16 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Jan 8 11:45:16 2015 -0800
----------------------------------------------------------------------
.../users/ConnectionResourceTest.java | 151 ++++++++++---------
.../collection/users/OwnershipResourceIT.java | 6 +-
2 files changed, 84 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/944bcf9b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
index 2949b85..8ab63f7 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
@@ -30,6 +30,8 @@ import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
import org.apache.usergrid.rest.test.resource2point0.model.Collection;
import org.apache.usergrid.rest.test.resource2point0.model.Entity;
import org.apache.usergrid.rest.test.resource2point0.model.User;
+
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -42,86 +44,98 @@ import static org.junit.Assert.*;
/**
- * // TODO: Document this
- *
- * @author ApigeeCorporation
- * @since 4.0
+ * Contains tests that center around using connections with entities and users.
*/
public class ConnectionResourceTest extends AbstractRestIT {
+ private CollectionEndpoint thingsResource;
+ private UUID thing1Id;
+ private UUID thing2Id;
- @Test
- public void connectionsQueryTest() throws IOException {
+ /**
+ * Setup two thing objects for use in the following tests
+ */
+ @Before
+ public void setup(){
+ this.thingsResource = this.app().collection("things");
+
+ thing1Id = thingsResource.post( new Entity().chainPut("name", "thing1") ).getUuid();
+
+ thing2Id = thingsResource.post( new Entity().chainPut("name", "thing2") ).getUuid();
+ refreshIndex();
+ }
+ /**
+ * Checks to see that a connection associated with one user cannot be retrieved by a different user.
+ * @throws IOException
+ */
+ @Test
+ public void connectionMisMatchTest() throws IOException {
+ //Creates collection and posts a chicken entity to it.
CollectionEndpoint activities = this.app().collection("peeps");
Entity stuff = new Entity().chainPut("name", "chicken").chainPut("type","chicken");
activities.post(stuff);
-
+ //Create two users
User payload = new User("todd", "todd", "todd@apigee.com", "password");
- payload.put("username", "todd");
this.app().collection("users").post(payload);
payload = new User("scott", "scott", "scott@apigee.com", "password");
this.app().collection("users").post(payload);
refreshIndex();
- /*finish setting up the two users */
-
+ //Set user Todd to connect to the chicken entity.
Entity entity = this.app().collection("users").entity("todd").connection("likes").collection("peeps").entity("chicken").post();
assertNotNull(entity);
refreshIndex();
+ //Get the collection and get the chicken entity.
Collection collection = this.app().collection("peeps").get();
String uuid = collection.next().get("uuid").toString();
-
+ //Set user Scott to get back a nonexistant connection.
try {
- entity = this.app().collection("users").entity("scott").connection("likes").entity(uuid).get();
+ this.app().collection("users").entity("scott").connection("likes").entity(uuid).get();
assert ( false );
}
catch ( UniformInterfaceException uie ) {
- assertEquals( 404, uie.getResponse().getClientResponseStatus().getStatusCode() );
+ assertEquals( 404, uie.getResponse().getStatus() );
}
}
+ /**
+ * Checks that we can setup a connection loop and that we can retrieve both entities from the loop.
+ * @throws IOException
+ */
@Test
public void connectionsLoopbackTest() throws IOException {
- CollectionEndpoint things = this.app().collection("things");
-
- UUID thing1Id = things.post( new Entity().chainPut("name", "thing1") ).getUuid();
-
- UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
-
- refreshIndex();
-
- //create the connection
- things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
- things.entity( thing2Id ).connection( "likes" ).entity( thing1Id ).post();
+ //create a connection loop by having thing1 connect to thing2 and vise versa.
+ thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
+ thingsResource.entity( thing2Id ).connection( "likes" ).entity( thing1Id ).post();
refreshIndex();
- //test we have the "likes" in our connection meta data response
-
+ //Do a get on thing1 to make sure we have the connection present
Collection collection =this.app().collection("things").entity(thing1Id).connection( "likes" ).get();
assertTrue("Connection url returned in entity", collection.hasNext());
+ //Verify that thing1 is connected to thing2
UUID returnedUUID = collection.next().getUuid();
assertEquals( thing2Id, returnedUUID );
- //now follow the loopback, which should be pointers to the other entity
+ //now follow the loopback from thing2, which should be pointers to thing1
collection = this.app().collection("things").entity(thing2Id).connection("likes").get();
@@ -131,38 +145,32 @@ public class ConnectionResourceTest extends AbstractRestIT {
}
+ /**
+ * Checks that we can get a valid uuid from a connection url and follow it to the correct entity.
+ * @throws IOException
+ */
@Test
- public void connectionsUUIDTest() throws IOException {
-
- CollectionEndpoint things = this.app().collection("things");
-
- UUID thing1Id = things.post( new Entity().chainPut("name", "thing1") ).getUuid();
+ public void connectionsUrlTest() throws IOException {
- UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
+ //Create a connection between thing1 and thing2
+ thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
refreshIndex();
- //create the connection
- things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
-
-
- refreshIndex();
-
- //test we have the "likes" in our connection meta data response
-
- Entity response = things.entity( "thing1" ).get();
+ //Do a get on thing1 to make sure we have the connection present
+ Entity response = thingsResource.entity( "thing1" ).get();
String url =((Map) ((Map)response.get( "metadata" )).get( "connections" )).get("likes").toString();
assertNotNull( "Connection url returned in entity", url );
- //trim off the start /
+ //trim off the starting / from the url.
url = url.substring( 1 );
- //now that we know the URl is correct, follow it
+ //now that we know the URl is correct, follow it to get the entity in the connection
Collection collection = this.app().collection(url).get();
@@ -170,38 +178,37 @@ public class ConnectionResourceTest extends AbstractRestIT {
assertEquals( thing2Id, returnedUUID );
- //get on the collection works, now get it directly by uuid
-
- //now we should get thing1 from the loopback url
-
- response = things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).get();
+ //get on the collection works, now get it directly by uuid. We should also get thing1 from the loopback url.
+ response = thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).get();
UUID returned = response.getUuid();
assertEquals( "Should point to thing2 as an entity connection", thing2Id, returned );
}
- @Test //USERGRID-3011
- public void connectionsDeleteSecondEntityInConnectionTest() throws IOException {
-
- CollectionEndpoint things = this.app().collection("things");
- UUID thing1Id = things.post( new Entity().chainPut("name", "thing1") ).getUuid();
+ /**
+ * Deletes the connected to entity and make sure the delete persists.
+ * @throws IOException
+ */
+ @Test //USERGRID-3011
+ public void deleteConnectedEntity() throws IOException {
- UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
+ //create the connection
+ thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
refreshIndex();
- //create the connection
- things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
-
- ApiResponse response = things.entity( "thing2" ).delete();
+ //Delete the connected entity.
+ thingsResource.entity( "thing2" ).delete();
refreshIndex();
+ //Make sure that we can no longer retrieve the entity.
int status = 0;
try {
- Entity node = things.entity("thing2").get();
+ thingsResource.entity("thing2").get();
+ fail( "Entity should have been deleted." );
}catch (UniformInterfaceException e){
status = e.getResponse().getStatus();
}
@@ -210,27 +217,29 @@ public class ConnectionResourceTest extends AbstractRestIT {
}
- @Test //USERGRID-3011
- public void connectionsDeleteFirstEntityInConnectionTest() throws IOException {
-
- CollectionEndpoint things = this.app().collection("things");
- UUID thing1Id = things.post( new Entity().chainPut("name", "thing1") ).getUuid();
+ /**
+ * Delete the connecting entity and make sure the delete persists.
+ * @throws IOException
+ */
+ @Test //USERGRID-3011
+ public void deleteConnectingEntity() throws IOException {
- UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
+ //create the connection
+ thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
refreshIndex();
- //create the connection
- things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
-
- ApiResponse response = things.entity( "thing1" ).delete();
+ //Delete the connecting entity
+ thingsResource.entity( "thing1" ).delete();
refreshIndex();
+ //Make sure that we can no longer retrieve the entity.
int status = 0;
try {
- Entity node = things.entity("thing1").get();
+ thingsResource.entity("thing1").get();
+ fail( "Entity should have been deleted." );
}catch (UniformInterfaceException e){
status = e.getResponse().getStatus();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/944bcf9b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
index 30b12f1..52e27c7 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
@@ -218,7 +218,8 @@ public class OwnershipResourceIT extends AbstractRestIT {
/**
- *
+ * Tests that we can have our own personal connections without being seen by other users, but are still visible
+ * from a root context.
* @throws IOException
*/
@Test
@@ -373,7 +374,8 @@ public class OwnershipResourceIT extends AbstractRestIT {
/**
- *
+ * Checks that a once guests permissions are opened up that a user can view the connections/entities
+ * and get/post/delete things on that connection.
* @throws IOException
*/
@Test
[11/13] incubator-usergrid git commit: Added in a bunch of comments
to clarify what was going on in PermissionsResourceIT
Posted by ro...@apache.org.
Added in a bunch of comments to clarify what was going on in PermissionsResourceIT
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/d567dd1a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/d567dd1a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/d567dd1a
Branch: refs/heads/two-dot-o
Commit: d567dd1af9d0a530e7cefa7b057cb2383fb4a787
Parents: 944bcf9
Author: grey <gr...@apigee.com>
Authored: Thu Jan 8 13:02:04 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Jan 8 13:02:04 2015 -0800
----------------------------------------------------------------------
.../collection/users/OwnershipResourceIT.java | 2 +-
.../collection/users/PermissionsResourceIT.java | 166 ++++++++++---------
2 files changed, 88 insertions(+), 80 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d567dd1a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
index 52e27c7..b335a1f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
@@ -219,7 +219,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
/**
* Tests that we can have our own personal connections without being seen by other users, but are still visible
- * from a root context.
+ * from a root context.
* @throws IOException
*/
@Test
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d567dd1a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
index 5f196bb..c72d906 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
@@ -50,7 +50,6 @@ import static org.junit.Assert.*;
/**
* Tests permissions of adding and removing users from roles as well as groups
*
- * @author tnine
*/
@Concurrent()
public class PermissionsResourceIT extends AbstractRestIT {
@@ -64,7 +63,11 @@ public class PermissionsResourceIT extends AbstractRestIT {
public PermissionsResourceIT() throws Exception {
}
-
+
+
+ /**
+ * Creates a user in the default org/app combo for use by all of the tests
+ */
@Before
public void setup(){
@@ -74,8 +77,14 @@ public class PermissionsResourceIT extends AbstractRestIT {
}
+ /**
+ * Tests that we can delete a role that is in use by a user.
+ * @throws IOException
+ */
@Test
public void deleteUserFromRole() throws IOException {
+
+ //Create a role and check the response
Entity data = new Entity().chainPut("name", ROLE);
Entity node = this.app().collection("roles").post(data);
@@ -85,6 +94,8 @@ public class PermissionsResourceIT extends AbstractRestIT {
assertEquals( ROLE, node.get("name").toString() );
refreshIndex();
+
+ //Post the user with a specific role into the users collection
node = this.app().collection("roles").entity(node).collection("users").entity(USER).post();
assertNull( node.get( "error" ) );
@@ -116,13 +127,16 @@ public class PermissionsResourceIT extends AbstractRestIT {
}
+ /**
+ * Deletes a user from the group.
+ * @throws IOException
+ */
@Test
public void deleteUserGroup() throws IOException {
- // don't populate the user, it will use the currently authenticated
- // user.
String groupPath = "groupPath" ;
+ //Creates and posts a group.
Entity data = new Entity().chainPut("name",groupPath).chainPut("type", "group").chainPut( "path", groupPath );
Entity node = this.app().collection("groups").post(data);
@@ -131,13 +145,15 @@ public class PermissionsResourceIT extends AbstractRestIT {
refreshIndex();
+ //Create a user that is in the group.
node = this.app().collection("groups").entity(groupPath).collection("users").entity(USER).post();
assertNull( node.get( "error" ) );
refreshIndex();
- Collection groups = this.app().collection("users").entity(USER).collection("groups").get();
+ //Get the user and make sure that they are part of the group
+ Collection groups = this.app().collection("users").entity(USER).collection("groups").get();
assertEquals(groups.next().get("name"), groupPath);
@@ -149,6 +165,7 @@ public class PermissionsResourceIT extends AbstractRestIT {
refreshIndex();
+ //Check that the user no longer exists in the group
int status = 0;
try {
groups = this.app().collection("users").entity(USER).collection("groups").get();
@@ -164,17 +181,11 @@ public class PermissionsResourceIT extends AbstractRestIT {
/**
* For the record, you should NEVER allow the guest role to add roles. This is a gaping security hole and a VERY BAD
* IDEA! That being said, this should technically work, and needs testing.
+ *
+ * Tests that you can allow a guest role to add additional roles.
*/
@Test
public void dictionaryPermissions() throws Exception {
- UUID id = UUIDUtils.newTimeUUID();
-
- String applicationName = "testapp";
- String orgname = "dictionaryPermissions";
- String username = "permissionadmin" + id;
- String password = "password";
- String email = String.format( "email%s@usergrid.com", id );
-
// add the perms to the guest to allow users in the role to create roles
// themselves
@@ -195,94 +206,82 @@ public class PermissionsResourceIT extends AbstractRestIT {
/**
- * Tests a real world example with the following steps. Creates an application.
- * <p/>
- * Creates a new role "reviewer"
- * <p/>
- * Grants a permission to GET, POST, and PUT the reviews url for the reviewer role
- * <p/>
- * Grants a permission GET on the reviewer for the
- * <p/>
- * Create a user reviewer1 and add them to the reviewer role
- * <p/>
- * Test access with reviewer1
- * <p/>
- * Create a group reviewergroup and add the "reviewer" group to it
- * <p/>
- * Create a user reviewer 2 and add them to the "reveiwergroup"
+ * Test application permissions by posting entities different users and making sure we work within
+ * the permissions given.
*/
@Test
public void applicationPermissions() throws Exception {
- // now create the new role
- UUID secondUserId = createRoleUser( "reviewer2", "reviewer2@usergrid.com" );
- UUID userId = createRoleUser( "reviewer1", "reviewer1@usergrid.com" );
+ //Creates two new roles: reviewer1 and reviewer2
+ createRoleUser( "reviewer1", "reviewer1@usergrid.com" );
+ createRoleUser( "reviewer2", "reviewer2@usergrid.com" );
Entity data = new Entity().chainPut("name", "reviewer");
+ //Creates a new role "reviewer"
Entity node = this.app().collection("roles").post(data);
assertNull( node.getError() );
- // delete the default role to test permissions later
refreshIndex();
+ // delete the default role to test permissions later
ApiResponse response = this.app().collection("roles").entity("default").delete();
assertNull( response.getError() );
refreshIndex();
- // grant the perms to reviewer
+ // Grants a permission to GET, POST, and PUT the reviews url for the reviewer role
addPermission( "reviewer", "get,put,post:/reviews/**" );
- // grant get to guest
+ // Grants a permission GET on the guests for the reviews url
addPermission( "guest", "get:/reviews/**" );
+ //Creates a reviewer group
Entity group = new Entity().chainPut( "path", "reviewergroup" ).chainPut("name","reviewergroup");
- // now create the group
this.app().collection("groups").post(group);
refreshIndex();
+ //Adds the reviewer to the reviewerGroup
this.app().collection("groups").entity("reviewergroup").collection("roles").entity("reviewer").post();
refreshIndex();
- // add the user to the group
+ //Adds reviewer2 user to the reviewergroup
this.app().collection("users").entity("reviewer2").collection("groups").entity("reviewergroup").post();
refreshIndex();
- Entity userRole = this.app().collection("users").entity("reviewer1").collection("roles").entity("reviewer").post();
- // grant this user the "reviewer" role
+ //Adds reviewer1 to the reviewer role
+ this.app().collection("users").entity("reviewer1").collection("roles").entity("reviewer").post();
refreshIndex();
+ //Set the current context to reviewer1
this.app().token().post(new Token("reviewer1","password"));
+ //Post reviews to the reviews collection as reviewer1
Entity review =
new Entity().chainPut("rating", "4").chainPut("name", "noca").chainPut("review", "Excellent service and food");
+ this.app().collection("reviews").post( review );
- this.app().collection("reviews").post(review);
- refreshIndex();
-
- // post a review as the reviewer1 user
review = new Entity().chainPut ("rating", "4").chainPut( "name", "4peaks").chainPut("review", "Huge beer selection" );
this.app().collection("reviews").post(review);
refreshIndex();
- // get the reviews
+ // get the reviews and assert they were created
Collection reviews = this.app().collection("reviews").get();
assertEquals( "noca",reviews.next().get("name") );
- assertEquals("4peaks", reviews.next().get("name").toString());
-
- // can't delete, not in the grants
+ assertEquals("4peaks", reviews.next().get( "name" ));
+ //Try to delete the reviews, but it should fail due to have having delete permission in the grants.
int status = 0;
try {
this.app().collection("reviews").entity("noca").delete();
+ fail( "this should have failed due to having insufficient permissions" );
}
catch ( UniformInterfaceException uie ) {
status = uie.getResponse().getStatus();
@@ -290,12 +289,12 @@ public class PermissionsResourceIT extends AbstractRestIT {
assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
- refreshIndex();
-
status = 0;
+ //Try to delete the reviews, but it should fail due to have having delete permission in the grants.
try {
this.app().collection("reviews").entity("4peaks").delete();
+ fail( "this should have failed due to having insufficient permissions" );
}
catch ( UniformInterfaceException uie ) {
status = uie.getResponse().getStatus();
@@ -305,30 +304,23 @@ public class PermissionsResourceIT extends AbstractRestIT {
refreshIndex();
- // now test some groups
-
- // post 2 reviews. Should get permissions from the group
+ //TODO: maybe make this into two different tests?
- Token secondUserToken = this.app().token().post(new Token("reviewer2", "password"));
+ //Change context to reviewer2
+ this.app().token().post(new Token("reviewer2", "password"));
+ // post 2 reviews as reviewer2
review = new Entity().chainPut("rating", "4").chainPut("name", "cowboyciao").chainPut("review", "Great atmosphoere");
-
- // post a review as the reviewer2 user
this.app().collection("reviews").post(review);
- refreshIndex();
review = new Entity().chainPut( "rating", "4" ).chainPut("name", "currycorner").chainPut( "review", "Authentic" );
-
- // post a review as the reviewer2 user
this.app().collection("reviews").post(review);
refreshIndex();
+ // get all reviews as reviewer2
reviews = this.app().collection("reviews").get();
- // get all reviews as a user
-
-
assertEquals("noca", reviews.next().get("name").toString());
assertEquals("4peaks", reviews.next().get("name").toString());
assertEquals("cowboyciao", reviews.next().get("name").toString());
@@ -340,7 +332,7 @@ public class PermissionsResourceIT extends AbstractRestIT {
try {
this.app().collection("reviews").entity("cowboyciao").delete();
-
+ fail( "this should have failed due to having insufficient permissions" );
}
catch ( UniformInterfaceException uie ) {
status = uie.getResponse().getStatus();
@@ -354,7 +346,7 @@ public class PermissionsResourceIT extends AbstractRestIT {
try {
this.app().collection("reviews").entity("currycorner").delete();
-
+ fail( "this should have failed due to having insufficient permissions" );
}
catch ( UniformInterfaceException uie ) {
status = uie.getResponse().getStatus();
@@ -378,20 +370,22 @@ public class PermissionsResourceIT extends AbstractRestIT {
@Test
public void wildcardMiddlePermission() throws Exception {
+ //Deletes the default role
this.app().collection("roles").entity("default").delete();
- Entity data = new Entity().chainPut("name", "reviewer");
+ //Creates a reviewer role
+ Entity data = new Entity().chainPut("name", "reviewer");
this.app().collection("roles").post(data);
refreshIndex();
- // allow access to reviews
+ // allow access to reviews excluding delete
addPermission( "reviewer",
"get,put,post:/reviews/**" );
- // allow access to all user's connections
+ // allow access to all user's connections excluding delete
addPermission( "reviewer",
"get,put,post:/users/${user}/**" );
- // allow access to the review relationship
+ // allow access to the review relationship excluding delete
addPermission( "reviewer",
"get,put,post:/books/*/review/*" );
@@ -408,24 +402,26 @@ public class PermissionsResourceIT extends AbstractRestIT {
assertNotNull( userTwoId );
refreshIndex();
-
+
+ //Add user1 to the reviewer role
this.app().collection("users").entity(userOneId).collection("roles").entity("reviewer").post();
-
+
refreshIndex();
+ //Add a book to the books collection
Entity book = new Entity().chainPut( "title", "Ready Player One" ).chainPut("author", "Earnest Cline");
book = this.app().collection("books").post(book);
- // create a book as admin
-
assertEquals( "Ready Player One", book.get("title").toString() );
String bookId = book.get("uuid").toString();
refreshIndex();
+ //Switch the contex to be that of user1
this.app().token().post(new Token("wildcardpermuserone","password"));
+
// post a review of the book as user1
// POST https://api.usergrid.com/my-org/my-app/users/$user1/reviewed/books/$uuid
Entity review =
@@ -438,25 +434,21 @@ public class PermissionsResourceIT extends AbstractRestIT {
// POST https://api.usergrid.com/my-org/my-app/users/me/wrote/review/${reviewId}
this.app().collection("users").entity("me").connection("wrote").collection("review").entity(reviewId).post();
-
- refreshIndex();
+ // POST https://api.usergrid.com/my-org/my-app/users/me/reviewed/review/${reviewId}
this.app().collection("users").entity("me").connection("reviewed").collection("books").entity(bookId).post();
-
refreshIndex();
-
-
// POST https://api.usergrid.com/my-org/my-app/books/${bookId}/review/${reviewId}
this.app().collection("books").entity(bookId).collection("review").entity(reviewId).post();
refreshIndex();
- // now try to post the same thing to books to verify as userOne the failure
+ // now try to post the same thing to books to verify as userOne does not have correct permissions
int status = 0;
try {
- this.app().collection("books").post();
+ this.app().collection("books").post(book);
}
catch ( UniformInterfaceException uie ) {
@@ -464,11 +456,13 @@ public class PermissionsResourceIT extends AbstractRestIT {
}
assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
- refreshIndex();
+ //Gets all books that user1 reviewed\
this.app().collection("users").entity("me").connection("reviewed").collection("books").get();
+ //Gets a specific review
this.app().collection("reviews").entity(reviewId).get();
+ //Gets all the reviews that user1 wrote
this.app().collection("users").entity("me").connection("wrote").get();
}
@@ -484,15 +478,20 @@ public class PermissionsResourceIT extends AbstractRestIT {
* <p/>
* examplepatient add himself to exampledoctor following list
*/
+ //TODO: get this test working.
@Test
public void wildcardFollowingPermission() throws Exception {
+ //Delete default role
app().collection("roles").entity("default").delete();
+
+ //Create new role named patient
Entity data = new Entity().chainPut( "name", "patient" );
app().collection("roles").post(data);
//allow patients to add doctors as their followers
addPermission( "patient", "delete,post:/users/*/following/users/${user}" );
refreshIndex();
+
// create examplepatient
UUID patientId = createRoleUser( "examplepatient", "examplepatient@apigee.com" );
assertNotNull( patientId );
@@ -522,16 +521,25 @@ public class PermissionsResourceIT extends AbstractRestIT {
Entity entity = this.app().collection("users").post(props);
+ assertNotNull( entity );
+
return entity.getUuid();
}
- /** Test adding the permission to the role */
+ /**
+ * Adds the permission in grant to the rolename role, and tests that they were added correctly
+ * @param rolename
+ * @param grant
+ * @throws IOException
+ */
private void addPermission( String rolename, String grant ) throws IOException {
+ //Create and post the permissions
Entity props = new Entity().chainPut("permission", grant);
this.app().collection("roles").entity(rolename).collection("permissions").post(props);
+ //Checks that the permissions were added correctly
Collection node = this.app().collection("roles").entity(rolename).collection("permissions").get();
List<Object> data =(List) node.getResponse().getData();
[08/13] incubator-usergrid git commit: Added a comment clearing what
the token post method accomplishes. Adding clarifying comments to meVerify,
contextualPathOwnership, and contextualConnectionOwnership test.
Posted by ro...@apache.org.
Added a comment clearing what the token post method accomplishes.
Adding clarifying comments to meVerify, contextualPathOwnership, and contextualConnectionOwnership test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/fac2e053
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/fac2e053
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/fac2e053
Branch: refs/heads/two-dot-o
Commit: fac2e053bd71a16fb9b4c550aa14b66d774bb880
Parents: f789821
Author: grey <gr...@apigee.com>
Authored: Wed Jan 7 16:33:14 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Wed Jan 7 16:33:14 2015 -0800
----------------------------------------------------------------------
.../collection/users/OwnershipResourceIT.java | 85 +++++++++++++-------
.../endpoints/TokenResource.java | 2 +-
2 files changed, 56 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fac2e053/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
index fc85ca0..f562ccd 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
@@ -39,7 +39,7 @@ import static org.junit.Assert.fail;
/**
- *
+ * Take in tests that handle owner permissions relating to a specific user.
*/
@Concurrent()
public class OwnershipResourceIT extends AbstractRestIT {
@@ -48,43 +48,58 @@ public class OwnershipResourceIT extends AbstractRestIT {
private User user1;
private User user2;
+
+ /**
+ * Setup two user objects for use in the following tests.
+ */
@Before
public void setup(){
this.usersResource = this.app().collection("users");
String email = "testuser1@usergrid.org";
String email2 = "testuser2@usergrid.org";
+ user1 = new User("testuser1","testuser1", email, "password" );
user2 = new User("testuser2","testuser2", email2, "password" );
- user1 = new User("testuser1","testuser1", email, "password" );
user1 = new User(this.usersResource.post(user1));
user2 = new User(this.usersResource.post(user2));
refreshIndex();
}
+
+ /**
+ * Verifies that me and user1 are the same and that we can revoke the token from user1 and have the me call fail.
+ * @throws Exception
+ */
@Test
public void meVerify() throws Exception {
+ //Clear the applications previous token and start anonymous
this.app().token().clearToken();
+ //Set the token for getting the me entity.
Token token = this.app().token().post(new Token(user1.getUsername(),"password"));
+ //Get the entity known as "me" out of the users collection and asserts it isn't null and is equal to user1.
Entity userNode = usersResource.entity("me").get();
assertNotNull( userNode );
+ assertEquals( user1.getName(), userNode.get( "username" ) );
+ //Gets the uuid of the me entity.
String uuid = userNode.getUuid().toString();
assertNotNull( uuid );
+ //Revoke the user1 token
usersResource.entity(user1).connection("revoketokens").post(new Entity().chainPut("token", token.getAccessToken()));
refreshIndex();
+ //See if we can still access the me entity after revoking its token
try {
- userNode = usersResource.entity("me").get();
-
- fail();
+ usersResource.entity("me").get();
+ fail("This should not work after we've revoked the usertoken");
}
catch ( Exception ex ) {
ex.printStackTrace();
@@ -93,14 +108,19 @@ public class OwnershipResourceIT extends AbstractRestIT {
}
+ /**
+ * Checks that that can only see our own devices when looking at our own path. Then checks that we can see
+ * both devices from a root path.
+ * @throws IOException
+ */
@Test
public void contextualPathOwnership() throws IOException {
- // anonymous user
+ //Clear the applications previous token and start anonymous
this.app().token().clearToken();
-
- Token token = this.app().token().post(new Token(user1.getUsername(),"password"));
+ //Setting the token to be in a user1 context.
+ this.app().token().post(new Token(user1.getUsername(),"password"));
// create device 1 on user1 devices
@@ -108,17 +128,17 @@ public class OwnershipResourceIT extends AbstractRestIT {
.post(new Entity( ).chainPut("name", "device1").chainPut("number", "5551112222"));
refreshIndex();
- // anonymous user
+ //Clear the current user token
this.app().token().clearToken();
- // create device 2 on user 2
- token = this.app().token().post(new Token(user2.getUsername(),"password"));
+ // create device 2 on user 2 and switch the context to use user2
+ Token token = this.app().token().post(new Token(user2.getUsername(),"password"));
usersResource.entity("me").collection("devices")
.post(new Entity( ).chainPut("name", "device2").chainPut("number", "5552223333"));
refreshIndex();
- // now query on user 1.
+ //Check that we can get back device1 on user1
token = this.app().token().post(new Token(user1.getUsername(),"password"));
CollectionEndpoint devices = usersResource.entity( user1 ).collection("devices");
@@ -127,7 +147,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertNotNull( data );
assertEquals("device1", data.get("name").toString());
- // check we can't see device2
+ // check we can't see device2 on user1
int status = 0;
try {
data = devices.entity("device2").get();
@@ -142,7 +162,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertEquals("device1", devicesData.next().get("name").toString());
assertTrue(!devicesData.hasNext());
- // log in as user 2 and check it
+ // log in as user 2 and check that we can see device 2
token = this.app().token().post(new Token(user2.getUsername(),"password"));
devices = usersResource.entity("me").collection("devices");
@@ -151,7 +171,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertNotNull( data );
assertEquals( "device2", data.get("name").toString() );
- // check we can't see device1
+ // check we can't see device1 on user2
status = 0;
try{
data = devices.entity("device1").get();
@@ -169,7 +189,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
// we should see both devices when loaded from the root application
devices = this.app().collection("devices");
- // test for user 1
+ // test we can see both devices for user 1 under root application
token = this.app().token().post(new Token(user1.getUsername(),"password"));
data = devices.entity("device1").get();
@@ -181,7 +201,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertNotNull( data );
assertEquals( "device2", data.get("name").toString() );
- // test for user 2
+ // test we can see both devices for user 2 under root application
token = this.app().token().post(new Token(user2.getUsername(),"password"));
@@ -197,13 +217,18 @@ public class OwnershipResourceIT extends AbstractRestIT {
}
+ /**
+ *
+ * @throws IOException
+ */
@Test
public void contextualConnectionOwnership() throws IOException {
// anonymous user
this.app().token().clearToken();
- this.app().token().post(new Token(user1.getUsername(),"password"));
+ //Setting the token to be in a user1 context.
+ this.app().token().post(new Token(user1.getUsername(),"password"));
// create a 4peaks restaurant
@@ -211,14 +236,12 @@ public class OwnershipResourceIT extends AbstractRestIT {
refreshIndex();
- // create our connection
+ //Create a restaurant and link it to user1/me
data = usersResource.entity("me")
.connection("likes").collection( "restaurants" ).entity( "4peaks" ).post();
refreshIndex();
- String peaksId = data.getUuid().toString();
-
// anonymous user
this.app().token().clearToken();
@@ -235,24 +258,26 @@ public class OwnershipResourceIT extends AbstractRestIT {
String arrogantButcherId = data.getUuid().toString();
- // now query on user 1.
+ //Setting the token to be in a user1 context.
this.app().token().post(new Token(user1.getUsername(),"password"));
+ //Setup the connection between user1 and the restaurant collection.
CollectionEndpoint likeRestaurants =
usersResource.entity( "me" ).connection( "likes" )
.collection( "restaurants" );
- // check we can get it via id
+ //Check that we can get the restaurant by using its uuid
+ String peaksId = data.getUuid().toString();
data = likeRestaurants.entity(peaksId).get();
assertNotNull( data );
assertEquals("4peaks", data.get("name").toString());
- // check we can get it by name
+ //Check that we can get the restaurant by name
data = likeRestaurants.entity( "4peaks" ).get();
assertNotNull( data );
assertEquals( "4peaks", data.get("name").toString() );
- // check we can't see arrogantbutcher by name or id
+ // check we can't see arrogantbutcher by name or id from user1
int status = 200;
try {
data = likeRestaurants.entity("arrogantbutcher").get();
@@ -269,13 +294,13 @@ public class OwnershipResourceIT extends AbstractRestIT {
}
assertEquals(status, 404);
- // do a collection load, make sure we're not entities we shouldn't see
+ // do a collection load, make sure we're not getting entities we shouldn't see
Collection collectionData = likeRestaurants.get();
assertEquals("4peaks", collectionData.next().get("name").toString());
assertTrue( !collectionData.hasNext() );
- // log in as user 2 and check it
+ // log in as user 2 and check that we can see the arrogantbutcher
this.app().token().post(new Token(user2.getUsername(),"password"));
likeRestaurants = usersResource.entity("me").connection( "likes" )
@@ -289,7 +314,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertNotNull( data );
assertEquals( "arrogantbutcher", data.get("name").toString() );
- // check we can't see 4peaks
+ // check we can't see 4peaks as user2
status = 200;
try {
data = likeRestaurants.entity( "4peaks" ).get();
@@ -316,7 +341,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
// we should see both devices when loaded from the root application
- // test for user 1
+ //Check we can see both restaurants as user1 from the root application
this.app().token().post(new Token(user1.getUsername(),"password"));
CollectionEndpoint restaurants = this.app().collection( "restaurants" );
@@ -330,7 +355,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
assertNotNull( data );
assertEquals( "arrogantbutcher", data.get("name").toString() );
- // test for user 2
+ //Check we can see both restaurants as user2 from the root application
this.app().token().post(new Token(user2.getUsername(),"password"));
restaurants = this.app().collection("restaurants");
data = restaurants.entity( "4peaks" ).get();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fac2e053/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/TokenResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/TokenResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/TokenResource.java
index c7c5367..d28bde2 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/TokenResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/TokenResource.java
@@ -37,7 +37,7 @@ public class TokenResource extends NamedResource {
/**
- * Obtains an access token
+ * Obtains an access token and sets the token for the context to use in later calls
*
* @param token
* @return
[09/13] incubator-usergrid git commit: Finished adding comments for
OwnershipResourceIT
Posted by ro...@apache.org.
Finished adding comments for OwnershipResourceIT
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0b894415
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0b894415
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0b894415
Branch: refs/heads/two-dot-o
Commit: 0b894415b97308cd4eb9da240ae04eb65cc62581
Parents: fac2e05
Author: grey <gr...@apigee.com>
Authored: Thu Jan 8 10:37:58 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Jan 8 10:37:58 2015 -0800
----------------------------------------------------------------------
.../collection/users/OwnershipResourceIT.java | 33 +++++++++++---------
1 file changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b894415/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
index f562ccd..30b12f1 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
@@ -218,7 +218,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
/**
- *
+ *
* @throws IOException
*/
@Test
@@ -261,12 +261,12 @@ public class OwnershipResourceIT extends AbstractRestIT {
//Setting the token to be in a user1 context.
this.app().token().post(new Token(user1.getUsername(),"password"));
- //Setup the connection between user1 and the restaurant collection.
+ //Gets the connection between user1 and the their restaurants. In this case gets 4peaks
CollectionEndpoint likeRestaurants =
usersResource.entity( "me" ).connection( "likes" )
.collection( "restaurants" );
- //Check that we can get the restaurant by using its uuid
+ //Check that we can get the 4peaks restaurant by using its uuid
String peaksId = data.getUuid().toString();
data = likeRestaurants.entity(peaksId).get();
assertNotNull( data );
@@ -280,7 +280,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
// check we can't see arrogantbutcher by name or id from user1
int status = 200;
try {
- data = likeRestaurants.entity("arrogantbutcher").get();
+ likeRestaurants.entity("arrogantbutcher").get();
}catch (UniformInterfaceException e){
status = e.getResponse().getStatus();
}
@@ -288,7 +288,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
status = 200;
try {
- data = likeRestaurants.entity( arrogantButcherId ).get();
+ likeRestaurants.entity( arrogantButcherId ).get();
}catch (UniformInterfaceException e){
status = e.getResponse().getStatus();
}
@@ -327,11 +327,13 @@ public class OwnershipResourceIT extends AbstractRestIT {
status = 200;
try {
- data = likeRestaurants.entity( peaksId ).get();
+ likeRestaurants.entity( peaksId ).get();
}catch (UniformInterfaceException e){
status = e.getResponse().getStatus();
}
+ assertEquals( status,404 );
+
// do a collection load, make sure we're not loading device 1
collectionData = likeRestaurants.get();
@@ -370,6 +372,10 @@ public class OwnershipResourceIT extends AbstractRestIT {
}
+ /**
+ *
+ * @throws IOException
+ */
@Test
public void contextualConnectionOwnershipGuestAccess() throws IOException {
@@ -378,25 +384,24 @@ public class OwnershipResourceIT extends AbstractRestIT {
.post(new Entity().chainPut("permission", "get,put,post,delete:/**"));
-
+ //Sets up the cities collection with the city tempe
Entity city = this.app().collection("cities").post(new Entity().chainPut("name", "tempe"));
refreshIndex();
- String cityId = city.get("uuid").toString();
-
- // create a 4peaks restaurant
+ // create a 4peaks restaurant that is connected by a like to tempe.
Entity data = this.app().collection("cities").entity( "tempe" ).connection( "likes" )
.collection( "restaurants" ).post(new Entity().chainPut("name", "4peaks"));
String peaksId = data.get("uuid").toString();
+ // create the arrogantbutcher restaurant that is connected by a like to tempe.
data = this.app().collection("cities").entity( "tempe" ).connection( "likes" )
.collection( "restaurants" ).post(new Entity().chainPut("name", "arrogantbutcher"));
String arrogantButcherId = data.get("uuid").toString();
- // now query on user 1.
+ //Set the user to user1 and get the collection cities
this.app().token().post(new Token(user1.getUsername(),"password"));
CollectionEndpoint likeRestaurants =
@@ -404,7 +409,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
refreshIndex();
- // check we can get it via id with no collection name
+ // check we can get the resturant entities back via uuid without a collection name
data = likeRestaurants.entity( peaksId ).get();
assertNotNull( data );
assertEquals( "4peaks", data.get("name").toString() );
@@ -412,7 +417,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
data = likeRestaurants.entity( arrogantButcherId ).get();
assertEquals( "arrogantbutcher", data.get("name").toString() );
- // check we can get it via id with a collection name
+ // check we can get the restaurant via uuid with a collection name
data = likeRestaurants.collection( "restaurants" ).entity( peaksId ).get();
assertNotNull( data );
assertEquals( "4peaks", data.get("name").toString() );
@@ -420,7 +425,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
data = likeRestaurants.collection( "restaurants" ).entity( arrogantButcherId ).get();
assertEquals( "arrogantbutcher", data.get("name").toString() );
- // do a delete either token should work
+ // Delete the restaurants, either token should work for deletion
ApiResponse deleteResponse = likeRestaurants.collection( "restaurants" ).entity( peaksId ).delete();
assertNotNull( deleteResponse );
[07/13] incubator-usergrid git commit: Merge branch 'two-dot-o' of
github.com:apache/incubator-usergrid into USERGRID-313
Posted by ro...@apache.org.
Merge branch 'two-dot-o' of github.com:apache/incubator-usergrid into USERGRID-313
# By ryan bridges
# Via ryan bridges
* 'two-dot-o' of github.com:apache/incubator-usergrid:
[USERGRID-303]Fixed paging issue in orderByReturnCorrectResults
[USERGRID-303]fixed tests after framework update
[USERGRID-303]Code formatting and updates for query tests
[USERGRID-303]Updated AND/OR query tests to work with new test framework
[USERGRID-303]Updated 'order by' tests to work with new test framework
[USERGRID-303]Updates to AndOrQueryTest
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f789821a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f789821a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f789821a
Branch: refs/heads/two-dot-o
Commit: f789821a6a44e8b195bb90b1a2650b7e0d74ed30
Parents: 421a1d9 231a449
Author: grey <gr...@apigee.com>
Authored: Wed Jan 7 14:36:14 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Wed Jan 7 14:36:14 2015 -0800
----------------------------------------------------------------------
.../applications/queries/AndOrQueryTest.java | 390 ++++++++++++-------
.../queries/BadGrammarQueryTest.java | 78 ++--
.../applications/queries/GeoPagingTest.java | 19 +-
.../applications/queries/MatrixQueryTests.java | 181 ++++-----
.../rest/applications/queries/OrderByTest.java | 269 ++++++-------
5 files changed, 498 insertions(+), 439 deletions(-)
----------------------------------------------------------------------
[13/13] incubator-usergrid git commit: Merge branch 'USERGRID-313' of
https://git-wip-us.apache.org/repos/asf/incubator-usergrid into
apache_usergrid/two-dot-o
Posted by ro...@apache.org.
Merge branch 'USERGRID-313' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into apache_usergrid/two-dot-o
Conflicts:
stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/8b338b18
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/8b338b18
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/8b338b18
Branch: refs/heads/two-dot-o
Commit: 8b338b184d07932c4cfdb72e81ceffb84843185f
Parents: 1ef4325 9fcb150
Author: Rod Simpson <ro...@apigee.com>
Authored: Mon Jan 12 11:18:58 2015 -0700
Committer: Rod Simpson <ro...@apigee.com>
Committed: Mon Jan 12 11:18:58 2015 -0700
----------------------------------------------------------------------
.../users/ConnectionResourceTest.java | 282 ++++----
.../collection/users/OwnershipResourceIT.java | 424 ++++++-----
.../collection/users/PermissionsResourceIT.java | 723 +++++++------------
.../endpoints/TokenResource.java | 2 +-
.../rest/test/resource2point0/model/Entity.java | 6 +-
5 files changed, 635 insertions(+), 802 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8b338b18/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
----------------------------------------------------------------------
[02/13] incubator-usergrid git commit: Merge branch 'two-dot-o' of
https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-313
Posted by ro...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-313
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/389fb9d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/389fb9d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/389fb9d7
Branch: refs/heads/two-dot-o
Commit: 389fb9d77999d63833057f9af26d532a69a7fac1
Parents: d2faf43 fe7719a
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jan 6 08:38:00 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jan 6 08:38:00 2015 -0700
----------------------------------------------------------------------
.../collection/groups/GroupResourceIT.java | 32 ++++++
.../collection/groups/UpdateGroupIT.java | 114 -------------------
.../test/resource2point0/AbstractRestIT.java | 2 +-
.../rest/test/resource2point0/model/Entity.java | 4 +
4 files changed, 37 insertions(+), 115 deletions(-)
----------------------------------------------------------------------
[03/13] incubator-usergrid git commit: fix resourse test
Posted by ro...@apache.org.
fix resourse test
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e964551e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e964551e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e964551e
Branch: refs/heads/two-dot-o
Commit: e964551e7f735c0b1c64122b80d33ccf36cd4568
Parents: 389fb9d
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jan 6 09:08:46 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jan 6 09:08:46 2015 -0700
----------------------------------------------------------------------
.../users/ConnectionResourceTest.java | 86 +++++++-------------
1 file changed, 31 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e964551e/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
index 0e18b13..2949b85 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
@@ -29,6 +29,7 @@ import org.apache.usergrid.rest.test.resource2point0.endpoints.CollectionEndpoin
import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
import org.apache.usergrid.rest.test.resource2point0.model.Collection;
import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.User;
import org.junit.Rule;
import org.junit.Test;
@@ -36,10 +37,8 @@ import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
import java.io.IOException;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.apache.usergrid.utils.MapUtils.hashMap;
+import static org.junit.Assert.*;
/**
@@ -49,7 +48,7 @@ import static org.apache.usergrid.utils.MapUtils.hashMap;
* @since 4.0
*/
public class ConnectionResourceTest extends AbstractRestIT {
-
+
@Test
@@ -58,31 +57,22 @@ public class ConnectionResourceTest extends AbstractRestIT {
CollectionEndpoint activities = this.app().collection("peeps");
- Entity stuff = new Entity().chainPut("type", "chicken");
+ Entity stuff = new Entity().chainPut("name", "chicken").chainPut("type","chicken");
activities.post(stuff);
- Entity payload = new Entity();
- payload.put( "username", "todd" );
-
- Entity objectOfDesire = new Entity();
- objectOfDesire.put( "codingmunchies", "doritoes" );
-
- Entity entity = this.app().collection("users").post(payload);
-
-
- payload.put( "username", "scott" );
+ User payload = new User("todd", "todd", "todd@apigee.com", "password");
+ payload.put("username", "todd");
+ this.app().collection("users").post(payload);
+ payload = new User("scott", "scott", "scott@apigee.com", "password");
+ this.app().collection("users").post(payload);
- entity = this.app().collection("users").post(payload);
refreshIndex();
+ /*finish setting up the two users */
- /*finish setting up the two users */
-
-
-
- entity = this.app().collection("users").entity("todd").connection("likes").entity("peeps").post();
+ Entity entity = this.app().collection("users").entity("todd").connection("likes").collection("peeps").entity("chicken").post();
assertNotNull(entity);
@@ -113,50 +103,27 @@ public class ConnectionResourceTest extends AbstractRestIT {
UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
-
refreshIndex();
//create the connection
things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
-
+ things.entity( thing2Id ).connection( "likes" ).entity( thing1Id ).post();
refreshIndex();
//test we have the "likes" in our connection meta data response
- Entity response = things.entity( "thing1" ).get();
+ Collection collection =this.app().collection("things").entity(thing1Id).connection( "likes" ).get();
- String url =((Map) ((Map)response.get( "metadata" )).get( "connections" )).get( "likes" ).toString();
+ assertTrue("Connection url returned in entity", collection.hasNext());
-
- assertNotNull( "Connection url returned in entity", url );
-
- //trim off the start /
- url = url.substring( 1 );
-
-
- //now that we know the URl is correct, follow it
-
- Collection collection = this.app().collection(url).get();
-
- Entity entity =collection.next();
- UUID returnedUUID = entity.getUuid();
+ UUID returnedUUID = collection.next().getUuid();
assertEquals( thing2Id, returnedUUID );
-
//now follow the loopback, which should be pointers to the other entity
- url = ((Map) ((Map)entity.get( "metadata" )).get( "connections" )).get("likes").toString();
-
- assertNotNull( "Incoming edge URL provited", url );
-
- //trim off the start /
- url = url.substring( 1 );
-
- //now we should get thing1 from the loopback url
-
- collection = this.app().collection(url).get();
+ collection = this.app().collection("things").entity(thing2Id).connection("likes").get();
UUID returned = collection.next().getUuid();
@@ -186,7 +153,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
Entity response = things.entity( "thing1" ).get();
- String url =((Map) ((Map)response.get( "metadata" )).get( "connections" )).get( "likes" ).toString();
+ String url =((Map) ((Map)response.get( "metadata" )).get( "connections" )).get("likes").toString();
assertNotNull( "Connection url returned in entity", url );
@@ -232,9 +199,14 @@ public class ConnectionResourceTest extends AbstractRestIT {
refreshIndex();
- Entity node = things.entity ( "thing2" ).get();
+ int status = 0;
+ try {
+ Entity node = things.entity("thing2").get();
+ }catch (UniformInterfaceException e){
+ status = e.getResponse().getStatus();
+ }
+ assertEquals(404,status);
- assertNull(node);
}
@@ -256,9 +228,13 @@ public class ConnectionResourceTest extends AbstractRestIT {
refreshIndex();
- Entity node = things.entity ( "thing1" ).get();
-
- assertNull(node);
+ int status = 0;
+ try {
+ Entity node = things.entity("thing1").get();
+ }catch (UniformInterfaceException e){
+ status = e.getResponse().getStatus();
+ }
+ assertEquals(404,status);
}
[05/13] incubator-usergrid git commit: fixed null ref issues
Posted by ro...@apache.org.
fixed null ref issues
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e0310878
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e0310878
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e0310878
Branch: refs/heads/two-dot-o
Commit: e03108786d6923c51d643ffdcf52c5bc3ab9229d
Parents: 01173d9
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jan 6 15:51:21 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jan 6 15:51:21 2015 -0700
----------------------------------------------------------------------
.../collection/users/PermissionsResourceIT.java | 631 ++++++-------------
.../rest/test/resource2point0/model/Entity.java | 6 +-
2 files changed, 209 insertions(+), 428 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0310878/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
index a07622e..5f196bb 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
@@ -18,6 +18,7 @@ package org.apache.usergrid.rest.applications.collection.users;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -25,13 +26,16 @@ import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.*;
+import org.elasticsearch.common.collect.HppcMaps;
+import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.apache.usergrid.cassandra.Concurrent;
import org.apache.usergrid.java.client.entities.Group;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationOwnerInfo;
-import org.apache.usergrid.rest.AbstractRestIT;
import org.apache.usergrid.utils.UUIDUtils;
import com.sun.jersey.api.client.ClientResponse;
@@ -39,11 +43,8 @@ import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
import java.io.IOException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
import static org.apache.usergrid.utils.MapUtils.hashMap;
+import static org.junit.Assert.*;
/**
@@ -57,59 +58,61 @@ public class PermissionsResourceIT extends AbstractRestIT {
private static final String ROLE = "permtestrole";
private static final String USER = "edanuff";
+ private User user;
public PermissionsResourceIT() throws Exception {
}
+
+ @Before
+ public void setup(){
+
+ user = new User(USER,USER,USER+"@apigee.com","password");
+ user = new User( this.app().collection("users").post(user));
+ refreshIndex();
+ }
@Test
public void deleteUserFromRole() throws IOException {
- Map<String, String> data = hashMap( "name", ROLE );
+ Entity data = new Entity().chainPut("name", ROLE);
- JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/roles" ).queryParam( "access_token", access_token )
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .post( String.class, data ));
-
- assertNull( node.get( "error" ) );
+ Entity node = this.app().collection("roles").post(data);
- assertEquals( ROLE, getEntity( node, 0 ).get( "name" ).asText() );
+ assertNull(node.get("error"));
- refreshIndex("test-organization", "test-app");
-
- // add the user to the role
- node = mapper.readTree( resource().path( "/test-organization/test-app/roles/" + ROLE + "/users/" + USER )
- .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
+ assertEquals( ROLE, node.get("name").toString() );
+ refreshIndex();
+ node = this.app().collection("roles").entity(node).collection("users").entity(USER).post();
assertNull( node.get( "error" ) );
- refreshIndex("test-organization", "test-app");
+ refreshIndex();
// now check the user has the role
- node = mapper.readTree( resource().path( "/test-organization/test-app/users/" + USER + "/roles" )
- .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+ node = this.app().collection("users").entity(USER).collection("roles").entity(ROLE).get();
+
// check if the role was assigned
- assertEquals( ROLE, getEntity( node, 0 ).get( "name" ).asText() );
+ assertEquals( ROLE, node.get("name").toString() );
// now delete the role
- node = mapper.readTree( resource().path( "/test-organization/test-app/users/" + USER + "/roles/" + ROLE )
- .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class ));
+ this.app().collection("users").entity(USER).collection("roles").entity(ROLE).delete();
- refreshIndex("test-organization", "test-app");
+ refreshIndex();
// check if the role was deleted
- node = mapper.readTree( resource().path( "/test-organization/test-app/users/" + USER + "/roles" )
- .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+ int status = 0;
+ try {
+ node = this.app().collection("users").entity(USER).collection("roles").entity(ROLE).get();
+ }catch (UniformInterfaceException e){
+ status = e.getResponse().getStatus();
+ }
// check if the role was assigned
- assertNull( getEntity( node, 0 ) );
+ assertEquals(status, 404);
}
@@ -118,54 +121,43 @@ public class PermissionsResourceIT extends AbstractRestIT {
// don't populate the user, it will use the currently authenticated
// user.
+ String groupPath = "groupPath" ;
- UUID id = UUIDUtils.newTimeUUID();
-
- String groupPath = "groupPath" + id;
+ Entity data = new Entity().chainPut("name",groupPath).chainPut("type", "group").chainPut( "path", groupPath );
- Map<String, String> data = hashMap( "type", "group" ).map( "path", groupPath );
-
- JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/groups" )
- .queryParam( "access_token", access_token )
- .accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE )
- .post( String.class, data ));
+ Entity node = this.app().collection("groups").post(data);
assertNull( node.get( "error" ) );
- refreshIndex("test-organization", "test-app");
+ refreshIndex();
- node = mapper.readTree(
- resource().path( "/test-organization/test-app/groups/" + groupPath + "/users/" + USER )
- .queryParam( "access_token", access_token )
- .accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE )
- .post( String.class ));
+ node = this.app().collection("groups").entity(groupPath).collection("users").entity(USER).post();
assertNull( node.get( "error" ) );
- refreshIndex("test-organization", "test-app");
+ refreshIndex();
- Map<String, Group> groups = client.getGroupsForUser( USER );
+ Collection groups = this.app().collection("users").entity(USER).collection("groups").get();
- assertNotNull( groups.get( groupPath ) );
+ assertEquals(groups.next().get("name"), groupPath);
// now delete the group
- node = mapper.readTree(
- resource().path( "/test-organization/test-app/groups/" + groupPath + "/users/" + USER )
- .queryParam( "access_token", access_token )
- .accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE )
- .delete( String.class ));
+ ApiResponse response = this.app().collection("groups").entity(groupPath).collection("users").entity(USER).delete();
- assertNull( node.get( "error" ) );
+ assertNull( response.getError() );
- refreshIndex("test-organization", "test-app");
+ refreshIndex();
- groups = client.getGroupsForUser( USER );
+ int status = 0;
+ try {
+ groups = this.app().collection("users").entity(USER).collection("groups").get();
+ assertFalse(groups.hasNext());
+ }catch (UniformInterfaceException e){
+ status=e.getResponse().getStatus();
+ fail();
+ }
- assertNull( groups.get( groupPath ) );
}
@@ -183,33 +175,22 @@ public class PermissionsResourceIT extends AbstractRestIT {
String password = "password";
String email = String.format( "email%s@usergrid.com", id );
- OrganizationOwnerInfo orgs = setup.getMgmtSvc()
- .createOwnerAndOrganization( orgname, username, "noname", email, password,
- true, false );
-
- // create the app
- ApplicationInfo appInfo =
- setup.getMgmtSvc().createApplication( orgs.getOrganization().getUuid(), applicationName );
-
- String adminToken = setup.getMgmtSvc().getAccessTokenForAdminUser( orgs.getOwner().getUuid(), 0 );
// add the perms to the guest to allow users in the role to create roles
// themselves
- addPermission( orgname, applicationName, adminToken, "guest", "get,put,post:/roles/**" );
+ addPermission( "guest", "get,put,post:/roles/**" );
- Map<String, String> data = hashMap( "name", "usercreatedrole" );
+ Entity data = new Entity().chainPut("name", "usercreatedrole");
// create a role as the user
- JsonNode node = mapper.readTree( resource().path( String.format( "/%s/%s/roles", orgname, applicationName ) )
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .post( String.class, data ));
+ Entity entity = this.app().collection("roles").post(data);
- assertNull( getError( node ) );
+ assertNull( entity.getError() );
- refreshIndex(orgname, applicationName);
+ refreshIndex();
// now try to add permission as the user, this should work
- addPermission( orgname, applicationName, "usercreatedrole", "get,put,post:/foo/**" );
+ addPermission( "usercreatedrole", "get,put,post:/foo/**" );
}
@@ -232,211 +213,154 @@ public class PermissionsResourceIT extends AbstractRestIT {
*/
@Test
public void applicationPermissions() throws Exception {
- UUID id = UUIDUtils.newTimeUUID();
-
- String applicationName = "test";
- String orgname = "applicationpermissions";
- String username = "permissionadmin" + id;
- String password = "password";
- String email = String.format( "email%s@usergrid.com", id );
-
- OrganizationOwnerInfo orgs = setup.getMgmtSvc()
- .createOwnerAndOrganization( orgname, username, "noname", email, password,
- true, false );
-
- // create the app
- ApplicationInfo appInfo =
- setup.getMgmtSvc().createApplication( orgs.getOrganization().getUuid(), applicationName );
-
// now create the new role
- Map<String, String> data = hashMap( "name", "reviewer" );
+ UUID secondUserId = createRoleUser( "reviewer2", "reviewer2@usergrid.com" );
+ UUID userId = createRoleUser( "reviewer1", "reviewer1@usergrid.com" );
- String adminToken = setup.getMgmtSvc().getAccessTokenForAdminUser( orgs.getOwner().getUuid(), 0 );
+ Entity data = new Entity().chainPut("name", "reviewer");
- JsonNode node = mapper.readTree( resource().path( String.format( "/%s/%s/roles", orgname, applicationName ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
+ Entity node = this.app().collection("roles").post(data);
- assertNull( getError( node ) );
+ assertNull( node.getError() );
// delete the default role to test permissions later
- node = mapper.readTree( resource().path( String.format( "/%s/%s/roles/default", orgname, applicationName ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class ));
+ refreshIndex();
+
+ ApiResponse response = this.app().collection("roles").entity("default").delete();
- assertNull( getError( node ) );
- refreshIndex(orgname, applicationName);
+ assertNull( response.getError() );
+ refreshIndex();
// grant the perms to reviewer
- addPermission( orgname, applicationName, adminToken, "reviewer", "get,put,post:/reviews/**" );
+ addPermission( "reviewer", "get,put,post:/reviews/**" );
// grant get to guest
- addPermission( orgname, applicationName, adminToken, "guest", "get:/reviews/**" );
+ addPermission( "guest", "get:/reviews/**" );
- UUID userId = createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "reviewer1",
- "reviewer1@usergrid.com" );
+ Entity group = new Entity().chainPut( "path", "reviewergroup" ).chainPut("name","reviewergroup");
- refreshIndex(orgname, applicationName);
+ // now create the group
+ this.app().collection("groups").post(group);
- // grant this user the "reviewer" role
- node = mapper.readTree( resource().path( String.format( "/%s/%s/users/reviewer1/roles/reviewer", orgname, applicationName ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
+ refreshIndex();
- assertNull( getError( node ) );
+ this.app().collection("groups").entity("reviewergroup").collection("roles").entity("reviewer").post();
- refreshIndex(orgname, applicationName);
+ refreshIndex();
- String reviewer1Token = setup.getMgmtSvc().getAccessTokenForAppUser( appInfo.getId(), userId, 0 );
+ // add the user to the group
+ this.app().collection("users").entity("reviewer2").collection("groups").entity("reviewergroup").post();
- Map<String, String> review =
- hashMap( "rating", "4" ).map( "name", "noca" ).map( "review", "Excellent service and food" );
+ refreshIndex();
- // post a review as the reviewer1 user
- resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
- .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, review );
+ Entity userRole = this.app().collection("users").entity("reviewer1").collection("roles").entity("reviewer").post();
+ // grant this user the "reviewer" role
- review = hashMap( "rating", "4" ).map( "name", "4peaks" ).map( "review", "Huge beer selection" );
+ refreshIndex();
- refreshIndex(orgname, applicationName);
+ this.app().token().post(new Token("reviewer1","password"));
- // put a review as the reviewer1 user
- resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
- .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, review );
+ Entity review =
+ new Entity().chainPut("rating", "4").chainPut("name", "noca").chainPut("review", "Excellent service and food");
- refreshIndex(orgname, applicationName);
+ this.app().collection("reviews").post(review);
+ refreshIndex();
- // get the reviews
+ // post a review as the reviewer1 user
+ review = new Entity().chainPut ("rating", "4").chainPut( "name", "4peaks").chainPut("review", "Huge beer selection" );
+ this.app().collection("reviews").post(review);
- node = mapper.readTree( resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
- .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+ refreshIndex();
- assertEquals( "noca", getEntity( node, 0 ).get( "name" ).asText() );
- assertEquals( "4peaks", getEntity( node, 1 ).get( "name" ).asText() );
+ // get the reviews
+ Collection reviews = this.app().collection("reviews").get();
- // can't delete, not in the grants
+ assertEquals( "noca",reviews.next().get("name") );
+ assertEquals("4peaks", reviews.next().get("name").toString());
- ClientResponse.Status status = null;
+ // can't delete, not in the grants
+ int status = 0;
try {
- resource().path( String.format( "/%s/%s/reviews/noca", orgname, applicationName ) )
- .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class );
+ this.app().collection("reviews").entity("noca").delete();
}
catch ( UniformInterfaceException uie ) {
- status = uie.getResponse().getClientResponseStatus();
+ status = uie.getResponse().getStatus();
}
- assertEquals( Status.UNAUTHORIZED, status );
+ assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
- refreshIndex(orgname, applicationName);
+ refreshIndex();
- status = null;
+ status = 0;
try {
- resource().path( String.format( "/%s/%s/reviews/4peaks", orgname, applicationName ) )
- .queryParam( "access_token", reviewer1Token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class );
+ this.app().collection("reviews").entity("4peaks").delete();
}
catch ( UniformInterfaceException uie ) {
- status = uie.getResponse().getClientResponseStatus();
+ status = uie.getResponse().getStatus();
}
- assertEquals( Status.UNAUTHORIZED, status );
+ assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
- refreshIndex(orgname, applicationName);
+ refreshIndex();
// now test some groups
- UUID secondUserId = createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "reviewer2",
- "reviewer2@usergrid.com" );
-
- Map<String, String> group = hashMap( "path", "reviewergroup" );
-
- // /now create the group
- resource().path( String.format( "/%s/%s/groups", orgname, applicationName ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, group );
-
- refreshIndex(orgname, applicationName);
-
- // link the group to the role
- resource().path( String.format( "/%s/%s/groups/reviewergroup/roles/reviewer", orgname, applicationName ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, group );
-
- refreshIndex(orgname, applicationName);
-
- // add the user to the group
- resource().path( String.format( "/%s/%s/users/reviewer2/groups/reviewergroup", orgname, applicationName ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class );
-
- refreshIndex(orgname, applicationName);
// post 2 reviews. Should get permissions from the group
- String secondUserToken = setup.getMgmtSvc().getAccessTokenForAppUser( appInfo.getId(), secondUserId, 0 );
+ Token secondUserToken = this.app().token().post(new Token("reviewer2", "password"));
- review = hashMap( "rating", "4" ).map( "name", "cowboyciao" ).map( "review", "Great atmosphoere" );
+ review = new Entity().chainPut("rating", "4").chainPut("name", "cowboyciao").chainPut("review", "Great atmosphoere");
// post a review as the reviewer2 user
- resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
- .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, review );
-
- review = hashMap( "rating", "4" ).map( "name", "currycorner" ).map( "review", "Authentic" );
+ this.app().collection("reviews").post(review);
- refreshIndex(orgname, applicationName);
+ refreshIndex();
+ review = new Entity().chainPut( "rating", "4" ).chainPut("name", "currycorner").chainPut( "review", "Authentic" );
// post a review as the reviewer2 user
- resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
- .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, review );
+ this.app().collection("reviews").post(review);
+
+ refreshIndex();
- refreshIndex(orgname, applicationName);
+ reviews = this.app().collection("reviews").get();
// get all reviews as a user
- node = mapper.readTree( resource().path( String.format( "/%s/%s/reviews", orgname, applicationName ) )
- .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
- assertEquals( "noca", getEntity( node, 0 ).get( "name" ).asText() );
- assertEquals( "4peaks", getEntity( node, 1 ).get( "name" ).asText() );
- assertEquals( "cowboyciao", getEntity( node, 2 ).get( "name" ).asText() );
- assertEquals( "currycorner", getEntity( node, 3 ).get( "name" ).asText() );
+
+ assertEquals("noca", reviews.next().get("name").toString());
+ assertEquals("4peaks", reviews.next().get("name").toString());
+ assertEquals("cowboyciao", reviews.next().get("name").toString());
+ assertEquals("currycorner", reviews.next().get("name").toString());
// issue a delete, it shouldn't work, no permissions
- status = null;
+ status = 0;
try {
- resource().path( String.format( "/%s/%s/reviews/cowboyciao", orgname, applicationName ) )
- .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class );
+ this.app().collection("reviews").entity("cowboyciao").delete();
+
}
catch ( UniformInterfaceException uie ) {
- status = uie.getResponse().getClientResponseStatus();
+ status = uie.getResponse().getStatus();
}
- assertEquals( Status.UNAUTHORIZED, status );
+ assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
- refreshIndex(orgname, applicationName);
+ refreshIndex();
- status = null;
+ status = 0;
try {
- resource().path( String.format( "/%s/%s/reviews/currycorner", orgname, applicationName ) )
- .queryParam( "access_token", secondUserToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class );
+ this.app().collection("reviews").entity("currycorner").delete();
+
}
catch ( UniformInterfaceException uie ) {
- status = uie.getResponse().getClientResponseStatus();
+ status = uie.getResponse().getStatus();
}
- assertEquals( Status.UNAUTHORIZED, status );
+ assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
}
@@ -454,148 +378,99 @@ public class PermissionsResourceIT extends AbstractRestIT {
@Test
public void wildcardMiddlePermission() throws Exception {
- Map<String, String> params = buildOrgAppParams();
- String orgname =params.get( "orgName" ) ;
- String applicationName = params.get( "appName" ) ;
-
- OrganizationOwnerInfo orgs = setup.getMgmtSvc().createOwnerAndOrganization( params.get( "orgName" ),
- params.get( "username" ), "noname", params.get( "email" ), params.get( "password" ), true, false );
-
- // create the app
- ApplicationInfo appInfo =
- setup.getMgmtSvc().createApplication( orgs.getOrganization().getUuid(), params.get( "appName" ) );
- assertNotNull( appInfo );
-
- String adminToken = setup.getMgmtSvc().getAccessTokenForAdminUser( orgs.getOwner().getUuid(), 0 );
-
- JsonNode node = mapper.readTree( resource()
- .path( String.format( "/%s/%s/roles/default", params.get( "orgName" ), params.get( "appName" ) ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class ));
- Map<String, String> data = hashMap( "name", "reviewer" );
+ this.app().collection("roles").entity("default").delete();
+ Entity data = new Entity().chainPut("name", "reviewer");
- node = mapper.readTree( resource().path( String.format( "/%s/%s/roles", params.get( "orgName" ), params.get( "appName" ) ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
- assertNull( getError( node ) );
+ this.app().collection("roles").post(data);
- refreshIndex(orgname, applicationName);
+ refreshIndex();
// allow access to reviews
- addPermission( params.get( "orgName" ), params.get( "appName" ), adminToken, "reviewer",
+ addPermission( "reviewer",
"get,put,post:/reviews/**" );
// allow access to all user's connections
- addPermission( params.get( "orgName" ), params.get( "appName" ), adminToken, "reviewer",
+ addPermission( "reviewer",
"get,put,post:/users/${user}/**" );
// allow access to the review relationship
- addPermission( params.get( "orgName" ), params.get( "appName" ), adminToken, "reviewer",
+ addPermission( "reviewer",
"get,put,post:/books/*/review/*" );
- assertNull( getError( node ) );
// create userOne
UUID userOneId =
- createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "wildcardpermuserone",
+ createRoleUser( "wildcardpermuserone",
"wildcardpermuserone@apigee.com" );
assertNotNull( userOneId );
// create userTwo
UUID userTwoId =
- createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "wildcardpermusertwo",
+ createRoleUser( "wildcardpermusertwo",
"wildcardpermusertwo@apigee.com" );
assertNotNull( userTwoId );
- refreshIndex(orgname, applicationName);
-
- // assign userOne the reviewer role
- node = mapper.readTree( resource().path( String
- .format( "/%s/%s/users/%s/roles/reviewer", params.get( "orgName" ), params.get( "appName" ),
- userOneId.toString() ) ).queryParam( "access_token", adminToken )
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
+ refreshIndex();
+
+ this.app().collection("users").entity(userOneId).collection("roles").entity("reviewer").post();
- refreshIndex(orgname, applicationName);
+
+ refreshIndex();
- Map<String, String> book = hashMap( "title", "Ready Player One" ).map( "author", "Earnest Cline" );
+ Entity book = new Entity().chainPut( "title", "Ready Player One" ).chainPut("author", "Earnest Cline");
+ book = this.app().collection("books").post(book);
// create a book as admin
- node = mapper.readTree( resource().path( String.format( "/%s/%s/books", params.get( "orgName" ), params.get( "appName" ) ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, book ));
+
- logNode( node );
- assertEquals( "Ready Player One", getEntity( node, 0 ).get( "title" ).textValue() );
- String bookId = getEntity( node, 0 ).get( "uuid" ).textValue();
+ assertEquals( "Ready Player One", book.get("title").toString() );
+ String bookId = book.get("uuid").toString();
- refreshIndex(orgname, applicationName);
+ refreshIndex();
- String userOneToken = setup.getMgmtSvc().getAccessTokenForAppUser( appInfo.getId(), userOneId, 0 );
+ this.app().token().post(new Token("wildcardpermuserone","password"));
// post a review of the book as user1
// POST https://api.usergrid.com/my-org/my-app/users/$user1/reviewed/books/$uuid
- Map<String, String> review =
- hashMap( "heading", "Loved It" ).map( "body", "80s Awesomeness set in the future" );
- node = mapper.readTree( resource().path( String.format( "/%s/%s/reviews", params.get( "orgName" ), params.get( "appName" ) ) )
- .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, review ));
- String reviewId = getEntity( node, 0 ).get( "uuid" ).textValue();
+ Entity review =
+ new Entity().chainPut( "heading", "Loved It" ).chainPut( "body", "80s Awesomeness set in the future" );
+ review = this.app().collection("reviews").post(review);
+ String reviewId = review.get("uuid").toString();
- refreshIndex(orgname, applicationName);
+ refreshIndex();
// POST https://api.usergrid.com/my-org/my-app/users/me/wrote/review/${reviewId}
- node = mapper.readTree( resource().path( String
- .format( "/%s/%s/users/me/wrote/review/%s", params.get( "orgName" ), params.get( "appName" ),
- reviewId ) ).queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
+ this.app().collection("users").entity("me").connection("wrote").collection("review").entity(reviewId).post();
+
+
+ refreshIndex();
+ this.app().collection("users").entity("me").connection("reviewed").collection("books").entity(bookId).post();
- refreshIndex(orgname, applicationName);
- node = mapper.readTree( resource().path( String
- .format( "/%s/%s/users/me/reviewed/books/%s", params.get( "orgName" ), params.get( "appName" ),
- bookId ) ).queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
- logNode( node );
+ refreshIndex();
+
- refreshIndex(orgname, applicationName);
// POST https://api.usergrid.com/my-org/my-app/books/${bookId}/review/${reviewId}
- node = mapper.readTree( resource().path( String
- .format( "/%s/%s/books/%s/review/%s", params.get( "orgName" ), params.get( "appName" ), bookId,
- reviewId ) ).queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
- logNode( node );
+ this.app().collection("books").entity(bookId).collection("review").entity(reviewId).post();
+
- refreshIndex(orgname, applicationName);
+ refreshIndex();
// now try to post the same thing to books to verify as userOne the failure
- Status status = null;
+ int status = 0;
try {
- node = mapper.readTree( resource().path( String.format( "/%s/%s/books", params.get( "orgName" ), params.get( "appName" ) ) )
- .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
- logNode( node );
+ this.app().collection("books").post();
+
}
catch ( UniformInterfaceException uie ) {
- status = uie.getResponse().getClientResponseStatus();
+ status = uie.getResponse().getStatus();
}
- assertEquals( Status.UNAUTHORIZED, status );
-
- refreshIndex(orgname, applicationName);
-
- node = mapper.readTree( resource().path( String
- .format( "/%s/%s/users/me/reviewed/books", params.get( "orgName" ), params.get( "appName" ) ) )
- .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
- logNode( node );
-
- node = mapper.readTree( resource().path( String
- .format( "/%s/%s/reviews/%s", params.get( "orgName" ), params.get( "appName" ), reviewId ) )
- .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
- logNode( node );
-
- node = mapper.readTree( resource()
- .path( String.format( "/%s/%s/users/me/wrote", params.get( "orgName" ), params.get( "appName" ) ) )
- .queryParam( "access_token", userOneToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
- logNode( node );
+ assertEquals( Status.UNAUTHORIZED.getStatusCode(), status );
+
+ refreshIndex();
+ this.app().collection("users").entity("me").connection("reviewed").collection("books").get();
+
+ this.app().collection("reviews").entity(reviewId).get();
+
+ this.app().collection("users").entity("me").connection("wrote").get();
+
}
@@ -610,127 +485,59 @@ public class PermissionsResourceIT extends AbstractRestIT {
* examplepatient add himself to exampledoctor following list
*/
@Test
- @Ignore("Why is this ignored?")
public void wildcardFollowingPermission() throws Exception {
- UUID id = UUIDUtils.newTimeUUID();
+ app().collection("roles").entity("default").delete();
+ Entity data = new Entity().chainPut( "name", "patient" );
+ app().collection("roles").post(data);
- String applicationName = "test";
- String orgname = "followingpermissions";
- String username = "permissionadmin" + id;
- String password = "password";
- String email = String.format( "email%s@usergrid.com", id );
-
- OrganizationOwnerInfo orgs = setup.getMgmtSvc()
- .createOwnerAndOrganization( orgname, username, "noname", email, password,
- true, false );
-
- // create the app
- ApplicationInfo appInfo =
- setup.getMgmtSvc().createApplication( orgs.getOrganization().getUuid(), applicationName );
- assertNotNull( appInfo );
-
- String adminToken = setup.getMgmtSvc().getAccessTokenForAdminUser( orgs.getOwner().getUuid(), 0 );
-
- JsonNode node = mapper.readTree( resource().path( String.format( "/%s/%s/roles/default", orgname, applicationName ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).delete( String.class ));
- Map<String, String> data = hashMap( "name", "patient" );
-
- node = mapper.readTree( resource().path( String.format( "/%s/%s/roles", orgname, applicationName ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
- assertNull( getError( node ) );
//allow patients to add doctors as their followers
- addPermission( orgname, applicationName, adminToken, "patient",
- "delete,post:/users/*/following/users/${user}" );
-
- assertNull( getError( node ) );
+ addPermission( "patient", "delete,post:/users/*/following/users/${user}" );
+ refreshIndex();
// create examplepatient
- UUID patientId =
- createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "examplepatient",
- "examplepatient@apigee.com" );
+ UUID patientId = createRoleUser( "examplepatient", "examplepatient@apigee.com" );
assertNotNull( patientId );
// create exampledoctor
- UUID doctorId = createRoleUser( orgs.getOrganization().getUuid(), appInfo.getId(), adminToken, "exampledoctor",
- "exampledoctor@apigee.com" );
+ UUID doctorId = createRoleUser( "exampledoctor", "exampledoctor@apigee.com" );
assertNotNull( doctorId );
-
-
+ refreshIndex();
// assign examplepatient the patient role
- node = mapper.readTree( resource().path( String
- .format( "/%s/%s/users/%s/roles/patient", orgname, applicationName, patientId.toString() ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
-
- String patientToken = setup.getMgmtSvc().getAccessTokenForAppUser( appInfo.getId(), patientId, 0 );
-
- node = mapper.readTree( resource().path( String
- .format( "/%s/%s/users/%s/following/users/%s", orgname, applicationName, "exampledoctor",
- "examplepatient" ) ).queryParam( "access_token", patientToken )
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
- logNode( node );
+ this.app().collection("users").entity(patientId).collection("roles").entity("patient").post();
+ refreshIndex();
+ this.app().token().post(new Token("examplepatient","password"));
+ refreshIndex();
+ //not working yet, used to be ignored
+// this.app().collection("users").entity("exampledoctor").connection("following").collection("users").entity("examplepatient").post();
}
-
- private Map<String, String> buildOrgAppParams() {
- UUID id = UUIDUtils.newTimeUUID();
- Map<String, String> props =
- hashMap( "username", "wcpermadmin" ).map( "orgName", "orgnamewcperm" ).map( "appName", "test" )
- .map( "password", "password" )
- .map( "email", String.format( "email%s@apigee.com", id.toString() ) );
-
- return props;
- }
-
-
/**
* Create the user, check there are no errors
*
* @return the userid
*/
- private UUID createRoleUser( UUID orgId, UUID appId, String adminToken, String username, String email )
+ private UUID createRoleUser(String username, String email)
throws Exception {
- Map<String, String> props = hashMap( "email", email ).map( "username", username ).map( "name", username )
- .map( "password", "password" );
-
- JsonNode node = mapper.readTree( resource().path( String.format( "/%s/%s/users", orgId, appId ) )
- .queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, props ));
-
- assertNull( getError( node ) );
+ User props = new User(username, username, email, "password");
- UUID userId = UUID.fromString( getEntity( node, 0 ).get( "uuid" ).asText() );
+ Entity entity = this.app().collection("users").post(props);
- // manually activate user
- setup.getMgmtSvc().activateAppUser( appId, userId );
-
- return userId;
+ return entity.getUuid();
}
/** Test adding the permission to the role */
- private void addPermission( String orgname, String appname, String adminToken, String rolename, String grant ) throws IOException {
- Map<String, String> props = hashMap( "permission", grant );
-
- String rolePath = String.format( "/%s/%s/roles/%s/permissions", orgname, appname, rolename );
-
- JsonNode node = mapper.readTree( resource().path( rolePath ).queryParam( "access_token", adminToken )
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .put( String.class, props ));
+ private void addPermission( String rolename, String grant ) throws IOException {
+ Entity props = new Entity().chainPut("permission", grant);
- assertNull( getError( node ) );
+ this.app().collection("roles").entity(rolename).collection("permissions").post(props);
- node = mapper.readTree( resource().path( rolePath ).queryParam( "access_token", adminToken ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+ Collection node = this.app().collection("roles").entity(rolename).collection("permissions").get();
- ArrayNode data = ( ArrayNode ) node.get( "data" );
+ List<Object> data =(List) node.getResponse().getData();
- Iterator<JsonNode> iterator = data.elements();
-
- while ( iterator.hasNext() ) {
- if ( grant.equals( iterator.next().asText() ) ) {
+ for(Object o : data){
+ if(grant.equals(o.toString())){
return;
}
}
@@ -739,30 +546,4 @@ public class PermissionsResourceIT extends AbstractRestIT {
}
- /** Test adding the permission to the role */
- private void addPermission( String orgname, String appname, String rolename, String grant ) throws IOException {
- Map<String, String> props = hashMap( "permission", grant );
-
- String rolePath = String.format( "/%s/%s/roles/%s/permissions", orgname, appname, rolename );
-
- JsonNode node = mapper.readTree( resource().path( rolePath ).accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .put( String.class, props ));
-
- assertNull( getError( node ) );
-
- node = mapper.readTree( resource().path( rolePath ).accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .get( String.class ));
-
- ArrayNode data = ( ArrayNode ) node.get( "data" );
-
- Iterator<JsonNode> iterator = data.elements();
-
- while ( iterator.hasNext() ) {
- if ( grant.equals( iterator.next().asText() ) ) {
- return;
- }
- }
-
- fail( String.format( "didn't find grant %s in the results", grant ) );
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0310878/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
index b70f90c..5b74215 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
@@ -124,15 +124,15 @@ public class Entity implements Serializable, Map<String,Object> {
}
public String getError () {
- return (String) this.get("error").toString();
+ return (String) this.get("error");
}
public String getErrorCode () {
- return (String) this.get("errorCode").toString();
+ return (String)this.get("errorCode");
}
public String getErrorDescription () {
- return (String) this.get("errorDescription").toString();
+ return (String) this.get("errorDescription");
}
@Override
[06/13] incubator-usergrid git commit: Merge branch 'two-dot-o' of
github.com:apache/incubator-usergrid into USERGRID-313
Posted by ro...@apache.org.
Merge branch 'two-dot-o' of github.com:apache/incubator-usergrid into USERGRID-313
# By grey (5) and ryan bridges (5)
# Via Rod Simpson (4) and grey (2)
* 'two-dot-o' of github.com:apache/incubator-usergrid:
Removed test duplicated test. Fixed logic issue with helper method.
Added a helper method to collections. Changed the test to use this new helper method.
Removed test that was never properly implemented. Cleaned up all the tests with helper methods. Added comments detailing what each test does.
Removed different PagingEntitiesTest and just consolidated tests into PagingResourceIT. Added helper methods and removed a lot of duplicated code. Added queryParameters to getNextPage method since we can do queryGets. Added a note to have the collection remember its own name
Fixed PagingEntities and PagingResourceTest. Fixed bug where proper resource wasn't being used in the delete call. Added a queryParameter get call to the Entity method for testing purposes. Added a way to get the response from Collection
[USERGRID-288]Updated GeoPagingTests
Added comments to configuration options. removed 'root' declaration
Adding editorconfig settings file to help with consistent formatting
fixed formatting
Adding excludes to rat
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/421a1d9d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/421a1d9d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/421a1d9d
Branch: refs/heads/two-dot-o
Commit: 421a1d9d855d95cfadb481036cd3a13ec023c684
Parents: e031087 323ef95
Author: grey <gr...@apigee.com>
Authored: Wed Jan 7 11:01:42 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Wed Jan 7 11:01:42 2015 -0800
----------------------------------------------------------------------
stack/.editorconfig | 26 +
stack/pom.xml | 2 +
.../collection/paging/PagingEntitiesTest.java | 132 -----
.../collection/paging/PagingResourceIT.java | 442 ++++++++-------
.../applications/queries/GeoPagingTest.java | 563 +++++++++----------
.../endpoints/CollectionEndpoint.java | 10 +-
.../endpoints/EntityEndpoint.java | 11 +
.../test/resource2point0/model/Collection.java | 11 +-
8 files changed, 566 insertions(+), 631 deletions(-)
----------------------------------------------------------------------
[12/13] incubator-usergrid git commit: Cleanup the imports and add an
actual loop in the connection loopback test.
Posted by ro...@apache.org.
Cleanup the imports and add an actual loop in the connection loopback test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9fcb1502
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9fcb1502
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9fcb1502
Branch: refs/heads/two-dot-o
Commit: 9fcb1502f661a96881e3572319d3c68607cb40c3
Parents: d567dd1
Author: grey <gr...@apigee.com>
Authored: Thu Jan 8 16:42:15 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Jan 8 16:42:15 2015 -0800
----------------------------------------------------------------------
.../users/ConnectionResourceTest.java | 30 +++++++++++---------
1 file changed, 16 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9fcb1502/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
index 8ab63f7..716b15f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
@@ -17,30 +17,25 @@
package org.apache.usergrid.rest.applications.collection.users;
-import java.util.LinkedHashMap;
+import java.io.IOException;
import java.util.Map;
import java.util.UUID;
-import javax.ws.rs.core.MediaType;
+import org.junit.Before;
+import org.junit.Test;
-import com.fasterxml.jackson.databind.JsonNode;
import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
import org.apache.usergrid.rest.test.resource2point0.endpoints.CollectionEndpoint;
-import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
import org.apache.usergrid.rest.test.resource2point0.model.Collection;
import org.apache.usergrid.rest.test.resource2point0.model.Entity;
import org.apache.usergrid.rest.test.resource2point0.model.User;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
-import java.io.IOException;
-import static org.apache.usergrid.utils.MapUtils.hashMap;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
@@ -103,8 +98,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
//Set user Scott to get back a nonexistant connection.
try {
this.app().collection("users").entity("scott").connection("likes").entity(uuid).get();
-
- assert ( false );
+ fail("We shouldn't be able to see user1 connection through user2");
}
catch ( UniformInterfaceException uie ) {
assertEquals( 404, uie.getResponse().getStatus() );
@@ -142,6 +136,14 @@ public class ConnectionResourceTest extends AbstractRestIT {
UUID returned = collection.next().getUuid();
assertEquals( "Should point to thing1 as an incoming entity connection", thing1Id, returned );
+
+ //Follow the connection through the loop to make sure it works.
+ Entity thing1Return = this.app().collection("things").entity(thing1Id).connection( "likes" )
+ .collection( "things" ).entity( thing2Id ).connection( "likes" )
+ .collection( "things" ).entity( thing1Id ).get();
+
+ assertEquals(thing1Id,thing1Return.getUuid());
+
}