usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [1/2] incubator-usergrid git commit: Got paths working for the resource just like they used to work with Jersey 2.
Date Wed, 10 Dec 2014 00:43:58 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/UG-rest-test-framework-overhaul fa4b4ccb2 -> 9af4135ae


Got paths working for the resource just like they used to work with Jersey 2.


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

Branch: refs/heads/UG-rest-test-framework-overhaul
Commit: c19936524c6fdc8a44ebe28017fec4773d6741df
Parents: fa4b4cc
Author: grey <greyes@apigee.com>
Authored: Tue Dec 9 12:16:55 2014 -0800
Committer: grey <greyes@apigee.com>
Committed: Tue Dec 9 12:16:55 2014 -0800

----------------------------------------------------------------------
 .../test/resource2point0/AbstractRestIT.java    | 57 +++++++++++++++-
 .../rest/test/resource2point0/DumbClient.java   | 10 ++-
 .../rest/test/resource2point0/RestClient.java   | 72 +++++++++++++++++---
 3 files changed, 124 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1993652/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java
index 7b71b19..acf386e 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java
@@ -18,24 +18,79 @@ package org.apache.usergrid.rest.test.resource2point0;
 
 
 import java.net.URI;
+import java.net.URLClassLoader;
+import java.util.Arrays;
 
 import org.junit.ClassRule;
 
+import org.apache.usergrid.java.client.Client;
 import org.apache.usergrid.rest.ITSetup;
 import org.apache.usergrid.rest.RestITSuite;
 
 import javax.ws.rs.core.Application;
 
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.json.JSONConfiguration;
+import com.sun.jersey.test.framework.AppDescriptor;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.WebAppDescriptor;
+import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
+
 
 //import com.sun.jersey.api.json.JSONConfiguration;
 //import com.sun.jersey.test.framework.WebAppDescriptor;
 
 
