You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/02/25 01:10:40 UTC
[2/2] incubator-usergrid git commit: Moving back to embedded Tomcat
instead of Arquillian.
Moving back to embedded Tomcat instead of Arquillian.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e05800e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e05800e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e05800e4
Branch: refs/heads/USERGRID-273
Commit: e05800e450240603dd2b88584242f505b0990296
Parents: 4795355
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Feb 24 19:10:22 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Feb 24 19:10:22 2015 -0500
----------------------------------------------------------------------
.../applications/ApplicationsResource.java | 20 +-
.../apache/usergrid/rest/AbstractRestIT.java | 42 ++---
.../java/org/apache/usergrid/rest/BasicIT.java | 66 +++----
.../java/org/apache/usergrid/rest/ITSetup.java | 15 +-
.../apache/usergrid/rest/TomcatResource.java | 182 +++++++++++++++++++
.../test/resource2point0/AbstractRestIT.java | 75 ++++----
6 files changed, 281 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e05800e4/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
index 0c8ee06..2a5ce9d 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
@@ -140,16 +140,16 @@ public class ApplicationsResource extends AbstractContextResource {
}
- @RequireOrganizationAccess
- @Path(RootResource.APPLICATION_ID_PATH)
- @PUT
- public ApplicationResource restoreApplicationFromOrganizationByApplicationId(
- @Context UriInfo ui,
- @PathParam( "applicationId" )
- String applicationIdStr ) throws Exception {
-
- return getSubResource( ApplicationResource.class ).init( organization, UUID.fromString( applicationIdStr ) );
- }
+// @RequireOrganizationAccess
+// @Path(RootResource.APPLICATION_ID_PATH)
+// @PUT
+// public ApplicationResource restoreApplicationFromOrganizationByApplicationId(
+// @Context UriInfo ui,
+// @PathParam( "applicationId" )
+// String applicationIdStr ) throws Exception {
+//
+// return getSubResource( ApplicationResource.class ).init( organization, UUID.fromString( applicationIdStr ) );
+// }
@RequireOrganizationAccess
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e05800e4/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
index eb1f628..15b2882 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
@@ -27,35 +27,28 @@ 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 org.apache.usergrid.java.client.Client;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Rule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.UriBuilder;
-import org.apache.usergrid.java.client.Client;
+
import static org.apache.usergrid.utils.JsonUtils.mapToFormattedJsonString;
import static org.apache.usergrid.utils.MapUtils.hashMap;
-
-import org.eu.ingwar.tools.arquillian.extension.suite.annotations.ArquillianSuiteDeployment;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporter;
-import org.junit.AfterClass;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
@@ -82,9 +75,10 @@ public abstract class AbstractRestIT extends JerseyTest {
protected static final AppDescriptor descriptor;
- // TODO, this needs to be removed. Instead we need to hook into the Arquillian event lifecycle
- // to invoke /system/database/setup from the REST tier.
- public static ITSetup setup = new ITSetup( );
+ public static ITSetup setup = new ITSetup();
+
+ @Rule
+ public TomcatResource tomcatResource = new TomcatResource();
//private static final URI baseURI = setup.getBaseURI();
@@ -211,7 +205,11 @@ public abstract class AbstractRestIT extends JerseyTest {
@Override
protected URI getBaseURI() {
- return setup.getBaseURI();
+ try {
+ return new URI("http://localhost:" + tomcatResource.getPort());
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Error determining baseURI", e);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e05800e4/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java
index 53b30a4..20d0a64 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java
@@ -17,38 +17,26 @@
package org.apache.usergrid.rest;
-import java.util.Map;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-
import com.fasterxml.jackson.databind.JsonNode;
-
-import org.eu.ingwar.tools.arquillian.extension.suite.annotations.ArquillianSuiteDeployment;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
+import org.apache.usergrid.rest.test.security.TestAppUser;
+import org.apache.usergrid.rest.test.security.TestUser;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
-import java.util.UUID;
+import java.util.Map;
import static org.apache.commons.lang.StringUtils.isNotBlank;
-
-import org.apache.usergrid.persistence.index.utils.UUIDUtils;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.rest.management.organizations.OrganizationsResource;
-import org.apache.usergrid.rest.test.resource.app.UsersCollection;
-import org.apache.usergrid.rest.test.security.TestAppUser;
-import org.apache.usergrid.rest.test.security.TestUser;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.apache.usergrid.utils.MapUtils.hashMap;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
public class BasicIT extends AbstractRestIT {
@@ -80,11 +68,12 @@ public class BasicIT extends AbstractRestIT {
public void testGenericCollectionEntityNameUuid() throws Exception {
JsonNode node = null;
String orgAppPath = "/"+context.getOrgName()+"/"+context.getAppName();
- TestUser testUser = new TestAppUser( "temp"+ UUIDUtils.newTimeUUID(),"password","temp"+UUIDUtils.newTimeUUID()+"@usergrid.com" ).create( context );
+ TestUser testUser = new TestAppUser( "temp"+ UUIDUtils.newTimeUUID(),
+ "password","temp"+UUIDUtils.newTimeUUID()+"@usergrid.com" ).create( context );
//String token = userToken( "ed@anuff.com", "sesame" );
- WebResource resource =
- resource().path( orgAppPath+"/suspects" ).queryParam( "access_token", context.getActiveUser().getToken() );
+ WebResource resource = resource().path( orgAppPath+"/suspects" )
+ .queryParam( "access_token", context.getActiveUser().getToken() );
node = mapper.readTree( resource.accept( MediaType.APPLICATION_JSON ).post( String.class ));
@@ -95,8 +84,9 @@ public class BasicIT extends AbstractRestIT {
Map<String, String> payload = hashMap( "hair", "brown" ).map( "sex", "male" ).map( "eyes", "green" )
.map( "name", uuid.replace( '-', '0' ) ).map( "build", "thin" ).map( "height", "6 4" );
- node = mapper.readTree( resource.queryParam( "access_token", context.getActiveUser().getToken() ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
+ node = mapper.readTree( resource.queryParam( "access_token",
+ context.getActiveUser().getToken() ).accept( MediaType.APPLICATION_JSON )
+ .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
logNode( node );
@@ -163,8 +153,8 @@ public class BasicIT extends AbstractRestIT {
logNode( node );
- assertEquals( username,
- node.get( "data" ).get( "organizations" ).get( orgName.toLowerCase() ).get( "users" ).get( username ).get("name").textValue());
+ assertEquals( username, node.get( "data" ).get( "organizations" ).get( orgName.toLowerCase() )
+ .get( "users" ).get( username ).get("name").textValue());
// test login user with incorrect password
@@ -196,11 +186,13 @@ public class BasicIT extends AbstractRestIT {
assertTrue( "Error should have been thrown", err_thrown );
// test login user with correct password
- TestUser testUser = new TestAppUser( "temp"+ UUIDUtils.newTimeUUID(),"password","temp"+UUIDUtils.newTimeUUID()+"@usergrid.com" ).create( context );
+ TestUser testUser = new TestAppUser( "temp"+ UUIDUtils.newTimeUUID(),"password",
+ "temp"+UUIDUtils.newTimeUUID()+"@usergrid.com" ).create( context );
- node = mapper.readTree( resource().path( "/"+orgName+"/"+appName+"/token" ).queryParam( "grant_type", "password" )
- .queryParam( "username", testUser.getUser() ).queryParam( "password", testUser.getPassword())
- .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+ node = mapper.readTree( resource().path( "/"+orgName+"/"+appName+"/token" )
+ .queryParam( "grant_type", "password" )
+ .queryParam( "username", testUser.getUser() ).queryParam( "password", testUser.getPassword())
+ .accept( MediaType.APPLICATION_JSON ).get( String.class ));
logNode( node );
@@ -235,8 +227,9 @@ public class BasicIT extends AbstractRestIT {
err_thrown = false;
try {
- node = mapper.readTree( resource().path( "/"+orgName+"/"+appName+"/users" ).queryParam( "access_token", "blahblahblah" )
- .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+ node = mapper.readTree( resource().path( "/"+orgName+"/"+appName+"/users" )
+ .queryParam( "access_token", "blahblahblah" )
+ .accept( MediaType.APPLICATION_JSON ).get( String.class ));
}
catch ( UniformInterfaceException e ) {
if ( e.getResponse().getStatus() != 401 ) {
@@ -341,7 +334,8 @@ public class BasicIT extends AbstractRestIT {
err_thrown = false;
try {
- node = mapper.readTree( resource().path( "/"+orgName+"/"+appName+"/items" ).accept( MediaType.APPLICATION_JSON )
+ node = mapper.readTree( resource().path( "/"+orgName+"/"+appName+"/items" )
+ .accept( MediaType.APPLICATION_JSON )
.type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
}
catch ( UniformInterfaceException e ) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e05800e4/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
index 021f937..7888061 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
@@ -42,6 +42,7 @@ public class ITSetup {
private SignInProviderFactory providerFactory;
private Properties properties;
private ManagementService managementService;
+ private TomcatResource tomcatResource;
private URI uri;
@@ -52,10 +53,6 @@ public class ITSetup {
this.springResource = ConcurrentProcessSingleton.getInstance().getSpringResource();
- //start tomcat
-
-
-
emf = springResource.getBean( EntityManagerFactory.class );
smf = springResource.getBean( ServiceManagerFactory.class );
tokenService = springResource.getBean( TokenService.class );
@@ -63,16 +60,15 @@ public class ITSetup {
applicationCreator = springResource.getBean( ApplicationCreator.class );
managementService = springResource.getBean( ManagementService.class );
+ tomcatResource = TomcatResource.instance;
+ tomcatResource.setWebAppsPath( "src/main/webapp" );
// Initialize Jersey Client
//TODO, make this port a resource that's filtered by maven build for the port number
uri = UriBuilder.fromUri("http://localhost/").port( 8080 ).build();
-
-
}
-
public int getTomcatPort() {
return 8080;
}
@@ -111,9 +107,4 @@ public class ITSetup {
public SignInProviderFactory getProviderFactory() {
return providerFactory;
}
-
-
- public URI getBaseURI() {
- return uri;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e05800e4/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java
new file mode 100644
index 0000000..5f00f7b
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java
@@ -0,0 +1,182 @@
+/*
+ * 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;
+
+import com.google.common.io.Files;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.commons.lang.math.RandomUtils;
+import org.apache.usergrid.cassandra.AvailablePortFinder;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import javax.servlet.ServletException;
+import java.io.File;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+/**
+ * Start and stop embedded Tomcat.
+ */
+public class TomcatResource extends ExternalResource {
+ private static final Logger log = LoggerFactory.getLogger(TomcatResource.class);
+
+ public static final TomcatResource instance = new TomcatResource();
+
+ private static final Object mutex = new Object();
+ private String webAppsPath = "src/main/webapp";
+ private int port;
+ private boolean started = false;
+
+ private static AtomicInteger clientCount = new AtomicInteger(0);
+
+ Tomcat tomcat = null;
+ Process process = null;
+
+
+ public TomcatResource() {
+ try {
+ String[] locations = { "usergrid-properties-context.xml" };
+ ConfigurableApplicationContext appContext =
+ new ClassPathXmlApplicationContext( locations );
+
+ } catch (Exception ex) {
+ throw new RuntimeException("Error getting properties", ex);
+ }
+ }
+
+
+ @Override
+ protected void after() {
+ log.info("Entering after");
+
+ synchronized (mutex) {
+
+ if ( clientCount.decrementAndGet() < 1 ) {
+
+ log.info("----------------------------------------------------------------------");
+ log.info("Destroying Tomcat running on port " + port);
+ log.info("----------------------------------------------------------------------");
+
+ if ( process != null ) {
+ process.destroy();
+
+ } else if ( tomcat != null ) {
+ try {
+ tomcat.stop();
+ tomcat.destroy();
+ } catch (LifecycleException ex) {
+ log.error("Error stopping Tomcat", ex);
+ }
+ }
+ started = false;
+
+ } else {
+ log.info("NOT stopping Tomcat because it is still in use by {}", clientCount.get());
+ }
+ }
+
+ log.info("Leaving after");
+ }
+
+
+ @Override
+ protected void before() throws Throwable {
+ log.info("Entering before");
+
+ synchronized (mutex) {
+
+ clientCount.incrementAndGet();
+
+ if (started) {
+ log.info("NOT starting Tomcat because it is already started");
+ log.info("Leaving before: {} users of Tomcat", clientCount.get());
+ return;
+ }
+
+ startTomcatEmbedded();
+
+ log.info("Leaving before: Started Tomcat, now {} users", clientCount.get());
+ }
+
+ }
+
+
+ private void waitForTomcat() throws RuntimeException {
+ String url = "http://localhost:" + port + "/status";
+ int count = 0;
+ while (count++ < 30) {
+ try {
+ Thread.sleep(1000);
+ Client c = Client.create();
+ WebResource wr = c.resource( url );
+ wr.get(String.class);
+ log.info("Tomcat is started.");
+ started = true;
+ break;
+
+ } catch (Exception e) {
+ log.info("Waiting for Tomcat on url {}", url);
+ }
+ }
+ if ( !started ) {
+ throw new RuntimeException("Tomcat process never started.");
+ }
+ }
+
+
+ private void startTomcatEmbedded() throws ServletException, LifecycleException {
+
+ File dataDir = Files.createTempDir();
+ dataDir.deleteOnExit();
+
+ port = AvailablePortFinder.getNextAvailable( 9998 + RandomUtils.nextInt(10) );
+
+ tomcat = new Tomcat();
+ tomcat.setBaseDir( dataDir.getAbsolutePath() );
+ tomcat.setPort( port );
+ tomcat.getConnector().setAttribute("maxThreads", "2000");
+ tomcat.addWebapp( "/", new File( getWebAppsPath() ).getAbsolutePath() );
+
+ log.info("-----------------------------------------------------------------");
+ log.info("Starting Tomcat embedded port {} dir {}", port, dataDir.getAbsolutePath());
+ log.info("-----------------------------------------------------------------");
+ tomcat.start();
+
+ waitForTomcat();
+
+ mutex.notifyAll();
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public String getWebAppsPath() {
+ return webAppsPath;
+ }
+
+ public void setWebAppsPath(String webAppsPath) {
+ this.webAppsPath = webAppsPath;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e05800e4/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 cdba34c..43d0ba4 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
@@ -17,27 +17,6 @@
package org.apache.usergrid.rest.test.resource2point0;
-import java.net.URI;
-import java.net.URLClassLoader;
-import java.util.Arrays;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporter;
-import org.junit.Rule;
-import org.junit.runner.RunWith;
-
-import org.apache.usergrid.rest.ITSetup;
-import org.apache.usergrid.rest.test.resource2point0.endpoints.ApplicationsResource;
-import org.apache.usergrid.rest.test.resource2point0.endpoints.OrganizationResource;
-import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResource;
-import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
-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.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.jersey.api.client.UniformInterfaceException;
@@ -48,26 +27,40 @@ 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 org.apache.usergrid.rest.ITSetup;
+import org.apache.usergrid.rest.TomcatResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.ApplicationsResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.OrganizationResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResource;
+import org.apache.usergrid.rest.test.resource2point0.model.Token;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+import org.junit.Rule;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLClassLoader;
+import java.util.Arrays;
import static org.junit.Assert.assertEquals;
/**
- * How would we get the client from here
+ * Base class for REST tests.
*/
-@RunWith( Arquillian.class )
+//@RunWith( Arquillian.class )
public class AbstractRestIT extends JerseyTest {
private static ClientConfig clientConfig = new DefaultClientConfig();
-
+ @Rule
+ public TomcatResource tomcatResource = new TomcatResource();
public static ITSetup setup = new ITSetup( );
//
// TODO: Allow the client to be setup seperately
@Rule
- public ClientSetup clientSetup = new ClientSetup(setup.getBaseURI().toString());
+ public ClientSetup clientSetup = new ClientSetup( this.getBaseURI().toString() );
protected static final AppDescriptor descriptor;
@@ -86,19 +79,19 @@ public class AbstractRestIT extends JerseyTest {
}
- //We set testable = false so we deploy the archive to the server and test it locally
- @Deployment( testable = false )
- public static WebArchive createTestArchive() {
-
- //we use the MavenImporter from shrinkwrap to just produce whatever maven would build then test with it
-
- //set maven to be in offline mode
-
- System.setProperty( "org.apache.maven.offline", "true" );
-
- return ShrinkWrap.create( MavenImporter.class ).loadPomFromFile( "pom.xml", "arquillian-tomcat" )
- .importBuildOutput().as( WebArchive.class );
- }
+// //We set testable = false so we deploy the archive to the server and test it locally
+// @Deployment( testable = false )
+// public static WebArchive createTestArchive() {
+//
+// //we use the MavenImporter from shrinkwrap to just produce whatever maven would build then test with it
+//
+// //set maven to be in offline mode
+//
+// System.setProperty( "org.apache.maven.offline", "true" );
+//
+// return ShrinkWrap.create( MavenImporter.class ).loadPomFromFile( "pom.xml", "arquillian-tomcat" )
+// .importBuildOutput().as( WebArchive.class );
+// }
public static void dumpClasspath( ClassLoader loader ) {
System.out.println( "Classloader " + loader + ":" );
@@ -118,7 +111,11 @@ public class AbstractRestIT extends JerseyTest {
@Override
protected URI getBaseURI() {
- return setup.getBaseURI();
+ try {
+ return new URI("http://localhost:" + tomcatResource.getPort());
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Error determining baseURI", e);
+ }
}
@Override