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 2014/12/22 17:54:43 UTC
[37/50] incubator-usergrid git commit: Added AdminUserResources to
the management endpoints for the rest framework. User retrieval is broken but
creation still works.
Added AdminUserResources to the management endpoints for the rest framework.
User retrieval is broken but creation still works.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/fcc1bc8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/fcc1bc8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/fcc1bc8a
Branch: refs/heads/two-dot-o
Commit: fcc1bc8a5791627669f66593d256a0cc40a9c772
Parents: b87b049
Author: grey <gr...@apigee.com>
Authored: Wed Dec 17 16:43:15 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Wed Dec 17 16:43:15 2014 -0800
----------------------------------------------------------------------
.../rest/management/OrganizationsIT.java | 29 ++++++++----
.../endpoints/mgmt/AdminUserResource.java | 42 +++++++++++++++++
.../endpoints/mgmt/AdminUsersResource.java | 49 ++++++++++++++++++++
.../endpoints/mgmt/OrganizationResource.java | 7 ++-
.../rest/test/resource2point0/model/User.java | 10 ++++
5 files changed, 127 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fcc1bc8a/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
index cf94c04..dcf1a02 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/OrganizationsIT.java
@@ -26,6 +26,7 @@ import java.util.UUID;
import javax.ws.rs.core.MediaType;
import org.apache.usergrid.rest.test.resource2point0.ClientSetup;
+import org.apache.usergrid.rest.test.resource2point0.RestClient;
import org.apache.usergrid.rest.test.resource2point0.model.*;
import org.junit.Ignore;
import org.junit.Rule;
@@ -285,14 +286,22 @@ public class OrganizationsIT extends AbstractRestIT {
}
}
-//
-//
-// @Test
-// public void testCreateOrgUserAndReturnCorrectUsername() throws Exception {
-//
-//
-// String mgmtToken = context.getActiveUser().getToken();
-//
+
+
+ @Test
+ public void testCreateOrgUserAndReturnCorrectUsername() throws Exception {
+
+ String username = "testCreateOrgUserAndReturnCorrectUsername"+UUIDUtils.newTimeUUID();
+
+ RestClient restClient = clientSetup.getRestClient();
+
+ User adminUserPayload = new User(username,username,username+"@usergrid.com",username );
+
+ User adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() )
+ .users().post( adminUserPayload );
+
+ assertNotNull( adminUserResponse );
+
// Map<String, String> payload = hashMap( "username", "test-user-2" ).map( "name", "Test User 2" )
// .map( "email", "test-user-2@mockserver.com" )
// .map( "password", "password" );
@@ -302,6 +311,8 @@ public class OrganizationsIT extends AbstractRestIT {
// .queryParam( "access_token", mgmtToken ).accept( MediaType.APPLICATION_JSON )
// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ) );
//
+// clientSetup.getRestClient().management().orgs()
+//
// logNode( node );
// assertNotNull( node );
//
@@ -316,7 +327,7 @@ public class OrganizationsIT extends AbstractRestIT {
// assertEquals( "test-user-2", username );
// assertEquals( "Test User 2", name );
// assertEquals( "test-user-2@mockserver.com", email );
-// }
+ }
//
//
// @Test
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fcc1bc8a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/AdminUserResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/AdminUserResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/AdminUserResource.java
new file mode 100644
index 0000000..ba46664
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/AdminUserResource.java
@@ -0,0 +1,42 @@
+/*
+ *
+ * * 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 org.apache.usergrid.rest.test.resource2point0.endpoints.AbstractEntityResource;
+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.User;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+
+/**
+ * management/orgs/<org_name>/users/<user_name/id>
+ */
+public class AdminUserResource extends AbstractEntityResource<User> {
+ public AdminUserResource(String name, ClientContext context, UrlResource parent) {
+ super(name, context, parent);
+ }
+
+ @Override
+ protected User instantiateT(ApiResponse response) {
+ return new User(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fcc1bc8a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/AdminUsersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/AdminUsersResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/AdminUsersResource.java
new file mode 100644
index 0000000..8138344
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/AdminUsersResource.java
@@ -0,0 +1,49 @@
+/*
+ *
+ * * 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 org.apache.usergrid.rest.test.resource2point0.endpoints.AbstractCollectionResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.UserResource;
+import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.User;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+
+/**
+ * Models the admin endpoints
+ * management/orgs/<org_name>/users
+ */
+public class AdminUsersResource extends AbstractCollectionResource<User,AdminUserResource> {
+ public AdminUsersResource( ClientContext context, UrlResource parent) {
+ super("users",context,parent);
+ }
+
+ @Override
+ protected User instantiateT(ApiResponse response) {
+ return new User(response);
+ }
+
+ @Override
+ protected AdminUserResource instantiateEntityResource(String name, ClientContext context, UrlResource parent) {
+ return new AdminUserResource(name,context,parent);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fcc1bc8a/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 ac74142..abbfed9 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
@@ -23,6 +23,7 @@ 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.endpoints.UserResource;
import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
import org.apache.usergrid.rest.test.resource2point0.model.Application;
import org.apache.usergrid.rest.test.resource2point0.model.Organization;
@@ -54,7 +55,7 @@ public class OrganizationResource extends NamedResource {
*/
public Organization delete(){
Map<String,Object> response = getResource(true).type(MediaType.APPLICATION_JSON_TYPE)
- .accept(MediaType.APPLICATION_JSON).delete(Organization.class);
+ .accept(MediaType.APPLICATION_JSON).delete( Organization.class );
Organization org = new Organization().mapOrgResponse(response);
return org;
}
@@ -63,4 +64,8 @@ public class OrganizationResource extends NamedResource {
return new ApplicationResource( context ,this );
}
+ //TODO: add user management resource, this is placeholder for regular users.
+ public AdminUsersResource users() {
+ return new AdminUsersResource( context, this );
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fcc1bc8a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/User.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/User.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/User.java
index 36ca7ee..e06ddc9 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/User.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/User.java
@@ -17,6 +17,7 @@
package org.apache.usergrid.rest.test.resource2point0.model;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
@@ -38,10 +39,19 @@ public class User extends Entity {
* @param response
*/
public User (ApiResponse response){
+ //HashMap<String,Object> userResponse = ( HashMap<String, Object> ) response.getData();
+ //this.putAll( ( Map<? extends String, ?> ) userResponse.get( "user" ) );
super(response);
}
//TODO: create another constructor to take in the nessesary things to post to a user.
+ public User (String username, String name, String email, String password){
+ this.put( "username",username );
+ this.put( "name", name);
+ this.put( "email", email);
+ this.put( "password", password);
+ }
+
public Boolean getActivated(){
return (Boolean) this.get( "activated" );
}