-public class AbstractRestIT {
+public class AbstractRestIT extends JerseyTest {
+
+    private static ClientConfig clientConfig = new DefaultClientConfig();
+
+    protected static Client client;
 
     @ClassRule
     public static ITSetup setup = new ITSetup( RestITSuite.cassandraResource );
 
+    protected static final AppDescriptor descriptor;
+
+    public AbstractRestIT() {
+        super( descriptor );
+    }
+
+
+    static {
+        clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE
);
+        descriptor = new WebAppDescriptor.Builder( "org.apache.usergrid.rest" )
+                .clientConfig( clientConfig ).build();
+        dumpClasspath( AbstractRestIT.class.getClassLoader() );
+    }
+
+    public static void dumpClasspath( ClassLoader loader ) {
+        System.out.println( "Classloader " + loader + ":" );
+
+        if ( loader instanceof URLClassLoader ) {
+            URLClassLoader ucl = ( URLClassLoader ) loader;
+            System.out.println( "\t" + Arrays.toString( ucl.getURLs() ) );
+        }
+        else {
+            System.out.println( "\t(cannot display components as not a URLClassLoader)" );
+        }
+
+        if ( loader.getParent() != null ) {
+            dumpClasspath( loader.getParent() );
+        }
+    }
+
+    @Override
+    protected URI getBaseURI() {
+        return setup.getBaseURI();
+    }
+
+    @Override
+    protected TestContainerFactory getTestContainerFactory() {
+        return new com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory();
+    }
+
 
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1993652/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
index 781f239..d818a7f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/DumbClient.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.rest.test.resource2point0;
 
 import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.catalina.startup.Tomcat;
@@ -42,20 +43,23 @@ import static org.junit.Assert.assertNotNull;
 public class DumbClient extends AbstractRestIT {
 
     //TODO: maybe this should just take in the raw uri.
-    private final RestClient client = new RestClient( "");
+    //TODO:fix this so it can work a lot like the context.
+    @Rule
+    public final RestClient client = new RestClient( getBaseURI().toString() );
 
 
     @Test
     public void stuff(){
+
         //EntityResponse itr  =  client.org( "test" ).getApp( "test" ).users().getEntityResponse();
         OrganizationResource organizationResource = client.org( "borg" );
         assertNotNull( organizationResource );
-        //assertEquals( getBaseUri().toString()+"borg",client.getPath());
+        assertEquals( getBaseURI().toString()+"borg",client.getPath());
 
 
         ApplicationResource applicationResource = client.org( "morg" ).getApp( "app" );
         assertNotNull( applicationResource );
-        //assertEquals( getBaseUri().toString()+"borg/morg",client.getPath());
+        assertEquals( getBaseURI().toString()+"borg/morg",client.getPath());
 
         //        for(Entity entity: itr){
 //

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1993652/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
index 9955e46..4072c95 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
@@ -16,35 +16,42 @@
  */
 package org.apache.usergrid.rest.test.resource2point0;
 
+import java.io.IOException;
 import java.net.URI;
 import org.junit.ClassRule;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
 
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.rest.ITSetup;
 import org.apache.usergrid.rest.RestITSuite;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResource;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.OrganizationResource;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+import org.apache.usergrid.rest.test.security.TestAdminUser;
+
+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.test.framework.JerseyTest;
 
 
 /**
  * Extends the JerseyTest framework because this is the client that we are going to be using
to interact with tomcat
  */
-public class RestClient implements UrlResource {
-
-    //ClientConfig clientConfig = new ClientConfig();
+public class RestClient implements UrlResource,TestRule {
 
 //    @ClassRule
 //    public static ITSetup setup = new ITSetup( RestITSuite.cassandraResource );
 
-    //Client client = ClientBuilder.newClient( clientConfig );
-
-   // private WebTarget webTarget;// = client.target("http://example.com/rest");
-
     private final String serverUrl;
     private final ClientContext context;
-    //ClientConfig config = new ClientConfig();
-
+    WebResource resource;
+    ClientConfig config = new DefaultClientConfig(  );//new ClientConfig();
+    Client client = Client.create( config );
 
 //This should work independantly of test frameowkr. Need to be able to pull the WebResource
Url and not have to integrate the webresource into the Endpoints/Client.
     //This uses jeresy to create the client. Initialize the client with the webresource,
and then the CLIENT calls the root resource.
@@ -55,6 +62,9 @@ public class RestClient implements UrlResource {
     public RestClient( final String serverUrl ) {
         this.serverUrl = serverUrl;
         this.context = new ClientContext();
+        resource = client.resource( serverUrl );
+        resource.path( serverUrl );
+
         //maybe the problem here is with the jaxrs version not having the correct dependencies
or methods.
        // webTarget = client.target( serverUrl );
         //webTarget = webTarget.path( serverUrl );
@@ -67,8 +77,8 @@ public class RestClient implements UrlResource {
      */
     @Override
     public String getPath() {
-        //return webTarget.getUri().toString();
-        return serverUrl;
+        return resource.getURI().toString(); //webResource.getUri().toString();
+        //return serverUrl;
     }
 
 
@@ -85,6 +95,7 @@ public class RestClient implements UrlResource {
      */
     public OrganizationResource org( final String orgName ) {
         OrganizationResource organizationResource = new OrganizationResource( orgName, context,
 this );
+        resource = resource.path( organizationResource.getPath() );
         //webTarget = webTarget.path( organizationResource.getPath()); This worked really
well, shame it couldn't be used.
         return new OrganizationResource( orgName, context,  this );
     }
@@ -96,4 +107,43 @@ public class RestClient implements UrlResource {
 
         //context.setToken( token );
     }
+
+    //TODO: maybe take out the below methods to be a seperate class? Follow solid principles?
Single responsiblitiy. This is currently
+    //taking on the responsibility of both the
+
+    @Override
+    public Statement apply( Statement base, Description description ) {
+        return statement( base, description );
+    }
+
+    private Statement statement( final Statement base, final Description description ) {
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                before( description );
+                try {
+                    base.evaluate();
+                }
+                finally {
+                    cleanup();
+                }
+            }
+        };
+    }
+    protected void cleanup() {
+        // might want to do something here later
+    }
+
+    //TODO: look over this logic
+    protected void before( Description description ) throws IOException {
+//        String testClass = description.getTestClass().getName();
+//        String methodName = description.getMethodName();
+//        String name = testClass + "." + methodName;
+//
+//        TestAdminUser testAdmin = new TestAdminUser( name+ UUIDUtils.newTimeUUID(),
+//                name + "@usergrid.com"+UUIDUtils.newTimeUUID(),
+//                name + "@usergrid.com"+UUIDUtils.newTimeUUID() );
+//        withOrg( name+ UUIDUtils.newTimeUUID() ).withApp( methodName + UUIDUtils.newTimeUUID()
).withUser(
+//                testAdmin ).initAll();
+    }
 }


Mime
View raw message