Author: ivol37 at gmail.com
Date: Fri Dec 3 10:05:37 2010
New Revision: 473
Log:
[AMDATU-181] Added waitForURL for REST service
Modified:
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthServiceConsumerRegistryREST.java
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/OAuthServiceConsumerRegistryTest.java
Modified:
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthServiceConsumerRegistryREST.java
==============================================================================
---
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthServiceConsumerRegistryREST.java
(original)
+++
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthServiceConsumerRegistryREST.java
Fri Dec 3 10:05:37 2010
@@ -55,6 +55,14 @@
public void start() {
m_logService.log(LogService.LOG_DEBUG, "OAuth Service Consumer
registry REST service started.");
}
+
+ @GET
+ /**
+ * Use this method to verify if the REST service is online.
+ */
+ public Response status() {
+ return Response.ok().build();
+ }
/**
* REST interface: GET
/rest/services/oauth/consumers/oauth/consumers/{consumerKey}
Modified:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
==============================================================================
---
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
(original)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
Fri Dec 3 10:05:37 2010
@@ -29,6 +29,8 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -38,6 +40,7 @@
import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.ServiceDependency;
import org.apache.felix.dm.tracker.ServiceTracker;
+import org.apache.http.HttpStatus;
import org.junit.Assert;
import org.junit.Before;
import org.ops4j.pax.exam.Inject;
@@ -63,6 +66,9 @@
public abstract class IntegrationTestBase {
public final static String TEST_PREFIX = "> TESTING: ";
public final static int SERVICE_TIMEOUT = 30;
+
+ // Time out for the http service to come available
+ private final static int HTTP_TIMEOUT = 5000;
@Inject
protected BundleContext m_bundleContext;
@@ -440,4 +446,10 @@
return
wrappedBundle(mavenBundle().groupId("servletapi").artifactId("servletapi")).exports(javaxServlet,
javaxServletHttp);
}
+
+ protected void waitForURL(String url) throws MalformedURLException,
IOException {
+ if (!ConfigProvider.waitForURL(new URL(url), HttpStatus.SC_OK,
HTTP_TIMEOUT)) {
+ throw new IllegalArgumentException("Timeout occurred waiting for
'" + url + "' to come available");
+ }
+ }
}
Modified:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/OAuthServiceConsumerRegistryTest.java
==============================================================================
---
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/OAuthServiceConsumerRegistryTest.java
(original)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/OAuthServiceConsumerRegistryTest.java
Fri Dec 3 10:05:37 2010
@@ -105,6 +105,11 @@
m_baseUrl = "http://" + ConfigProvider.HOSTNAME + ":" +
ConfigProvider.PORTNR;
m_logService.log(LogService.LOG_DEBUG, "Base URL = " + m_baseUrl);
+ // Wait for the REST service to become available
+ m_logService.log(LogService.LOG_DEBUG, "Waiting for '" + m_baseUrl +
CONSUMERS_REST_RESOURCE + "' to come available...");
+ waitForURL(m_baseUrl + CONSUMERS_REST_RESOURCE);
+ m_logService.log(LogService.LOG_DEBUG, "URL available");
+
HttpClient httpClient = new HttpClient();
// First add a new consumer using the JSON format
@@ -188,7 +193,8 @@
} else if ("application/json".equals(mimeType)) {
body = consumer.toJson().toString();
}
- m_logService.log(LogService.LOG_DEBUG, "Adding consumer for " +
mimeType + ", input=" + body);
+ m_logService.log(LogService.LOG_DEBUG, "Adding consumer for " +
mimeType + ", url=" + (update ? url + "/"
+ + consumer.getConsumerKey() : url) + ", input=" + body);
RequestEntity requestEntity = new StringRequestEntity(body, mimeType,
"UTF-8");
method.setRequestEntity(requestEntity);