Author: ivol37 at gmail.com
Date: Fri Dec  3 10:25:18 2010
New Revision: 474

Log:
[AMDATU-181] Added waitForURL for oAuth servlets


Modified:
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/OAuthClientTest.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/OAuthServiceConsumerRegistryTest.java

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:25:18 2010
@@ -447,9 +447,10 @@
             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");
+    protected void waitForURL(String url, int status) throws 
MalformedURLException, IOException {
+        if (!ConfigProvider.waitForURL(new URL(url), status, HTTP_TIMEOUT)) {
+            int responseCode = ConfigProvider.checkURL(new URL(url));
+            throw new IllegalArgumentException("Timeout occurred waiting for 
'" + url + "' to come available, response code=" + responseCode);
         }
     }
 }

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/OAuthClientTest.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/OAuthClientTest.java
        (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/OAuthClientTest.java
        Fri Dec  3 10:25:18 2010
@@ -19,6 +19,7 @@
 import static org.ops4j.pax.exam.CoreOptions.provision;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.util.Dictionary;
 import java.util.Hashtable;
 
@@ -42,6 +43,7 @@
 import org.amdatu.test.integration.mock.OAuthTestConsumer;
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyManager;
+import org.apache.http.HttpStatus;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -116,10 +118,23 @@
             amdatuOAuthServer(),
             amdatuJspSupport());
     }
+    
+    private void waitForOAuthServlets() throws MalformedURLException, 
IOException {
+        // First wait for the request servlet to become available
+        m_logService.log(LogService.LOG_DEBUG, "Waiting for '" + 
m_oAuthServiceProvider.getRequestTokenURL() + "' to come available...");
+        waitForURL( m_oAuthServiceProvider.getRequestTokenURL(), 
HttpStatus.SC_UNAUTHORIZED);
+        m_logService.log(LogService.LOG_DEBUG, "Waiting for '" + 
m_oAuthServiceProvider.getAuthorizeTokenURL() + "' to come available...");
+        waitForURL( m_oAuthServiceProvider.getAuthorizeTokenURL(), 
HttpStatus.SC_UNAUTHORIZED);
+        m_logService.log(LogService.LOG_DEBUG, "Waiting for '" + 
m_oAuthServiceProvider.getAccessTokenURL() + "' to come available...");
+        waitForURL( m_oAuthServiceProvider.getAccessTokenURL(), 
HttpStatus.SC_UNAUTHORIZED);
+        m_logService.log(LogService.LOG_DEBUG, "oAuth servlets available");
+    }
 
     @Test
     // Test the three-legged oAuth dance
-    public void testThreeLeggedOAuth() throws Exception {
+    public void testThreeLeggedOAuth() throws Exception {      
+        waitForOAuthServlets();
+        
         // Step 1: Register a service consumer
         m_logService.log(LogService.LOG_DEBUG, "*** Step 1: Register service 
consumer ***");
         OAuthServiceConsumer consumer = registerServiceConsumer();

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:25:18 2010
@@ -107,7 +107,7 @@
 
         // 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);
+        waitForURL(m_baseUrl + CONSUMERS_REST_RESOURCE, HttpStatus.SC_OK);
         m_logService.log(LogService.LOG_DEBUG, "URL available");
         
         HttpClient httpClient = new HttpClient();

Reply via email to