Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'gerey/USERGRID-280' into apache_usergri…
Browse files Browse the repository at this point in the history
…d/two-dot-o

Conflicts:
	stack/rest/src/test/resources/usergrid-custom-test.properties
  • Loading branch information
rodsimpson committed Mar 3, 2015
2 parents 83b2c23 + 0b5f598 commit 67cb719
Show file tree
Hide file tree
Showing 8 changed files with 899 additions and 655 deletions.
1,342 changes: 690 additions & 652 deletions stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java

Large diffs are not rendered by default.

Expand Up @@ -41,8 +41,13 @@
public class ClientSetup implements TestRule {

RestClient restClient;
//TODO: store the password as a string here as well
protected String username, orgName, appName;

protected String username;
protected String password;
protected String orgName;
protected String appName;
protected Token superuserToken;

protected Organization organization;
protected Application application;

Expand Down Expand Up @@ -83,7 +88,11 @@ protected void before( Description description ) throws IOException {
String methodName = description.getMethodName();
String name = testClass + "." + methodName;

restClient.superuserSetup();
superuserToken = restClient.management().token().post( new Token( "superuser", "superpassword" ) );

username = "user_"+name + UUIDUtils.newTimeUUID();
password = username;
orgName = "org_"+name+UUIDUtils.newTimeUUID();
appName = "app_"+name+UUIDUtils.newTimeUUID();

Expand All @@ -97,12 +106,18 @@ protected void before( Description description ) throws IOException {

public String getUsername(){return username;}

public String getPassword(){return password;}

public Organization getOrganization(){return organization;}

public String getOrganizationName(){return orgName;}

public String getAppName() {return appName;}

public Token getSuperuserToken() {
return superuserToken;
}

public void refreshIndex() {
this.restClient.refreshIndex(getOrganizationName(),getAppName());
}
Expand Down
Expand Up @@ -22,10 +22,12 @@
import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;

import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;

import javax.ws.rs.core.MediaType;

Expand Down Expand Up @@ -99,6 +101,15 @@ public void refreshIndex(String orgname, String appName) {
.accept( MediaType.APPLICATION_JSON ).post();
}

public void superuserSetup() {
//TODO: change this when we upgrade to new version of jersey
HTTPBasicAuthFilter httpBasicAuthFilter = new HTTPBasicAuthFilter( "superuser","superpassword" );
client.addFilter( httpBasicAuthFilter );

this.getResource().path( "system/superuser/setup" )
.accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON ).get( JsonNode.class );
}

//todo:fix this method for the client.
// public void loginAdminUser( final String username, final String password ) {
// //Post isn't implemented yet, but using the method below we should be able to get a superuser password as well.
Expand Down
@@ -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);


}
}
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* 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.
*/
package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;


import java.util.Map;

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.model.Token;
import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;

import com.sun.jersey.api.client.WebResource;


/**
* Relations to the following endpoint
* /management/users/"username"/password
* Allows admin users to change their passwords
*/
public class PasswordResource extends NamedResource {

public PasswordResource( final ClientContext context, final UrlResource parent ) {
super( "password", context, parent );
}

public Entity post(Token token, Map<String,Object> payload){
WebResource resource;

if(token != null) {
resource = getResource( true, token );
}
else
resource = getResource( true );

return resource.type( MediaType.APPLICATION_JSON_TYPE )
.accept( MediaType.APPLICATION_JSON ).post( Entity.class, payload );
}

public Entity post(Map<String, Object> payload){
return post( null, payload );
}
}
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* 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.
*/
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
* /management/users/"username"
* Store endpoints relating to specific users
*/
public class UserResource extends NamedResource {

public UserResource( final String name, final ClientContext context, final UrlResource parent ) {
super( name, context, parent );
}

public PasswordResource password() {
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);
}
}
Expand Up @@ -50,9 +50,13 @@ public EntityEndpoint entity(String identifier) {
return new EntityEndpoint(identifier, context, this);
}

public UserResource user(String identifier) {
return new UserResource( identifier, context, this );
}

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);
Expand Down
12 changes: 12 additions & 0 deletions stack/rest/src/test/resources/usergrid-custom-test.properties
Expand Up @@ -12,6 +12,12 @@

# REST module test properties


# these settings allow tests to run and consistently pass on 16GB MacBook Pro
# with ug.heapmax=5000m and ug.heapmin=3000m (set in Maven settings.xml)
tomcat.startup=embedded
tomcat.threads=200

cassandra.startup=external
cassandra.timeout=2000
cassandra.connections=800
Expand All @@ -36,3 +42,9 @@ usergrid.counter.batch.size=1
swagger.basepath=http://sometestvalue

usergrid.notifications.listener.run=false

usergrid.sysadmin.login.name=superuser
usergrid.sysadmin.login.email=superuser@usergrid.com
usergrid.sysadmin.login.password=superpassword
usergrid.sysadmin.login.allowed=true

0 comments on commit 67cb719

Please sign in to comment.