Author: [email protected]
Date: Tue Apr 10 17:32:24 2012
New Revision: 2212
Log:
[AMDATUOPENSOCIAL-210] Moved JSON and assert tools to Auth
Added:
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/OpenSocialTestBase.java
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/AmdatuFactory.java
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/AmdatuFrameworkFactory.java
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/OpenSocialTest.java
Modified:
trunk/amdatu-opensocial/test-integration/base/pom.xml
trunk/amdatu-opensocial/test-integration/base/src/main/java/org/amdatu/opensocial/test/integration/base/OpenSocialFixture.java
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/DashboardTest.java
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/framework/
Modified: trunk/amdatu-opensocial/test-integration/base/pom.xml
==============================================================================
--- trunk/amdatu-opensocial/test-integration/base/pom.xml (original)
+++ trunk/amdatu-opensocial/test-integration/base/pom.xml Tue Apr 10
17:32:24 2012
@@ -34,6 +34,13 @@
<scope>provided</scope>
<type>bundle</type>
</dependency>
+ <dependency>
+ <groupId>org.amdatu.auth</groupId>
+ <artifactId>org.amdatu.auth.tools.itest</artifactId>
+ <version>${org.amdatu.auth.version}</version>
+ <scope>compile</scope>
+ <type>jar</type>
+ </dependency>
</dependencies>
<!--
Modified:
trunk/amdatu-opensocial/test-integration/base/src/main/java/org/amdatu/opensocial/test/integration/base/OpenSocialFixture.java
==============================================================================
---
trunk/amdatu-opensocial/test-integration/base/src/main/java/org/amdatu/opensocial/test/integration/base/OpenSocialFixture.java
(original)
+++
trunk/amdatu-opensocial/test-integration/base/src/main/java/org/amdatu/opensocial/test/integration/base/OpenSocialFixture.java
Tue Apr 10 17:32:24 2012
@@ -15,10 +15,13 @@
*/
package org.amdatu.opensocial.test.integration.base;
+import static org.amdatu.auth.tools.itest.IntegrationTestBase.HOSTNAME;
+import static org.amdatu.auth.tools.itest.IntegrationTestBase.PORTNR;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import org.amdatu.auth.tools.itest.IntegrationTestBase;
import org.amdatu.core.itest.base.TestContext;
import java.io.File;
@@ -28,10 +31,6 @@
import org.ops4j.pax.exam.Option;
public class OpenSocialFixture {
- public static final String HOSTNAME = "localhost";
- public static final String IP = "127.0.0.1";
- public static final String PORTNR = "8080";
-
private static final String SHINDIG_PID = "org.amdatu.opensocial.shindig";
public Option provision() {
@@ -88,7 +87,7 @@
}
public void configureDefaults(TestContext testContext) throws Exception {
- testContext.updateConfig("org.apache.felix.http", getHttpServiceCfg());
+ testContext.updateConfig("org.apache.felix.http",
IntegrationTestBase.getHttpServiceCfg());
testContext.updateConfig(SHINDIG_PID, getShindigCfg());
testContext.updateConfig("org.amdatu.auth.tokenprovider",
getTokenProviderCfg());
}
@@ -159,16 +158,6 @@
return properties;
}
- private Properties getHttpServiceCfg() {
- Properties properties = new Properties();
- properties.put("org.osgi.service.http.hostname", HOSTNAME);
- properties.put("org.osgi.service.http.port", PORTNR);
- 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;
- }
-
private Properties getTokenProviderCfg() {
Properties properties = new Properties();
properties.put("secretkey", "[randomkey]");
Modified:
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/DashboardTest.java
==============================================================================
---
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/DashboardTest.java
(original)
+++
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/DashboardTest.java
Tue Apr 10 17:32:24 2012
@@ -21,17 +21,17 @@
import static javax.ws.rs.HttpMethod.PUT;
import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static org.amdatu.auth.tools.itest.AssertTools.assertEquals;
+import static org.amdatu.auth.tools.itest.AssertTools.assertFalse;
+import static org.amdatu.auth.tools.itest.AssertTools.assertTrue;
+import static org.amdatu.auth.tools.itest.JSONTools.compareJSON;
+import static org.amdatu.auth.tools.itest.JSONTools.getJSONObjects;
import static org.amdatu.auth.tools.itest.UserAdminTools.addTestUser;
-import static
org.amdatu.opensocial.test.integration.tests.util.AssertUtil.assertEquals;
-import static
org.amdatu.opensocial.test.integration.tests.util.AssertUtil.assertFalse;
-import static
org.amdatu.opensocial.test.integration.tests.util.AssertUtil.assertTrue;
import static org.apache.commons.httpclient.HttpStatus.SC_FORBIDDEN;
import static org.apache.commons.httpclient.HttpStatus.SC_NOT_FOUND;
import static org.apache.commons.httpclient.HttpStatus.SC_OK;
import static org.apache.commons.httpclient.HttpStatus.SC_UNAUTHORIZED;
-import
org.amdatu.opensocial.test.integration.tests.framework.OpenSocialTestBase;
-import org.amdatu.opensocial.test.integration.tests.util.BeanUtil;
import java.io.StringReader;
import java.util.ArrayList;
@@ -59,7 +59,7 @@
invokeHTTP("/rest/dashboards", GET, SC_UNAUTHORIZED);
// 3. Now add user 'georged' and login as this user
- addTestUser(m_userAdmin);
+ addTestUser(getUserAdmin());
m_httpTools.loginAsAdministrator();
// 4a. GET /rest/dashboards (XML). We should receive an empty set of
dashboards
@@ -96,7 +96,7 @@
response = invokeHTTP("/rest/dashboards", GET, SC_OK);
JSONObject dbs = createDashboards(db1, db2);
JSONObject jsonObj =
removeGeneratedProperties(XML.toJSONObject(response));
- assertTrue(BeanUtil.compareJSON(jsonObj, dbs));
+ assertTrue(compareJSON(jsonObj, dbs));
// 6a. GET /rest/dashboards/db1. We should receive the dashboard we
created in 5a with links
// but without gadgets
@@ -108,7 +108,7 @@
// 6b. GET /rest/dashboards/db2. We should receive the dashboard we
created in 5c
response = invokeHTTP("/rest/dashboards/" + db2Id + "?alt=json", GET,
SC_OK);
JSONObject jsonObject = removeSpecs(removeSecureTokens(new
JSONObject(response)));
- assertTrue("6b failed: dashboard not returned",
BeanUtil.compareJSON(jsonObject, db2));
+ assertTrue("6b failed: dashboard not returned",
compareJSON(jsonObject, db2));
// 7a. PUT /rest/dashboards/db1. The dashboard should have been updated
db1.getJSONObject("dashboard").getJSONObject("layout").put("id",
"newlayout");
@@ -119,7 +119,7 @@
response = invokeHTTP("/rest/dashboards/" + db1Id + "?alt=json", GET,
SC_OK);
jsonObject = removeGeneratedProperties(new JSONObject(response));
assertTrue("7b failed: dashboard not updated",
- BeanUtil.compareJSON(jsonObject, removeGeneratedProperties(db1)));
+ compareJSON(jsonObject, removeGeneratedProperties(db1)));
// 8a. POST /rest/dashboards/db1/gadgets (JSON). The dashboard should
have added the gadget.
String gadgetUrl =
"http://hosting.gmodules.com/ig/gadgets/file/109810496796399416248/timedate2.xml";
@@ -157,7 +157,7 @@
// 9c. GET /rest/dashboards/db1/gadgets/1/userPreferences (JSON).
Should return updated userPreferences
response = invokeHTTP("/rest/dashboards/" + db1Id +
"/gadgets/1/userPreferences?alt=json", GET, SC_OK);
JSONObject returnedUserPrefs = new JSONObject(response);
- assertTrue(BeanUtil.compareJSON(returnedUserPrefs, userPrefs));
+ assertTrue(compareJSON(returnedUserPrefs, userPrefs));
// 10a. DELETE /rest/dashboards/db1/gadgets/
invokeHTTP("/rest/dashboards/" + db1Id + "/gadgets/" + gadgetId,
DELETE, SC_OK);
@@ -208,10 +208,10 @@
private List<JSONObject> get(JSONObject jsonObj, String dotexpr) throws
JSONException {
List<JSONObject> objects;
if (jsonObj.has("dashboards")) {
- objects = BeanUtil.getJSONObjects(jsonObj, "dashboards." +
dotexpr);
+ objects = getJSONObjects(jsonObj, "dashboards." + dotexpr);
}
else {
- objects = BeanUtil.getJSONObjects(jsonObj, dotexpr);
+ objects = getJSONObjects(jsonObj, dotexpr);
}
return objects;
}
Added:
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/OpenSocialTestBase.java
==============================================================================
--- (empty file)
+++
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/OpenSocialTestBase.java
Tue Apr 10 17:32:24 2012
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.opensocial.test.integration.tests;
+
+import static org.amdatu.auth.tools.itest.AssertTools.fail;
+
+import org.amdatu.auth.tools.itest.HttpTools;
+import org.amdatu.auth.tools.itest.IntegrationTestBase;
+
+import junit.framework.Assert;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * The base class of all OpenSocial integration tests.
+ *
+ * @author <a href="mailto:[email protected]">Amdatu Project
Team</a>
+ */
+public abstract class OpenSocialTestBase extends IntegrationTestBase {
+
+ protected HttpTools m_httpTools = new HttpTools();
+
+ public abstract void execute() throws Exception;
+
+ protected String invokeHTTP(String urlPostfix, String httpMethod, int
expectedStatus) throws Exception {
+ return m_httpTools.invokeHTTP(urlPostfix, httpMethod, expectedStatus);
+ }
+
+ protected String invokeHTTP(String urlPostfix, String httpMethod, String
inputMimeType, Object content,
+ int expectedStatus) throws Exception {
+ return m_httpTools.invokeHTTP(urlPostfix, httpMethod, inputMimeType,
content, expectedStatus);
+ }
+
+ protected void assertEqual(JSONObject object, String dotExpr, String
value) throws JSONException {
+ String[] dotExpression = dotExpr.split("\\.");
+ if (dotExpression.length == 1) {
+ Assert.assertEquals(object.getString(dotExpression[0]), value);
+ }
+ else {
+ if (object.has(dotExpression[0])) {
+ JSONObject subObject = object.getJSONObject(dotExpression[0]);
+ assertEqual(subObject, dotExpr.substring(dotExpr.indexOf(".")
+ 1), value);
+ }
+ else {
+ fail(object.toString() + " has no " + dotExpression[0] + "
element");
+ }
+ }
+ }
+}
Added:
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/AmdatuFactory.java
==============================================================================
--- (empty file)
+++
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/AmdatuFactory.java
Tue Apr 10 17:32:24 2012
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.opensocial.test.integration.tests.launcher;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.TestContainer;
+import org.ops4j.pax.exam.TestContainerException;
+import org.ops4j.pax.exam.TestContainerFactory;
+import org.ops4j.pax.exam.nat.internal.NativeTestContainer;
+import org.ops4j.pax.exam.nat.internal.NativeTestContainerParser;
+import org.ops4j.pax.exam.options.ProvisionOption;
+
+/**
+ * The sole purpose of this class is to allow the use of an alternative
Framework Factory.
+ *
+ * @author ivol
+ */
+public class AmdatuFactory implements TestContainerFactory {
+
+ @SuppressWarnings("rawtypes")
+ public TestContainer[] parse(Option... options) throws
TestContainerException {
+ NativeTestContainerParser parser = new
NativeTestContainerParser(options);
+ List<ProvisionOption> bundles = parser.getBundles();
+ Map<String, String> properties = parser.getSystemProperties();
+ List<TestContainer> containers = new ArrayList<TestContainer>();
+ containers.add(new NativeTestContainer(new AmdatuFrameworkFactory(),
bundles, properties));
+ return containers.toArray(new TestContainer[containers.size()]);
+ }
+}
Added:
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/AmdatuFrameworkFactory.java
==============================================================================
--- (empty file)
+++
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/AmdatuFrameworkFactory.java
Tue Apr 10 17:32:24 2012
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.opensocial.test.integration.tests.launcher;
+
+import java.util.Map;
+
+import org.apache.felix.framework.Felix;
+import org.apache.felix.framework.util.FelixConstants;
+import org.osgi.framework.launch.Framework;
+
+/**
+ * The purpose of this custom Framework factory is to append certain packages
to the
+ * org.osgi.framework.system.packages.extra
+ * system property. Unfortunately, in Pax Exam 2.0.0 this system property is
overruled by the native test container
+ * (see org.ops4j.pax.exam.nat.internal.NativeTestContainer line 209).
Probably this is a unintended bug in Pax Exam
+ * 2.0.0
+ * (it worked fine in 1.2) and this should be filed. However, at the time of
this writing (18-05-2011) it is impossible
+ * to sign up for
+ * an OPS4J JIRA account (due to server maintenance???)
+ *
+ * @author ivol
+ */
+public class AmdatuFrameworkFactory implements
org.osgi.framework.launch.FrameworkFactory {
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public Framework newFramework(Map configuration) {
+ String extraSystemPackages =
configuration.get(FelixConstants.FRAMEWORK_SYSTEMPACKAGES_EXTRA).toString();
+ extraSystemPackages += ",sun.misc,com.sun.management,com.sun.org";
+ configuration.put(FelixConstants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
extraSystemPackages);
+ return new Felix(configuration);
+ }
+}
Added:
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/OpenSocialTest.java
==============================================================================
--- (empty file)
+++
trunk/amdatu-opensocial/test-integration/tests/src/test/java/org/amdatu/opensocial/test/integration/tests/launcher/OpenSocialTest.java
Tue Apr 10 17:32:24 2012
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.opensocial.test.integration.tests.launcher;
+
+import static org.amdatu.auth.tools.itest.ServiceTools.assertAvailable;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.LibraryOptions.junitBundles;
+
+import org.amdatu.auth.login.service.LoginService;
+import org.amdatu.auth.tokenprovider.TokenProvider;
+import org.amdatu.core.itest.base.CoreFixture;
+import org.amdatu.core.itest.base.TestContext;
+import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
+import org.amdatu.opensocial.gadgetmanagement.OpenSocialContainer;
+import org.amdatu.opensocial.shindig.ShindigService;
+import org.amdatu.opensocial.test.integration.base.OpenSocialFixture;
+import org.amdatu.opensocial.test.integration.tests.DashboardTest;
+import org.amdatu.opensocial.test.integration.tests.OpenSocialTestBase;
+import org.amdatu.web.itest.base.WebFixture;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.ExamFactory;
+import org.ops4j.pax.exam.junit.ExamReactorStrategy;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.log.LogService;
+import org.osgi.service.useradmin.UserAdmin;
+
+/**
+ * This class is responsible for executing the individual integration tests.
+ *
+ * @author <a href="mailto:[email protected]">Amdatu Project
Team</a>
+ */
+@RunWith(JUnit4TestRunner.class)
+@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
+@ExamFactory(AmdatuFactory.class)
+public class OpenSocialTest {
+
+ // Fixtures used by the OpenSocial integration tests
+ private CoreFixture m_coreFixture = new CoreFixture();
+ private WebFixture m_webFixture = new WebFixture();
+ private OpenSocialFixture m_openSocialFixture = new OpenSocialFixture();
+
+ private LogService m_logService;
+ private UserAdmin m_userAdmin;
+
+ @Configuration
+ public Option[] config() {
+ return options(
+ junitBundles(),
+ m_coreFixture.provisionWithFsStorage(),
+ m_webFixture.provision(),
+ m_openSocialFixture.provision());
+ }
+
+ public TestContext testContextSetUp(BundleContext bundleContext) throws
Exception {
+ assertThat(bundleContext, is(notNullValue()));
+ TestContext testContext = new TestContext(bundleContext);
+
+ // FIXME quickfix to let startlevel complete to
+ // prevent felix bundle locking issues
+ Thread.sleep(1000);
+
+ // Run the default configurations
+ m_coreFixture.configureDefaults(testContext);
+ m_openSocialFixture.configureDefaults(testContext);
+
+ // FIXME quickfix to let configadmin settle to
+ // prevent felix dropping configs
+ Thread.sleep(5000);
+
+ return testContext;
+ }
+
+ @Test
+ public void runTest(BundleContext bundleContext) throws Exception {
+ // Setup test context
+ TestContext testContext = testContextSetUp(bundleContext);
+
+ // Initialize services
+ m_logService = assertAvailable(testContext, LogService.class);
+ m_userAdmin = assertAvailable(testContext, UserAdmin.class);
+
+ assertAvailable(testContext, ShindigService.class);
+ assertAvailable(testContext, HttpService.class);
+ assertAvailable(testContext, TokenProvider.class);
+ assertAvailable(testContext, GadgetManagement.class);
+ assertAvailable(testContext, OpenSocialContainer.class);
+ assertAvailable(testContext, LoginService.class);
+
+ // Run the tests
+ test(DashboardTest.class);
+
+ // And we are done
+ testContext.tearDown();
+ }
+
+ private <T extends OpenSocialTestBase> void test(Class<T> testClass)
throws Exception {
+ T test = testClass.newInstance();
+ init(test);
+ test.execute();
+ }
+
+ private void init(OpenSocialTestBase test) {
+ test.setLogService(m_logService);
+ test.setUserAdmin(m_userAdmin);
+ }
+}
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits