Author: [email protected]
Date: Fri May 13 11:01:36 2011
New Revision: 1134
Log:
[AMDATUAUTH-23] Added 'wait until available' checks
Modified:
trunk/amdatu-auth/pom.xml
trunk/amdatu-auth/test-integration/base/src/main/java/org/amdatu/auth/test/integration/base/AuthFixture.java
trunk/amdatu-auth/test-integration/pom.xml
trunk/amdatu-auth/test-integration/tests/pom.xml
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/AuthTest.java
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthSignedRequestsTest.java
Modified: trunk/amdatu-auth/pom.xml
==============================================================================
--- trunk/amdatu-auth/pom.xml (original)
+++ trunk/amdatu-auth/pom.xml Fri May 13 11:01:36 2011
@@ -336,6 +336,7 @@
<taskdef resource="net/sf/antcontrib/antcontrib.properties"
classpathref="maven.compile.classpath"/>
<available
file="${project.build.directory}/${project.build.finalName}.jar"
property="fileExists" value="true"/>
+ <available file="../config-fileinstall"
property="configFileDirExists" value="true"/>
<if>
<isset property="fileExists" />
@@ -351,9 +352,14 @@
tofile="${amdatu.deploy.directory}/${project.artifactId}-${project.version}.jar"
overwrite="true" />
- <copy todir="${amdatu.deploy.directory}"
overwrite="false">
- <fileset dir="../config-fileinstall"/>
- </copy>
+ <if>
+ <isset property="configFileDirExists" />
+ <then>
+ <copy todir="${amdatu.deploy.directory}"
overwrite="false">
+ <fileset dir="../config-fileinstall"/>
+ </copy>
+ </then>
+ </if>
</else>
</if>
</then>
Modified:
trunk/amdatu-auth/test-integration/base/src/main/java/org/amdatu/auth/test/integration/base/AuthFixture.java
==============================================================================
---
trunk/amdatu-auth/test-integration/base/src/main/java/org/amdatu/auth/test/integration/base/AuthFixture.java
(original)
+++
trunk/amdatu-auth/test-integration/base/src/main/java/org/amdatu/auth/test/integration/base/AuthFixture.java
Fri May 13 11:01:36 2011
@@ -33,7 +33,11 @@
mavenBundle().groupId("org.amdatu.auth").artifactId("org.amdatu.auth.oauth.client").versionAsInProject(),
mavenBundle().groupId("org.amdatu.auth").artifactId("org.amdatu.auth.oauth.server").versionAsInProject(),
mavenBundle().groupId("org.amdatu.auth").artifactId("org.amdatu.auth.oauth.consumerregistry-fs").versionAsInProject(),
-
mavenBundle().groupId("org.amdatu.auth").artifactId("org.amdatu.auth.login.service").versionAsInProject()
+
mavenBundle().groupId("org.amdatu.auth").artifactId("org.amdatu.auth.login.service").versionAsInProject(),
+
+ // The following 2 artifacts are necessary for default tenant
resolving
+
mavenBundle().groupId("org.amdatu.web").artifactId("org.amdatu.web.tenantresolver.hostname").versionAsInProject(),
+
mavenBundle().groupId("org.amdatu.web").artifactId("org.amdatu.web.tenantresolver.parameter").versionAsInProject()
);
}
@@ -46,7 +50,7 @@
public void configureDefaults(TestContext testContext) throws Exception {
configureOAuthServer(testContext);
configureFSConsumerRegistry(testContext);
- System.out.println("!!!!!!!!!TEST CONFIG SET");
+ configureHttpService(testContext);
}
public void configureOAuthServer(TestContext testContext) throws Exception
{
@@ -70,4 +74,20 @@
properties.put("datadir", "work/consumerregistrystore"); // fixme
private/missing constants
return properties;
}
+
+ public void configureHttpService(TestContext testContext) throws Exception
{
+ testContext.updateConfig("org.apache.felix.http", getHttpServiceCfg());
+ }
+
+ private Properties getHttpServiceCfg() {
+ Properties properties = new Properties();
+ properties.put("org.osgi.service.http.hostname", "localhost"); //
fixme private/missing constants
+ properties.put("org.osgi.service.http.port", "8080");
+ properties.put("org.osgi.service.http.port.secure", "8090");
+ properties.put("org.apache.felix.http.debug", "true");
+ properties.put("org.apache.felix.log.storeDebug", "true");
+ return properties;
+ }
+
+
}
Modified: trunk/amdatu-auth/test-integration/pom.xml
==============================================================================
--- trunk/amdatu-auth/test-integration/pom.xml (original)
+++ trunk/amdatu-auth/test-integration/pom.xml Fri May 13 11:01:36 2011
@@ -116,8 +116,6 @@
<scope>compile</scope>
<type>bundle</type>
</dependency>
-
-
</dependencies>
</dependencyManagement>
Modified: trunk/amdatu-auth/test-integration/tests/pom.xml
==============================================================================
--- trunk/amdatu-auth/test-integration/tests/pom.xml (original)
+++ trunk/amdatu-auth/test-integration/tests/pom.xml Fri May 13 11:01:36 2011
@@ -35,6 +35,21 @@
<dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>org.amdatu.web</groupId>
+ <artifactId>org.amdatu.web.tenantresolver.hostname</artifactId>
+ <version>${org.amdatu.web.version}</version>
+ <scope>test</scope>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
+ <groupId>org.amdatu.web</groupId>
+ <artifactId>org.amdatu.web.tenantresolver.parameter</artifactId>
+ <version>${org.amdatu.web.version}</version>
+ <scope>test</scope>
+ <type>bundle</type>
+ </dependency>
+
<!--
Amdatu Auth itest base to be used by the tests.
-->
@@ -102,6 +117,16 @@
See explanation in the dependencyManagement section above.
-->
<dependency>
+ <groupId>org.amdatu.web</groupId>
+ <artifactId>org.amdatu.web.tenantresolver.hostname</artifactId>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
+ <groupId>org.amdatu.web</groupId>
+ <artifactId>org.amdatu.web.tenantresolver.parameter</artifactId>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
<groupId>org.amdatu.auth</groupId>
<artifactId>org.amdatu.auth.test.integration.base</artifactId>
<type>bundle</type>
Modified:
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/AuthTest.java
==============================================================================
---
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/AuthTest.java
(original)
+++
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/AuthTest.java
Fri May 13 11:01:36 2011
@@ -22,14 +22,20 @@
import static org.ops4j.pax.exam.LibraryOptions.junitBundles;
import java.io.IOException;
+import java.net.HttpURLConnection;
import java.net.MalformedURLException;
+import java.net.URL;
import org.amdatu.auth.test.integration.base.AuthFixture;
import org.amdatu.authentication.oauth.api.OAuthServiceConsumerRegistry;
import org.amdatu.authentication.oauth.api.OAuthServiceProvider;
+import org.amdatu.authentication.oauth.server.OAuthAccessTokenServlet;
+import org.amdatu.authentication.oauth.server.OAuthAuthorizeTokenServlet;
+import org.amdatu.authentication.oauth.server.OAuthRequestTokenServlet;
import org.amdatu.core.itest.base.CoreFixture;
import org.amdatu.core.itest.base.TestContext;
import org.amdatu.web.itest.base.WebFixture;
+import org.apache.http.HttpStatus;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
@@ -38,18 +44,24 @@
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpService;
import org.osgi.service.log.LogService;
@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class AuthTest {
+
+ // Time out for the http service to come available
+ private final static int HTTP_TIMEOUT = 10000;
+
// Fixtures used by the Auth integration tests
private CoreFixture m_coreFixture = new CoreFixture();
private WebFixture m_webFixture = new WebFixture();
private AuthFixture m_authFixture = new AuthFixture();
private LogService m_logService;
-
+ private OAuthServiceProvider m_oAuthServiceProvider;
@Configuration
public Option[] config() {
return options(
@@ -73,33 +85,64 @@
// FIXME quickfix to let configadmin settle to
// prevent felix dropping configs
- Thread.sleep(10000);
+ Thread.sleep(1000);
return testContext;
}
+
+ // FIXME: [AMDATU-379] This method is here since TestContext.getService
doesn't (always) work.
+ // For optimal performance we do this in 3 steps:
+ // 1. Try to get the service directly using getAllServiceReferences,
return it if available
+ // 2. Invoke super.getService using the service tracker, this will wait
until the service is available
+ // 3. Again try to get the service directly using getAllServiceReferences,
as step 2. might ave failed
+ @SuppressWarnings("unchecked")
+ <T extends Object> T getService(TestContext testContext, Class<T> clazz)
throws Exception {
+ BundleContext bundleContext = testContext.getBundleContext();
+ ServiceReference[] servRef =
bundleContext.getAllServiceReferences(clazz.getName(), null);
+ if (servRef != null && servRef.length > 0) {
+ return (T) bundleContext.getService(servRef[0]);
+ }
+
+ T service = testContext.getService(clazz);
+ if (service != null) {
+ return service;
+ }
+
+ servRef = bundleContext.getAllServiceReferences(clazz.getName(), null);
+ if (servRef != null && servRef.length > 0) {
+ return (T) bundleContext.getService(servRef[0]);
+ }
+ return null;
+ }
+
+ private <T> T assertAvailable(TestContext testContext, Class<T>
serviceClass) throws Exception {
+ T service = getService(testContext, serviceClass);
+ assertThat("Expected a " + serviceClass.getName(), service,
is(notNullValue()));
+ return service;
+ }
@Test
public void testWithServiceDependencies(BundleContext bundleContext)
throws Exception {
TestContext testContext = testContextSetUp(bundleContext);
-
- // First wait for the oAuth servlets to become available
- waitForOAuthServlets();
- m_logService = testContext.getService(LogService.class);
- assertThat("Expected a LogService", m_logService, is(notNullValue()));
+ m_logService = assertAvailable(testContext, LogService.class);
+ assertAvailable(testContext, OAuthRequestTokenServlet.class);
+ assertAvailable(testContext, OAuthAuthorizeTokenServlet.class);
+ assertAvailable(testContext, OAuthAccessTokenServlet.class);
+ assertAvailable(testContext, OAuthServiceConsumerRegistry.class);
+ assertAvailable(testContext, HttpService.class);
+ m_oAuthServiceProvider = assertAvailable(testContext,
OAuthServiceProvider.class);
- OAuthServiceConsumerRegistry registry =
testContext.getService(OAuthServiceConsumerRegistry.class);
- assertThat("Expected a OAuthServiceConsumerRegistry", registry,
is(notNullValue()));
- System.out.println("!!!!!!!!!!registry="+ registry);
+ //Thread.sleep(30000);
- OAuthServiceProvider serviceProvider =
testContext.getService(OAuthServiceProvider.class);
- assertThat("Expected a OAuthServiceProvider", serviceProvider,
is(notNullValue()));
+ // First wait for the oAuth servlets to become available
+ waitForOAuthServlets();
testContext.tearDown();
}
protected void waitForOAuthServlets() throws MalformedURLException,
IOException {
- /*// First wait for the request servlet to become available
+ // 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);
@@ -109,7 +152,52 @@
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");*/
+ m_logService.log(LogService.LOG_DEBUG, "oAuth servlets available");
+ }
+
+ protected void waitForURL(String url, int status) throws
MalformedURLException, IOException {
+ if (!waitForURL(new URL(url), status, HTTP_TIMEOUT)) {
+ int responseCode = checkURL(new URL(url));
+ throw new IllegalArgumentException("Timeout occurred waiting for
'" + url
+ + "' to come available, response code=" + responseCode);
+ }
}
+
+ /**
+ * Wait until the service at the specified URL returns the specified
response code with a timeout as specified.
+ *
+ * @throws IOException
+ */
+ public static boolean waitForURL(URL url, int responseCode, int timeout)
throws IOException {
+ long deadline = System.currentTimeMillis() + timeout;
+ while (System.currentTimeMillis() < deadline) {
+ try {
+ if (checkURL(url) == responseCode) {
+ return true;
+ }
+ Thread.sleep(100);
+ }
+ catch (InterruptedException ie) {}
+ catch (IOException e) {}
+ }
+ return false;
+ }
+
+ /**
+ * Invokes a URL and returns the response code.
+ *
+ * @throws IOException
+ */
+ public static int checkURL(URL url) throws IOException {
+ HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
+ int responseCode;
+ try {
+ connection.connect();
+ responseCode = connection.getResponseCode();
+ } finally {
+ connection.disconnect();
+ }
+ return responseCode;
+ }
}
Modified:
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthSignedRequestsTest.java
==============================================================================
---
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthSignedRequestsTest.java
(original)
+++
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthSignedRequestsTest.java
Fri May 13 11:01:36 2011
@@ -14,17 +14,17 @@
* limitations under the License.
*/
package org.amdatu.auth.test.integration.tests;
-
+
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+
/**
* Test class for oAuth signed requests.
*
* @author ivol
*/
-@RunWith(JUnit4TestRunner.class)
+//@RunWith(JUnit4TestRunner.class)
public class OAuthSignedRequestsTest extends OAuthTestBase {
@Test
public void testOAuthSignedRequests() throws Exception {
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits