You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ma...@apache.org on 2010/09/03 19:19:40 UTC
svn commit: r992384 -
/incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java
Author: mahrwald
Date: Fri Sep 3 17:19:40 2010
New Revision: 992384
URL: http://svn.apache.org/viewvc?rev=992384&view=rev
Log:
ARIES-398: ITest for app with bundle in global repository
Modified:
incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java
Modified: incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java?rev=992384&r1=992383&r2=992384&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java (original)
+++ incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java Fri Sep 3 17:19:40 2010
@@ -17,6 +17,7 @@
* under the License.
*/
package org.apache.aries.application.runtime.itests;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.ops4j.pax.exam.CoreOptions.equinox;
@@ -26,14 +27,30 @@ import static org.ops4j.pax.exam.CoreOpt
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.jar.Attributes;
+import org.apache.aries.application.Content;
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.VersionRange;
import org.apache.aries.application.management.AriesApplication;
import org.apache.aries.application.management.AriesApplicationContext;
import org.apache.aries.application.management.AriesApplicationManager;
+import org.apache.aries.application.management.BundleRepository;
+import org.apache.aries.application.management.RepositoryGenerator;
+import org.apache.aries.application.management.ResolveConstraint;
+import org.apache.aries.application.modelling.ModelledResource;
+import org.apache.aries.application.modelling.utils.ModellingManager;
import org.apache.aries.application.utils.filesystem.FileSystem;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
import org.apache.aries.isolated.sample.HelloWorld;
import org.apache.aries.unittest.fixture.ArchiveFixture;
import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,11 +58,14 @@ import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.Version;
import org.osgi.service.framework.CompositeBundle;
import org.osgi.util.tracker.ServiceTracker;
+
@RunWith(JUnit4TestRunner.class)
public class IsolatedRuntimeTest extends AbstractIntegrationTest {
@@ -82,14 +102,29 @@ public class IsolatedRuntimeTest extends
fout = new FileOutputStream("test2.eba");
testEba2.writeOut(fout);
fout.close();
+
+ ZipFixture sampleJar2 = ArchiveFixture.newJar()
+ .manifest().symbolicName("org.apache.aries.isolated.sample")
+ .attribute("Bundle-Version", "2.0.0")
+ .end()
+ .binary("org/apache/aries/isolated/sample/HelloWorld.class",
+ IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class"))
+ .binary("org/apache/aries/isolated/sample/HelloWorldImpl.class",
+ IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class"))
+ .binary("OSGI-INF/blueprint/aries.xml",
+ IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/sample2-blueprint.xml"))
+ .end();
+
+ fout = new FileOutputStream("sample_2.0.0.jar");
+ sampleJar2.writeOut(fout);
+ fout.close();
+
createdApplications = true;
}
@Test
public void testAppWithoutApplicationManifest() throws Exception {
- String result = null;
-
AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test.eba")));
AriesApplicationContext ctx = manager.install(app);
@@ -151,10 +186,97 @@ public class IsolatedRuntimeTest extends
}
}
-
+ @Test
+ public void testAppWithGlobalRepositoryBundle() throws Exception
+ {
+ AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
+ AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba")));
+
+ BundleRepository repo = new BundleRepository() {
+ public int getCost() {
+ return 1;
+ }
+
+ public BundleSuggestion suggestBundleToUse(DeploymentContent content) {
+ if (content.getContentName().equals("org.apache.aries.isolated.sample")) {
+ return new BundleSuggestion() {
+
+ public Bundle install(BundleContext ctx, AriesApplication app) throws BundleException {
+ File f = new File("sample_2.0.0.jar");
+ try {
+ return ctx.installBundle(f.toURL().toString());
+ } catch (MalformedURLException mue) {
+ throw new RuntimeException(mue);
+ }
+ }
+
+ public Version getVersion() {
+ return new Version("2.0.0");
+ }
+
+ public Set<Content> getImportPackage() {
+ return Collections.emptySet();
+ }
+
+ public Set<Content> getExportPackage() {
+ return Collections.emptySet();
+ }
+
+ public int getCost() {
+ return 1;
+ }
+ };
+ } else {
+ return null;
+ }
+ }
+ };
+
+ Hashtable<String, String> props = new Hashtable<String,String>();
+ props.put(BundleRepository.REPOSITORY_SCOPE, BundleRepository.GLOBAL_SCOPE);
+
+ bundleContext.registerService(BundleRepository.class.getName(), repo, props);
+
+ RepositoryGenerator repoGen = getOsgiService(RepositoryGenerator.class);
+ RepositoryAdmin repoAdmin = getOsgiService(RepositoryAdmin.class);
+
+ Attributes attrs = new Attributes();
+ attrs.putValue("Bundle-ManifestVersion", "2");
+ attrs.putValue("Bundle-Version", "2.0.0");
+ attrs.putValue("Bundle-SymbolicName", "org.apache.aries.isolated.sample");
+ attrs.putValue("Manifest-Version", "1");
+
+ ModelledResource res = ModellingManager.getModelledResource(
+ new File("sample_2.0.0.jar").toURI().toString(),
+ attrs,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST);
+
+ repoGen.generateRepository("repo.xml", Arrays.asList(res), new FileOutputStream("repo.xml"));
+ repoAdmin.addRepository(new File("repo.xml").toURI().toString());
+
+ AriesApplication newApp = manager.resolve(app, new ResolveConstraint() {
+ public String getBundleName() {
+ return "org.apache.aries.isolated.sample";
+ }
+
+ public VersionRange getVersionRange() {
+ return ManifestHeaderProcessor.parseVersionRange("[2.0.0,2.0.0]", true);
+ }
+ });
+
+ AriesApplicationContext ctx = manager.install(newApp);
+ ctx.start();
+
+ assertHelloWorldService("org.apache.aries.sample2", "hello brave new world");
+ }
private void assertHelloWorldService(String appName) throws Exception
{
+ assertHelloWorldService(appName, "hello world");
+ }
+
+ private void assertHelloWorldService(String appName, String message) throws Exception
+ {
BundleContext appContext = getAppIsolatedBundleContext(appName);
if (appContext != null) {
@@ -175,7 +297,7 @@ public class IsolatedRuntimeTest extends
Method method = returnClass.getDeclaredMethod("getMessage",null);
String result = (String)method.invoke(hw);
- assertEquals("hello world", result);
+ assertEquals(message, result);
}
else {
fail("No service found inside application framework");
@@ -183,6 +305,7 @@ public class IsolatedRuntimeTest extends
}
+
private BundleContext getAppIsolatedBundleContext(String appName)
{
for (Bundle sharedBundle : bundleContext.getBundles())
@@ -203,7 +326,6 @@ public class IsolatedRuntimeTest extends
return null;
}
-
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() {