You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2015/03/03 21:00:47 UTC
[08/37] incubator-usergrid git commit: Added test for user feeds and
started testCaseSensitivity test.
Added test for user feeds and started testCaseSensitivity 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/0b5f598f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0b5f598f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0b5f598f
Branch: refs/heads/USERGRID-422
Commit: 0b5f598fb8f934735aba7a9d52372a47e714911a
Parents: ff7b1a4
Author: grey <gr...@apigee.com>
Authored: Thu Feb 5 07:55:40 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Feb 5 07:55:40 2015 -0800
----------------------------------------------------------------------
.../usergrid/rest/management/AdminUsersIT.java | 79 +++++++++++++-------
.../endpoints/mgmt/FeedResource.java | 48 ++++++++++++
.../endpoints/mgmt/OrganizationResource.java | 4 +-
.../endpoints/mgmt/UserResource.java | 16 ++++
.../endpoints/mgmt/UsersResource.java | 2 +-
5 files changed, 117 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
index c5ca4d5..005c4ad 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
@@ -22,7 +22,9 @@ package org.apache.usergrid.rest.management;
* Created by ApigeeCorporation on 9/17/14.
*/
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -177,22 +179,16 @@ public class AdminUsersIT extends AbstractRestIT {
String username = clientSetup.getUsername();
String password = clientSetup.getPassword();
-
+ // change the password as admin. The old password isn't required
Map<String, Object> passwordPayload = new HashMap<String, Object>();
passwordPayload.put( "newpassword", "testPassword" );
- // change the password as admin. The old password isn't required
- //management.users().user( username ).password().
management.users().user( username ).password().post( clientSetup.getSuperuserToken(), passwordPayload );
this.refreshIndex();
-// JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken )
-// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-// .post( String.class, data ));
-
assertNotNull( management.token().post( new Token( username, "testPassword" ) ) );
//Check that we cannot get the token using the old password
@@ -203,23 +199,50 @@ public class AdminUsersIT extends AbstractRestIT {
errorParse( 400,"invalid_grant",uie );
}
}
-//
-// @Test
-// public void mgmtUserFeed() throws Exception {
-// JsonNode userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com/feed" )
-// .queryParam( "access_token", adminAccessToken )
-// .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-// assertTrue( StringUtils.contains( this.getEntity( userdata, 0 ).get( "title" ).asText(),
-// "<a href=\"mailto:test@usergrid.com\">" ) );
-// }
-//
-// //everything below is MUUserResourceIT
-//
-// @Test
-// public void testCaseSensitivityAdminUser() throws Exception {
-//
-// LOG.info( "Starting testCaseSensitivityAdminUser()" );
-//
+
+
+ /**
+ * Get the management user feed and check that it has the correct title.
+ * @throws Exception
+ */
+ @Test
+ public void mgmtUserFeed() throws Exception {
+
+ Entity mgmtUserFeedEntity = management.users().user( clientSetup.getUsername() ).feed().get();
+ String correctValue= "<a href=mailto:"+clientSetup.getUsername(); //user_org.apache.usergrid.rest.management.AdminUsersIT.mgmtUserFeed4c3e53e0-acc7-11e4-b527-0b8af3c5813f@usergrid.com">user_org.apache.usergrid.rest.management.AdminUsersIT.mgmtUserFeed4c3e53e0-acc7-11e4-b527-0b8af3c5813f (user_org.apache.usergrid.rest.management.AdminUsersIT.mgmtUserFeed4c3e53e0-acc7-11e4-b527-0b8af3c5813f@usergrid.com)</a> created a new organization account named org_org.apache.usergrid.rest.management.AdminUsersIT.mgmtUserFeed4c3ec910-acc7-11e4-94c8-33f0d48a5559
+
+ assertNotNull( mgmtUserFeedEntity );
+
+ ArrayList<Map<String,Object>> feedEntityMap = ( ArrayList ) mgmtUserFeedEntity.get( "entities" );
+ assertNotNull( feedEntityMap );
+ assertNotNull( feedEntityMap.get( 0 ).get( "title" ) );
+
+ }
+
+ //everything below is MUUserResourceIT
+
+ @Test
+ public void testCaseSensitivityAdminUser() throws Exception {
+
+ //Create adminUser values
+ Entity adminUserPayload = new Entity();
+ String username = "testCaseSensitivityAdminUser"+ org.apache.usergrid.persistence.index.utils
+ .UUIDUtils
+ .newTimeUUID();
+ adminUserPayload.put( "username", username );
+ adminUserPayload.put( "name", username );
+ adminUserPayload.put( "email", username+"@usergrid.com" );
+ adminUserPayload.put( "password", username );
+
+ //create adminUser
+ //Entity adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() ).users().post( adminUserPayload );
+ management.users().post( adminUserPayload );
+
+ refreshIndex();
+
+ Entity adminUserResponse = management.users().user( username.toLowerCase() ).get();
+ assertNotNull( adminUserResponse );
+
// UserInfo mixcaseUser = setup.getMgmtSvc()
// .createAdminUser( "AKarasulu", "Alex Karasulu", "AKarasulu@Apache.org", "test", true, false );
//
@@ -233,15 +256,15 @@ public class AdminUsersIT extends AbstractRestIT {
// refreshIndex(context.getOrgName(), context.getAppName());
//
// String tokenStr = mgmtToken( "akarasulu@apache.org", "test" );
-//
-// // Should succeed even when we use all lowercase
+
+ // Should succeed even when we use all lowercase
// JsonNode node = mapper.readTree( resource().path( "/management/users/akarasulu@apache.org" )
// .queryParam( "access_token", tokenStr )
// .accept( MediaType.APPLICATION_JSON )
// .type( MediaType.APPLICATION_JSON_TYPE )
// .get( String.class ));
-// logNode( node );
-// }
+
+ }
//
//
// @Test
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/FeedResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/FeedResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/FeedResource.java
new file mode 100644
index 0000000..5b95aa5
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/FeedResource.java
@@ -0,0 +1,48 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. The ASF licenses this file to You
+ * * under the Apache License, Version 2.0 (the "License"); you may not
+ * * use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License. For additional information regarding
+ * * copyright in this work, please see the NOTICE file in the top level
+ * * directory of this distribution.
+ *
+ */
+
+package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;
+
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
+import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+
+/**
+ * Contains the REST methods to interacting with the ManagementEndpoints
+ * and the user feeds
+ */
+public class FeedResource extends NamedResource {
+ public FeedResource(final ClientContext context, final UrlResource parent) {
+ super ( "feed",context, parent);
+ }
+
+ public Entity get() {
+ return getResource( true ).type( MediaType.APPLICATION_JSON_TYPE )
+ .accept( MediaType.APPLICATION_JSON ).get( Entity.class);
+
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
index a436358..dbc4ad5 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
@@ -25,8 +25,6 @@ import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
import org.apache.usergrid.rest.test.resource2point0.model.Organization;
-import org.apache.usergrid.rest.test.resource2point0.model.Token;
-import org.apache.usergrid.rest.test.resource2point0.model.User;
import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
@@ -74,7 +72,7 @@ public class OrganizationResource extends NamedResource {
organization );
}
-
+
public ApplicationResource app(){
return new ApplicationResource( context ,this );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
index c5a823e..1adcd83 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java
@@ -16,10 +16,16 @@
*/
package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;
+import javax.ws.rs.core.MediaType;
+
import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
+import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+import com.sun.jersey.api.client.WebResource;
+
/**
* Relations to the following endpoint
@@ -36,4 +42,14 @@ public class UserResource extends NamedResource {
return new PasswordResource( context, this );
}
+ public FeedResource feed() {
+ return new FeedResource( context, this );
+ }
+
+ public Entity get() {
+ WebResource resource = getResource( true );
+ ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE )
+ .accept( MediaType.APPLICATION_JSON ).get( ApiResponse.class );
+ return new Entity(response);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b5f598f/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java
index b71247c..a273c58 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java
@@ -56,7 +56,7 @@ public class UsersResource extends NamedResource {
public Entity post(Entity userPayload){
WebResource resource = getResource(true);
-//TODO: need to parse the specific response gotten for admin entities. It is different from regular entities.
+
ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE )
.accept( MediaType.APPLICATION_JSON ).post( ApiResponse.class, userPayload);
return new Entity(response);