You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jb...@apache.org on 2010/12/13 19:26:35 UTC
svn commit: r1045274 [2/7] - in
/incubator/aries/sandbox/jbohn/interceptor-proto: ./ application/
application/application-api/src/main/java/org/apache/aries/application/
application/application-api/src/main/java/org/apache/aries/application/management/...
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/DeploymentMetadata.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/DeploymentMetadata.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/DeploymentMetadata.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/DeploymentMetadata.java Mon Dec 13 18:26:19 2010
@@ -76,7 +76,7 @@ public interface DeploymentMetadata {
* Get the list of DeployedService-Import
* @return DeployedService-Import
*/
- public Collection<Filter> getDeployedServiceImport() throws InvalidAttributeException;
+ public Collection<Filter> getDeployedServiceImport();
/**
* get the contents of deployment manifest in a map
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationContext.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationContext.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/AriesApplicationContext.java Mon Dec 13 18:26:19 2010
@@ -49,13 +49,13 @@ public interface AriesApplicationContext
* in the associated AriesApplication's DeploymentMetadata.
* @throws BundleException
*/
- public void start() throws BundleException;
+ public void start() throws BundleException, IllegalStateException;
/**
* Stop the application by stopping all its constituent bundles.
* @throws BundleException
*/
- public void stop() throws BundleException;
+ public void stop() throws BundleException, IllegalStateException;
/**
* Get the org.osgi.framework.Bundle objects representing the application's runtime
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkFactory.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkFactory.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkFactory.java Mon Dec 13 18:26:19 2010
@@ -19,7 +19,6 @@
package org.apache.aries.application.management.spi.framework;
-import java.util.Properties;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -28,14 +27,10 @@ public interface BundleFrameworkFactory
/**
* Creates a new isolated bundle framework with the properties provided.
* @param bc The context in which to install the new framework
- * @param frameworkId The id of the new framework
- * @param frameworkConfig The config properties used to configure the new framework
- * @param frameworkManifest The manifest used to install the new bundle associated with the framework
+ * @param config The BundleFrameworkConfiguration object used to configure the returned framework
* @return
* @throws BundleException
*/
- public BundleFramework createBundleFramework(BundleContext bc,
- String frameworkId,
- Properties frameworkConfig,
- Properties frameworkManifest) throws BundleException;
+ public BundleFramework createBundleFramework(BundleContext bc, BundleFrameworkConfiguration config)
+ throws BundleException;
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkManager.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkManager.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkManager.java Mon Dec 13 18:26:19 2010
@@ -29,12 +29,18 @@ import org.apache.aries.application.Depl
import org.apache.aries.application.DeploymentMetadata;
import org.apache.aries.application.management.AriesApplication;
import org.apache.aries.application.management.UpdateException;
-import org.apache.aries.application.management.spi.repository.ContextException;
import org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion;
public interface BundleFrameworkManager
{
/**
+ * All additions/removals of frameworks and bundles from the shared bundle framework are
+ * performed under this object lock. Users bypassing this api and performing operations on
+ * the underlying OSGi frameworks should be sure to hold this lock.
+ */
+ Object SHARED_FRAMEWORK_LOCK = new Object();
+
+ /**
* Gets the BundleFramework object associated with the given bundle
* @param frameworkBundle - The bundle representing the bundle framework
* @return
@@ -76,7 +82,7 @@ public interface BundleFrameworkManager
public boolean allowsUpdate(DeploymentMetadata newMetadata, DeploymentMetadata oldMetadata);
public interface BundleLocator {
- public Map<DeploymentContent, BundleSuggestion> suggestBundle(Collection<DeploymentContent> bundles) throws ContextException;
+ public Map<DeploymentContent, BundleSuggestion> suggestBundle(Collection<DeploymentContent> bundles) throws BundleException;
}
public void updateBundles(
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/repository/BundleRepository.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/repository/BundleRepository.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/repository/BundleRepository.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/repository/BundleRepository.java Mon Dec 13 18:26:19 2010
@@ -24,8 +24,8 @@ import java.util.Set;
import org.apache.aries.application.Content;
import org.apache.aries.application.DeploymentContent;
import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.spi.framework.BundleFramework;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
@@ -53,7 +53,7 @@ public interface BundleRepository {
* @return the installed bundle
* @throws BundleException
*/
- public Bundle install(BundleContext ctx,
+ public Bundle install(BundleFramework framework,
AriesApplication app) throws BundleException;
/**
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/update/UpdateStrategy.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/update/UpdateStrategy.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/update/UpdateStrategy.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-api/src/main/java/org/apache/aries/application/management/spi/update/UpdateStrategy.java Mon Dec 13 18:26:19 2010
@@ -27,9 +27,9 @@ import org.apache.aries.application.mana
import org.apache.aries.application.management.UpdateException;
import org.apache.aries.application.management.spi.framework.BundleFramework;
import org.apache.aries.application.management.spi.repository.BundleRepository;
-import org.apache.aries.application.management.spi.repository.ContextException;
import org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
/**
* Plug point for update implementation
@@ -55,7 +55,7 @@ public interface UpdateStrategy {
* Find {@link BundleSuggestion} objects for new bundle requests
*/
public Map<DeploymentContent, BundleRepository.BundleSuggestion> suggestBundle(Collection<DeploymentContent> bundles)
- throws ContextException;
+ throws BundleException;
/**
* Register a new bundle with the application (i.e. a new bundle was installed)
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/main/java/org/apache/aries/application/deployment/management/impl/DeploymentManifestManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/main/java/org/apache/aries/application/deployment/management/impl/DeploymentManifestManagerImpl.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/main/java/org/apache/aries/application/deployment/management/impl/DeploymentManifestManagerImpl.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/main/java/org/apache/aries/application/deployment/management/impl/DeploymentManifestManagerImpl.java Mon Dec 13 18:26:19 2010
@@ -67,6 +67,7 @@ import org.apache.aries.application.util
import org.apache.aries.application.utils.filesystem.FileSystem;
import org.apache.aries.application.utils.filesystem.IOUtils;
import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor.NameValueMap;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.service.blueprint.container.ServiceUnavailableException;
@@ -76,7 +77,7 @@ import org.slf4j.LoggerFactory;
public class DeploymentManifestManagerImpl implements DeploymentManifestManager
{
- private Logger _logger = LoggerFactory.getLogger(DeploymentManifestManagerImpl.class);
+ private final Logger _logger = LoggerFactory.getLogger(DeploymentManifestManagerImpl.class);
private AriesApplicationResolver resolver;
private PostResolveTransformer postResolveTransformer = null;
@@ -130,7 +131,7 @@ public class DeploymentManifestManagerIm
* @throws ResolverException
*/
@Override
- public Manifest generateDeploymentManifest( AriesApplication app, ResolveConstraint... constraints ) throws ResolverException
+ public Manifest generateDeploymentManifest(AriesApplication app, ResolveConstraint... constraints ) throws ResolverException
{
_logger.debug(LOG_ENTRY, "generateDeploymentManifest", new Object[]{app, constraints});
@@ -332,6 +333,8 @@ public class DeploymentManifestManagerIm
throw (rx);
}
}
+
+ checkForIsolatedContentInProvisionBundle(appSymbolicName, deployedBundles);
if (postResolveTransformer != null) try {
deployedBundles = postResolveTransformer.postResolveProcess (appMetadata, deployedBundles);
@@ -526,6 +529,61 @@ public class DeploymentManifestManagerIm
return suspects;
}
+
+ /**
+ * Check whether there are isolated bundles deployed into both deployed content and provision bundles. This almost
+ * always indicates a resolution problem hence we throw a ResolverException.
+ * Note that we check provision bundles rather than provision bundles and deployed use bundles. So in any corner case
+ * where the rejected deployment is actually intended, it can still be achieved by introducing a use bundle clause.
+ *
+ * @param applicationSymbolicName
+ * @param appContentBundles
+ * @param provisionBundles
+ * @throws ResolverException
+ */
+ private void checkForIsolatedContentInProvisionBundle(String applicationSymbolicName, DeployedBundles db)
+ throws ResolverException
+ {
+ for (ModelledResource isolatedBundle : db.getDeployedContent()) {
+ for (ModelledResource provisionBundle : db.getDeployedProvisionBundle()) {
+ if (isolatedBundle.getSymbolicName().equals(provisionBundle.getSymbolicName())
+ && providesPackage(provisionBundle, db.getImportPackage())) {
+
+ throw new ResolverException(
+ MessageUtil.getMessage("ISOLATED_CONTENT_PROVISIONED",
+ applicationSymbolicName,
+ isolatedBundle.getSymbolicName(),
+ isolatedBundle.getVersion(),
+ provisionBundle.getVersion()));
+ }
+ }
+ }
+ }
+
+ /**
+ * Can the modelled resource provide a package against the given import specificiation
+ * @param bundle
+ * @param importPackages
+ * @return
+ */
+ private boolean providesPackage(ModelledResource bundle, String importPackages)
+ {
+ Map<String, NameValueMap<String, String>> imports = ManifestHeaderProcessor.parseImportString(importPackages);
+
+ try {
+ for (Map.Entry<String, NameValueMap<String,String>> e : imports.entrySet()) {
+ ImportedPackage importPackage = modellingManager.getImportedPackage(e.getKey(), e.getValue());
+
+ for (ExportedPackage export : bundle.getExportedPackages()) {
+ if (importPackage.isSatisfied(export)) return true;
+ }
+ }
+ } catch (InvalidAttributeException iae) {
+ _logger.error(MessageUtil.getMessage("UNEXPECTED_EXCEPTION_PARSING_IMPORTS", iae, importPackages), iae);
+ }
+
+ return false;
+ }
/**
* Covert a collection of contents to a collection of ImportedBundle objects
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/main/resources/org/apache/aries/application/deployment/management/messages/DeploymentManagementMessages.properties
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/main/resources/org/apache/aries/application/deployment/management/messages/DeploymentManagementMessages.properties?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/main/resources/org/apache/aries/application/deployment/management/messages/DeploymentManagementMessages.properties (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/main/resources/org/apache/aries/application/deployment/management/messages/DeploymentManagementMessages.properties Mon Dec 13 18:26:19 2010
@@ -23,3 +23,6 @@ SUSPECTED_CIRCULAR_DEPENDENCIES=Resoluti
EMPTY_DEPLOYMENT_CONTENT=Enterprise application {0} contains no content.
POST_RESOLVE_TRANSFORMER_UNAVAILABLE=An instance of the PostResolveTransformer was injected earlier but is currently inaccessible. Exception: {0}
+
+ISOLATED_CONTENT_PROVISIONED=Enterprise application {0} has resolved to a configuration where bundle {1} is deployed as part of the deployment content at version {2} and also as part of provisioned content at version {3}.
+UNEXPECTED_EXCEPTION_PARSING_IMPORTS=An unexpected exception {0} was encountered during parsing the generated import package statement {1}.
\ No newline at end of file
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/test/java/org/apache/aries/application/deployment/management/DeploymentGeneratorTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/test/java/org/apache/aries/application/deployment/management/DeploymentGeneratorTest.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/test/java/org/apache/aries/application/deployment/management/DeploymentGeneratorTest.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-deployment-management/src/test/java/org/apache/aries/application/deployment/management/DeploymentGeneratorTest.java Mon Dec 13 18:26:19 2010
@@ -25,6 +25,7 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -211,9 +212,10 @@ public class DeploymentGeneratorTest
ModelledResource mb = createModelledResource(bundleName, bundleVersion,
Arrays.asList(importedPackages) , Arrays.asList(exportedPackages));
- return mb.getExportedPackages().iterator().next();
-
+
+ return mb.getExportedPackages().iterator().next();
}
+
static {
try {
CAPABILITY_A = createExportedPackage ("aries.test.a", "1.0.0", new String[] {"aries.test.a"},
@@ -252,11 +254,11 @@ public class DeploymentGeneratorTest
Attributes attrs = man.getMainAttributes();
assertEquals("aries.test", attrs.getValue(AppConstants.APPLICATION_SYMBOLIC_NAME));
- assertEquals("1.0.0", (String)attrs.getValue(AppConstants.APPLICATION_VERSION));
+ assertEquals("1.0.0", attrs.getValue(AppConstants.APPLICATION_VERSION));
- String content = (String)attrs.getValue(AppConstants.DEPLOYMENT_CONTENT);
- String useBundle = (String) attrs.getValue(AppConstants.DEPLOYMENT_USE_BUNDLE);
- String provisioned =(String)attrs.getValue(AppConstants.DEPLOYMENT_PROVISION_BUNDLE);
+ String content = attrs.getValue(AppConstants.DEPLOYMENT_CONTENT);
+ String useBundle = attrs.getValue(AppConstants.DEPLOYMENT_USE_BUNDLE);
+ String provisioned =attrs.getValue(AppConstants.DEPLOYMENT_PROVISION_BUNDLE);
assertTrue(content.contains("aries.test.a;deployed-version=1.0.0"));
assertTrue(content.contains("aries.test.b;deployed-version=1.1.0"));
@@ -370,6 +372,114 @@ public class DeploymentGeneratorTest
}
}
+ @Test
+ public void checkBundleInAppContentAndProvisionContent() throws Exception
+ {
+ List<ModelledResource> cmr = new ArrayList<ModelledResource>();
+ cmr.add(createModelledResource("test.api", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
+ cmr.add(createModelledResource("test.api", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
+ cmr.add(createModelledResource("test.consumer", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,2.0.0)\""), Collections.<String>emptyList()));
+ cmr.add(createModelledResource("test.provider", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
+
+ // The second time DeploymentGenerator calls the Resolver, it will provide just
+ // test.shared. The resolver will return test.shared _plus_ test.isolated.
+ _resolver.addResult(cmr);
+ Skeleton.getSkeleton(appMetadata).setReturnValue(
+ new MethodCall(ApplicationMetadata.class, "getApplicationContents"),
+ Arrays.asList(
+ mockContent("test.api" , "1.1.0"),
+ mockContent("test.consumer" , "1.0.0"),
+ mockContent("test.provider", "1.0.0")));
+
+ app = Skeleton.newMock(AriesApplication.class);
+ Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
+
+ try {
+ DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles (appMetadata,
+ Arrays.asList(new ModelledResource[] {cmr.get(0), cmr.get(2), cmr.get(3)}),
+ new ArrayList<Content>());
+ deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(),
+ appMetadata.getApplicationVersion().toString(), deployedBundles);
+
+ fail("Expected exception because we can't provision an isolated bundle twice");
+ } catch (ResolverException rx) {}
+ }
+
+ /**
+ * Similar to the checkBundleInAppContentAndProvisionContent scenario. However, this time the provisioned bundle does not provide
+ * a package or service to the isolated content, so there is no problem.
+ * @throws Exception
+ */
+ @Test
+ public void checkBundleInAppContentAndProvisionContentButNothingSharedToIsolatedContent() throws Exception
+ {
+ List<ModelledResource> cmr = new ArrayList<ModelledResource>();
+ cmr.add(createModelledResource("test.util", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
+ cmr.add(createModelledResource("test.bundle", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.1.0,2.0.0)\""), Collections.<String>emptyList()));
+ cmr.add(createModelledResource("test.provisioned", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
+ cmr.add(createModelledResource("test.util", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
+
+ // The second time DeploymentGenerator calls the Resolver, it will provide just
+ // test.shared. The resolver will return test.shared _plus_ test.isolated.
+ _resolver.addResult(cmr);
+ Skeleton.getSkeleton(appMetadata).setReturnValue(
+ new MethodCall(ApplicationMetadata.class, "getApplicationContents"),
+ Arrays.asList(
+ mockContent("test.util" , "1.1.0"),
+ mockContent("test.bundle", "1.0.0")));
+
+ app = Skeleton.newMock(AriesApplication.class);
+ Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
+
+ DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles (appMetadata,
+ Arrays.asList(new ModelledResource[] {cmr.get(0), cmr.get(1)}),
+ new ArrayList<Content>());
+ Manifest mf = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(),
+ appMetadata.getApplicationVersion().toString(), deployedBundles);
+
+ assertTrue(mf.getMainAttributes().getValue("Deployed-Content").contains("test.util;deployed-version=1.1.0"));
+ assertTrue(mf.getMainAttributes().getValue("Provision-Bundle").contains("test.util;deployed-version=1.0.0"));
+ }
+
+ @Test
+ public void checkBundleInAppContentAndUseContent() throws Exception
+ {
+ List<ModelledResource> cmr = new ArrayList<ModelledResource>();
+ cmr.add(createModelledResource("test.api", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
+ cmr.add(createModelledResource("test.api", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
+ cmr.add(createModelledResource("test.consumer", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,2.0.0)\""), Collections.<String>emptyList()));
+ cmr.add(createModelledResource("test.provider", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
+
+ // The second time DeploymentGenerator calls the Resolver, it will provide just
+ // test.shared. The resolver will return test.shared _plus_ test.isolated.
+ _resolver.addResult(cmr);
+
+ Skeleton.getSkeleton(appMetadata).setReturnValue(
+ new MethodCall(ApplicationMetadata.class, "getApplicationContents"),
+ Arrays.asList(
+ mockContent("test.api" , "1.1.0"),
+ mockContent("test.consumer" , "1.0.0"),
+ mockContent("test.provider", "1.0.0")));
+
+ Skeleton.getSkeleton(appMetadata).setReturnValue(
+ new MethodCall(ApplicationMetadata.class, "getUseBundles"),
+ Arrays.asList(mockContent("test.api", "1.0.0")));
+
+ app = Skeleton.newMock(AriesApplication.class);
+ Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
+
+ DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles (appMetadata,
+ Arrays.asList(new ModelledResource[] {cmr.get(0), cmr.get(2), cmr.get(3)}),
+ new ArrayList<Content>());
+
+ Manifest mf = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(),
+ appMetadata.getApplicationVersion().toString(), deployedBundles);
+
+ mf.write(System.out);
+ assertTrue(mf.getMainAttributes().getValue("Deployed-Content").contains("test.api;deployed-version=1.1.0"));
+ assertTrue(mf.getMainAttributes().getValue("Deployed-Use-Bundle").contains("test.api;deployed-version=1.0.0"));
+ }
+
public static ModelledResource createModelledResource(String bundleName, String bundleVersion,
Collection<String> importedPackages, Collection<String> exportedPackages) throws InvalidAttributeException {
Attributes att = new Attributes();
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/pom.xml Mon Dec 13 18:26:19 2010
@@ -122,6 +122,13 @@
<dependency>
<groupId>org.apache.aries.application</groupId>
+ <artifactId>twitter4j</artifactId>
+ <version>2.0.8</version>
+
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.application</groupId>
<artifactId>org.apache.aries.application.management</artifactId>
<scope>test</scope>
</dependency>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/AbstractIntegrationTest.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/AbstractIntegrationTest.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/AbstractIntegrationTest.java Mon Dec 13 18:26:19 2010
@@ -142,7 +142,7 @@ public class AbstractIntegrationTest {
tracker = new ServiceTracker(bc == null ? bundleContext : bc, osgiFilter,
null);
tracker.open();
-
+
// add tracker to the list of trackers we close at tear down
srs.add(tracker);
@@ -168,6 +168,16 @@ public class AbstractIntegrationTest {
+ artifactVersion + "/eba", new Handler());
return urlToEba;
}
+
+ public static URL getUrlToBundle(String groupId, String artifactId) throws MalformedURLException {
+ String artifactVersion = getArtifactVersion(groupId, artifactId);
+
+ // Need to use handler from org.ops4j.pax.url.mvn
+ URL urlToEba = new URL(null,
+ ServiceConstants.PROTOCOL + ":" + groupId + "/" +artifactId + "/"
+ + artifactVersion, new Handler());
+ return urlToEba;
+ }
public static String getArtifactVersion(final String groupId, final String artifactId)
{
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java Mon Dec 13 18:26:19 2010
@@ -36,6 +36,7 @@ import org.apache.aries.application.mana
import org.apache.aries.application.management.spi.repository.RepositoryGenerator;
import org.apache.aries.application.modelling.ModellingManager;
import org.apache.aries.application.runtime.itests.util.IsolationTestUtils;
+import org.apache.aries.application.utils.AppConstants;
import org.apache.aries.application.utils.filesystem.FileSystem;
import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
import org.apache.aries.isolated.sample.HelloWorld;
@@ -239,6 +240,8 @@ public class IsolatedRuntimeTest extends
// logging (logProfile)
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+ // do not provision against the local runtime
+ systemProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP).value("true"),
// Bundles
mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.blueprint"),
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverAdvancedTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverAdvancedTest.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverAdvancedTest.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverAdvancedTest.java Mon Dec 13 18:26:19 2010
@@ -1,529 +1,558 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.aries.application.runtime.itests;
-import static junit.framework.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.ops4j.pax.exam.CoreOptions.equinox;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.apache.aries.application.Content;
-import org.apache.aries.application.DeploymentContent;
-import org.apache.aries.application.DeploymentMetadata;
-import org.apache.aries.application.filesystem.IDirectory;
-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.ResolverException;
-import org.apache.aries.application.management.spi.repository.RepositoryGenerator;
-import org.apache.aries.application.modelling.ModelledResource;
-import org.apache.aries.application.modelling.ModelledResourceManager;
-import org.apache.aries.application.utils.filesystem.FileSystem;
-import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
-import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor.NameValueMap;
-import org.apache.aries.sample.HelloWorld;
-import org.apache.aries.unittest.fixture.ArchiveFixture;
-import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
-import org.apache.felix.bundlerepository.Repository;
-import org.apache.felix.bundlerepository.RepositoryAdmin;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-@RunWith(JUnit4TestRunner.class)
-public class OBRResolverAdvancedTest extends AbstractIntegrationTest
-{
- public static final String CORE_BUNDLE_BY_VALUE = "core.bundle.by.value";
- public static final String CORE_BUNDLE_BY_REFERENCE = "core.bundle.by.reference";
- public static final String TRANSITIVE_BUNDLE_BY_VALUE = "transitive.bundle.by.value";
- public static final String TRANSITIVE_BUNDLE_BY_REFERENCE = "transitive.bundle.by.reference";
- public static final String USE_BUNDLE_BY_REFERENCE = "use.bundle.by.reference";
- public static final String REPO_BUNDLE = "aries.bundle1";
- public static final String HELLO_WORLD_CLIENT_BUNDLE="hello.world.client.bundle";
- public static final String HELLO_WORLD_SERVICE_BUNDLE1="hello.world.service.bundle1";
- public static final String HELLO_WORLD_SERVICE_BUNDLE2="hello.world.service.bundle2";
-
- /* Use @Before not @BeforeClass so as to ensure that these resources
- * are created in the paxweb temp directory, and not in the svn tree
- */
- @Before
- public static void createApplications() throws Exception
- {
- ZipFixture bundle = ArchiveFixture.newJar().manifest()
- .attribute(Constants.BUNDLE_SYMBOLICNAME, CORE_BUNDLE_BY_VALUE)
- .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
- .attribute(Constants.IMPORT_PACKAGE, "a.b.c, p.q.r, x.y.z, javax.naming")
- .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
-
-
- FileOutputStream fout = new FileOutputStream(CORE_BUNDLE_BY_VALUE + ".jar");
- bundle.writeOut(fout);
- fout.close();
-
- bundle = ArchiveFixture.newJar().manifest()
- .attribute(Constants.BUNDLE_SYMBOLICNAME, TRANSITIVE_BUNDLE_BY_VALUE)
- .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
- .attribute(Constants.EXPORT_PACKAGE, "p.q.r")
- .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
-
- fout = new FileOutputStream(TRANSITIVE_BUNDLE_BY_VALUE + ".jar");
- bundle.writeOut(fout);
- fout.close();
-
- bundle = ArchiveFixture.newJar().manifest()
- .attribute(Constants.BUNDLE_SYMBOLICNAME, TRANSITIVE_BUNDLE_BY_REFERENCE)
- .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
- .attribute(Constants.EXPORT_PACKAGE, "x.y.z")
- .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
-
- fout = new FileOutputStream(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar");
- bundle.writeOut(fout);
- fout.close();
-
- bundle = ArchiveFixture.newJar().manifest()
- .attribute(Constants.BUNDLE_SYMBOLICNAME, CORE_BUNDLE_BY_REFERENCE)
- .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
- .attribute(Constants.EXPORT_PACKAGE, "d.e.f")
- .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
-
- fout = new FileOutputStream(CORE_BUNDLE_BY_REFERENCE + ".jar");
- bundle.writeOut(fout);
- fout.close();
-
-
-
- // jar up a use bundle
- bundle = ArchiveFixture.newJar().manifest()
- .attribute(Constants.BUNDLE_SYMBOLICNAME, USE_BUNDLE_BY_REFERENCE)
- .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
- .attribute(Constants.EXPORT_PACKAGE, "a.b.c")
- .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
-
- fout = new FileOutputStream(USE_BUNDLE_BY_REFERENCE + ".jar");
- bundle.writeOut(fout);
- fout.close();
- // Create the EBA application
- ZipFixture testEba = ArchiveFixture.newZip()
- .binary("META-INF/APPLICATION.MF",
- OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/APPLICATION-UseBundle.MF"))
- .end()
- .binary(CORE_BUNDLE_BY_VALUE + ".jar", new FileInputStream(CORE_BUNDLE_BY_VALUE + ".jar")).end()
- .binary(TRANSITIVE_BUNDLE_BY_VALUE + ".jar", new FileInputStream(TRANSITIVE_BUNDLE_BY_VALUE + ".jar")).end();
-
- fout = new FileOutputStream("demo.eba");
- testEba.writeOut(fout);
- fout.close();
-
-
- //create the bundle
- bundle = ArchiveFixture.newJar()
- .binary("META-INF/MANIFEST.MF", OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/aries.bundle1/META-INF/MANIFEST.MF")).end()
- .binary("OSGI-INF/blueprint/blueprint.xml", OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/hello-world-client.xml")).end();
- fout = new FileOutputStream(REPO_BUNDLE + ".jar");
- bundle.writeOut(fout);
- fout.close();
-
-
- ///////////////////////////////////////////////
- //create an eba with a helloworld client, which get all 'HelloWorld' services
- //create a helloworld client
- bundle = ArchiveFixture.newJar().manifest()
- .attribute(Constants.BUNDLE_SYMBOLICNAME, HELLO_WORLD_CLIENT_BUNDLE)
- .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
- .attribute("Import-Package", "org.apache.aries.sample")
- .attribute(Constants.BUNDLE_VERSION, "1.0.0").end()
- .binary("org/apache/aries/application/helloworld/client/HelloWorldClientImpl.class",
- BasicAppManagerTest.class.getClassLoader().getResourceAsStream("org/apache/aries/application/helloworld/client/HelloWorldClientImpl.class"))
- .binary("OSGI-INF/blueprint/helloClient.xml",
- BasicAppManagerTest.class.getClassLoader().getResourceAsStream("obr/hello-world-client.xml"))
- .end();
-
-
- fout = new FileOutputStream(HELLO_WORLD_CLIENT_BUNDLE + ".jar");
- bundle.writeOut(fout);
- fout.close();
-
-
- //create two helloworld services
- // create the 1st helloworld service
- bundle = ArchiveFixture.newJar().manifest()
- .attribute(Constants.BUNDLE_SYMBOLICNAME, HELLO_WORLD_SERVICE_BUNDLE1)
- .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
- .attribute("Import-Package", "org.apache.aries.sample")
- .attribute(Constants.BUNDLE_VERSION, "1.0.0").end()
- .binary("org/apache/aries/sample/impl/HelloWorldImpl.class",
- BasicAppManagerTest.class.getClassLoader().getResourceAsStream("org/apache/aries/sample/impl/HelloWorldImpl.class"))
- .binary("OSGI-INF/blueprint/sample-blueprint.xml",
- BasicAppManagerTest.class.getClassLoader().getResourceAsStream("basic/sample-blueprint.xml"))
- .end();
-
- //create the 2nd helloworld service
- fout = new FileOutputStream(HELLO_WORLD_SERVICE_BUNDLE1 + ".jar");
- bundle.writeOut(fout);
- fout.close();
-
- bundle = ArchiveFixture.newJar().manifest()
- .attribute(Constants.BUNDLE_SYMBOLICNAME, HELLO_WORLD_SERVICE_BUNDLE2)
- .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
- .attribute("Import-Package", "org.apache.aries.sample")
- .attribute(Constants.BUNDLE_VERSION, "1.0.0").end()
- .binary("org/apache/aries/sample/impl/HelloWorldImpl.class",
- BasicAppManagerTest.class.getClassLoader().getResourceAsStream("org/apache/aries/sample/impl/HelloWorldImpl.class"))
- .binary("OSGI-INF/blueprint/sample-blueprint.xml",
- BasicAppManagerTest.class.getClassLoader().getResourceAsStream("basic/sample-blueprint.xml"))
- .end();
-
- fout = new FileOutputStream(HELLO_WORLD_SERVICE_BUNDLE2 + ".jar");
- bundle.writeOut(fout);
- fout.close();
-
- //Create a helloworld eba with the client included
- ZipFixture multiServiceHelloEba = ArchiveFixture.newZip()
- .binary(HELLO_WORLD_CLIENT_BUNDLE + ".jar", new FileInputStream(HELLO_WORLD_CLIENT_BUNDLE + ".jar")).end();
-
- fout = new FileOutputStream("hello.eba");
- multiServiceHelloEba.writeOut(fout);
- fout.close();
-
- }
-
- @Test(expected=ResolverException.class)
- public void testDemoAppResolveFail() throws ResolverException, Exception
- {
- generateOBRRepoXML(false, TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + "_0.0.0.jar", USE_BUNDLE_BY_REFERENCE+".jar");
-
- RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
-
- Repository[] repos = repositoryAdmin.listRepositories();
- for (Repository repo : repos) {
- repositoryAdmin.removeRepository(repo.getURI());
- }
-
- repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
-
- AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
- AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("demo.eba")));
-
- app = manager.resolve(app);
-
-
- }
-
- @Test
- public void testDemoApp() throws Exception
- {
- generateOBRRepoXML(false, TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + ".jar", USE_BUNDLE_BY_REFERENCE+".jar");
-
- RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
-
- Repository[] repos = repositoryAdmin.listRepositories();
- for (Repository repo : repos) {
- repositoryAdmin.removeRepository(repo.getURI());
- }
-
- repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
-
- AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
- AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("demo.eba")));
- //installing requires a valid url for the bundle in repository.xml.
-
- app = manager.resolve(app);
-
- DeploymentMetadata depMeta = app.getDeploymentMetadata();
-
- List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
- Collection<DeploymentContent> useBundles = depMeta.getDeployedUseBundle();
- Collection<Content> importPackages = depMeta.getImportPackage();
- assertEquals(provision.toString(), 2, provision.size());
- assertEquals(useBundles.toString(), 1, useBundles.size());
- assertEquals(importPackages.toString(), 4, importPackages.size());
-
- List<String> bundleSymbolicNames = new ArrayList<String>();
-
- for (DeploymentContent dep : provision) {
- bundleSymbolicNames.add(dep.getContentName());
- }
-
- assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_REFERENCE));
- assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_VALUE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_VALUE));
- bundleSymbolicNames.clear();
- for (DeploymentContent dep : useBundles) {
- bundleSymbolicNames.add(dep.getContentName());
- }
- assertTrue("Bundle " + USE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(USE_BUNDLE_BY_REFERENCE));
- Collection<String> packages = new ArrayList<String>();
- NameValueMap<String, String> maps = new NameValueMap<String, String>();
- maps.put("version", "0.0.0");
- maps.put("bundle-symbolic-name", "use.bundle.by.reference");
- maps.put("bundle-version", "[1.0.0,1.0.0]");
- Content useContent = ManifestHeaderProcessor.parseContent("a.b.c", maps);
- assertTrue("Use Bundle not found in import packags", importPackages.contains(useContent));
-
- for (Content c : importPackages) {
- packages.add(c.getContentName());
- }
-
- assertTrue("package javax.naming not found", packages.contains("javax.naming"));
- assertTrue("package p.q.r not found", packages.contains("p.q.r"));
- assertTrue("package x.y.z not found", packages.contains("x.y.z"));
- assertTrue("package a.b.c not found", packages.contains("a.b.c"));
- AriesApplicationContext ctx = manager.install(app);
- ctx.start();
-
- Set<Bundle> bundles = ctx.getApplicationContent();
-
- assertEquals("Number of bundles provisioned in the app", 5, bundles.size());
-
- ctx.stop();
- manager.uninstall(ctx);
-
- }
-
- /**
- * This test just verifies whether every entry in the MANIFEST.MF was fed into the repository generator.
- * Since the IBM JRE generates a slightly different repository file from the Sun JRE as far as the order of xml elements is concerned. It is not feasible
- * to perform a file comparison.
- * @throws Exception
- */
- @Test
- public void testRepo() throws Exception {
- generateOBRRepoXML(true, REPO_BUNDLE+".jar");
- //print out the repository.xml
- BufferedReader reader = new BufferedReader(new FileReader(new File("repository.xml")));
- String line;
- while (( line = reader.readLine()) != null) {
- System.out.println(line);
- }
- // compare the generated with the expected file
- Document real_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File("repository.xml"));
- Document expected_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("/obr/aries.bundle1/expectedRepository.xml"));
- // parse two documents to make sure they have the same number of elements
- Element element_real = real_doc.getDocumentElement();
- Element element_expected = expected_doc.getDocumentElement();
- NodeList nodes_real = element_real.getElementsByTagName("capability");
- NodeList nodes_expected = element_expected.getElementsByTagName("capability");
- assertEquals("The number of capability is not expected. ", nodes_expected.getLength(), nodes_real.getLength());
- nodes_real = element_real.getElementsByTagName("require");
- nodes_expected = element_expected.getElementsByTagName("require");
- assertEquals("The number of require elements is not expected. ", nodes_expected.getLength(), nodes_real.getLength());
- nodes_real = element_real.getElementsByTagName("p");
- nodes_expected = element_expected.getElementsByTagName("p");
- assertEquals("The number of properties is not expected. ", nodes_expected.getLength(), nodes_real.getLength());
- // Let's verify all p elements are shown as expected.
- for (int index=0; index < nodes_expected.getLength(); index++) {
- Node node = nodes_expected.item(index);
- boolean contains = false;
- // make sure the node exists in the real generated repository
- for (int i=0; i<nodes_real.getLength(); i++) {
- Node real_node = nodes_real.item(i);
- if (node.isEqualNode(real_node)) {
- contains = true;
- break;
- }
- }
- assertTrue("The node " + node.toString() + "should exist.", contains);
- }
- }
-
- @Test
- public void testMutlipleServices() throws Exception{
- generateOBRRepoXML(false, HELLO_WORLD_SERVICE_BUNDLE1 + ".jar", HELLO_WORLD_SERVICE_BUNDLE2 + ".jar");
-
- RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
-
- Repository[] repos = repositoryAdmin.listRepositories();
- for (Repository repo : repos) {
- repositoryAdmin.removeRepository(repo.getURI());
- }
-
- repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
-
- AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
- AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("hello.eba")));
- AriesApplicationContext ctx = manager.install(app);
- ctx.start();
-
- // Wait 5 seconds just to give the blueprint-managed beans a chance to come up
- try {
- Thread.sleep(5000);
- } catch (InterruptedException ix) {}
-
- HelloWorld hw = getOsgiService(HelloWorld.class);
- String result = hw.getMessage();
- assertEquals (result, "hello world");
-
-
- // Uncomment the block below after https://issues.apache.org/jira/browse/FELIX-2546,
- // "Only one service is provisioned even when specifying for mulitple services"
- // is fixed. This tracks the problem of provisioning only one service even when we
- // specify multiple services.
- /*
- * HelloWorldManager hwm = getOsgiService(HelloWorldManager.class);
- * int numberOfServices = hwm.getNumOfHelloServices();
- * assertEquals(2, numberOfServices);
- */
- ctx.stop();
- manager.uninstall(ctx);
-
- }
-
-
-
- //Test for JIRA-461 which currently fails.
- @Test
- public void testTwitter() throws Exception
- {
- RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
- Repository[] repos = repositoryAdmin.listRepositories();
- for (Repository repo : repos) {
- repositoryAdmin.removeRepository(repo.getURI());
- }
-
-
- // Use the superclasses' getUrlToEba() method instead of the pax-exam mavenBundle() method because pax-exam is running in a
- // diffference bundle which doesn't have visibility to the META-INF/maven/dependencies.properties file used to figure out the
- // version of the maven artifact.
- URL twitterEbaUrl = getUrlToEba("org.apache.aries.application.itest.twitter",
- "org.apache.aries.application.itest.twitter.eba");
-
- AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
- repositoryAdmin.addRepository("http://sigil.codecauldron.org/spring-external.obr");
- AriesApplication app = manager.createApplication(twitterEbaUrl);
- app = manager.resolve(app);
- DeploymentMetadata depMeta = app.getDeploymentMetadata();
- List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
- Collection<DeploymentContent> useBundles = depMeta.getDeployedUseBundle();
- Collection<DeploymentContent> appContent = depMeta.getApplicationDeploymentContents();
- // We cannot be sure whether there are two or three provision bundles pulled in by Felix OBR as there is an outstanding defect
- // https://issues.apache.org/jira/browse/FELIX-2672
- // The workaround is to check we get the two bunldes we are looking for, instead of insisting on just having two bundles.
-
- List<String> provisionBundleSymbolicNames = new ArrayList<String>();
- for (DeploymentContent dep : provision) {
- provisionBundleSymbolicNames.add(dep.getContentName());
- }
- String provision_bundle1 = "com.springsource.org.apache.commons.lang";
- String provision_bundle2 = "twitter4j";
- assertTrue("Bundle " + provision_bundle1 + " not found.", provisionBundleSymbolicNames.contains(provision_bundle1));
- assertTrue("Bundle " + provision_bundle2 + " not found.", provisionBundleSymbolicNames.contains(provision_bundle2));
- assertEquals(useBundles.toString(), 0, useBundles.size());
- assertEquals(appContent.toString(), 1, appContent.size());
- AriesApplicationContext ctx = manager.install(app);
- ctx.start();
- }
-
- private void generateOBRRepoXML(boolean nullURI, String ... bundleFiles) throws Exception
- {
- Set<ModelledResource> mrs = new HashSet<ModelledResource>();
- FileOutputStream fout = new FileOutputStream("repository.xml");
- RepositoryGenerator repositoryGenerator = getOsgiService(RepositoryGenerator.class);
- ModelledResourceManager modelledResourceManager = getOsgiService(ModelledResourceManager.class);
- for (String fileName : bundleFiles) {
- File bundleFile = new File(fileName);
- IDirectory jarDir = FileSystem.getFSRoot(bundleFile);
- String uri = "";
- if (!!!nullURI) {
- uri = bundleFile.toURI().toString();
- }
- mrs.add(modelledResourceManager.getModelledResource(uri, jarDir));
- }
- repositoryGenerator.generateRepository("Test repo description", mrs, fout);
- fout.close();
- }
-
- @After
- public void clearRepository() {
- RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
- Repository[] repos = repositoryAdmin.listRepositories();
- if ((repos != null) && (repos.length >0)) {
- for (Repository repo : repos) {
- repositoryAdmin.removeRepository(repo.getURI());
- }
- }
- }
-
- @org.ops4j.pax.exam.junit.Configuration
- public static Option[] configuration() {
- Option[] options = options(
- // Log
- mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
- mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
- // Felix Config Admin
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
- // Felix mvn url handler
- mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
-
- // this is how you set the default log level when using pax
- // logging (logProfile)
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
-
- // Bundles
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.api"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.utils"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.management"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.default.local.platform"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.noop.platform.repo"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.noop.postresolve.process"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.runtime"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.resolver.obr"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.deployment.management"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.modeller"),
- mavenBundle("org.apache.felix", "org.apache.felix.bundlerepository"),
- mavenBundle("org.apache.aries.application", "org.apache.aries.application.runtime.itest.interfaces"),
- mavenBundle("org.apache.aries", "org.apache.aries.util"),
- mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
- mavenBundle("org.osgi", "org.osgi.compendium"),
- mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit"),
-
- /* For debugging, uncomment the next two lines */
- /*vmOption ("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5010"),
- waitForFrameworkStartup(), */
-
- /* For debugging, add these imports:
- import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartup;
- import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
- */
-
- equinox().version("3.5.0"));
- options = updateOptions(options);
- return options;
- }
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.aries.application.runtime.itests;
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.aries.application.Content;
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.DeploymentMetadata;
+import org.apache.aries.application.filesystem.IDirectory;
+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.ResolverException;
+import org.apache.aries.application.management.spi.repository.RepositoryGenerator;
+import org.apache.aries.application.modelling.ModelledResource;
+import org.apache.aries.application.modelling.ModelledResourceManager;
+import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.utils.filesystem.FileSystem;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor.NameValueMap;
+import org.apache.aries.sample.HelloWorld;
+import org.apache.aries.unittest.fixture.ArchiveFixture;
+import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
+import org.apache.felix.bundlerepository.Repository;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+@RunWith(JUnit4TestRunner.class)
+public class OBRResolverAdvancedTest extends AbstractIntegrationTest
+{
+ public static final String CORE_BUNDLE_BY_VALUE = "core.bundle.by.value";
+ public static final String CORE_BUNDLE_BY_REFERENCE = "core.bundle.by.reference";
+ public static final String TRANSITIVE_BUNDLE_BY_VALUE = "transitive.bundle.by.value";
+ public static final String TRANSITIVE_BUNDLE_BY_REFERENCE = "transitive.bundle.by.reference";
+ public static final String USE_BUNDLE_BY_REFERENCE = "use.bundle.by.reference";
+ public static final String REPO_BUNDLE = "aries.bundle1";
+ public static final String HELLO_WORLD_CLIENT_BUNDLE="hello.world.client.bundle";
+ public static final String HELLO_WORLD_SERVICE_BUNDLE1="hello.world.service.bundle1";
+ public static final String HELLO_WORLD_SERVICE_BUNDLE2="hello.world.service.bundle2";
+
+ /* Use @Before not @BeforeClass so as to ensure that these resources
+ * are created in the paxweb temp directory, and not in the svn tree
+ */
+ @Before
+ public static void createApplications() throws Exception
+ {
+ ZipFixture bundle = ArchiveFixture.newJar().manifest()
+ .attribute(Constants.BUNDLE_SYMBOLICNAME, CORE_BUNDLE_BY_VALUE)
+ .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
+ .attribute(Constants.IMPORT_PACKAGE, "a.b.c, p.q.r, x.y.z, javax.naming")
+ .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
+
+
+ FileOutputStream fout = new FileOutputStream(CORE_BUNDLE_BY_VALUE + ".jar");
+ bundle.writeOut(fout);
+ fout.close();
+
+ bundle = ArchiveFixture.newJar().manifest()
+ .attribute(Constants.BUNDLE_SYMBOLICNAME, TRANSITIVE_BUNDLE_BY_VALUE)
+ .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
+ .attribute(Constants.EXPORT_PACKAGE, "p.q.r")
+ .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
+
+ fout = new FileOutputStream(TRANSITIVE_BUNDLE_BY_VALUE + ".jar");
+ bundle.writeOut(fout);
+ fout.close();
+
+ bundle = ArchiveFixture.newJar().manifest()
+ .attribute(Constants.BUNDLE_SYMBOLICNAME, TRANSITIVE_BUNDLE_BY_REFERENCE)
+ .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
+ .attribute(Constants.EXPORT_PACKAGE, "x.y.z")
+ .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
+
+ fout = new FileOutputStream(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar");
+ bundle.writeOut(fout);
+ fout.close();
+
+ bundle = ArchiveFixture.newJar().manifest()
+ .attribute(Constants.BUNDLE_SYMBOLICNAME, CORE_BUNDLE_BY_REFERENCE)
+ .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
+ .attribute(Constants.EXPORT_PACKAGE, "d.e.f")
+ .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
+
+ fout = new FileOutputStream(CORE_BUNDLE_BY_REFERENCE + ".jar");
+ bundle.writeOut(fout);
+ fout.close();
+
+
+
+ // jar up a use bundle
+ bundle = ArchiveFixture.newJar().manifest()
+ .attribute(Constants.BUNDLE_SYMBOLICNAME, USE_BUNDLE_BY_REFERENCE)
+ .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
+ .attribute(Constants.EXPORT_PACKAGE, "a.b.c")
+ .attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
+
+ fout = new FileOutputStream(USE_BUNDLE_BY_REFERENCE + ".jar");
+ bundle.writeOut(fout);
+ fout.close();
+ // Create the EBA application
+ ZipFixture testEba = ArchiveFixture.newZip()
+ .binary("META-INF/APPLICATION.MF",
+ OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/APPLICATION-UseBundle.MF"))
+ .end()
+ .binary(CORE_BUNDLE_BY_VALUE + ".jar", new FileInputStream(CORE_BUNDLE_BY_VALUE + ".jar")).end()
+ .binary(TRANSITIVE_BUNDLE_BY_VALUE + ".jar", new FileInputStream(TRANSITIVE_BUNDLE_BY_VALUE + ".jar")).end();
+
+ fout = new FileOutputStream("demo.eba");
+ testEba.writeOut(fout);
+ fout.close();
+
+
+ //create the bundle
+ bundle = ArchiveFixture.newJar()
+ .binary("META-INF/MANIFEST.MF", OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/aries.bundle1/META-INF/MANIFEST.MF")).end()
+ .binary("OSGI-INF/blueprint/blueprint.xml", OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/hello-world-client.xml")).end();
+ fout = new FileOutputStream(REPO_BUNDLE + ".jar");
+ bundle.writeOut(fout);
+ fout.close();
+
+
+ ///////////////////////////////////////////////
+ //create an eba with a helloworld client, which get all 'HelloWorld' services
+ //create a helloworld client
+ bundle = ArchiveFixture.newJar().manifest()
+ .attribute(Constants.BUNDLE_SYMBOLICNAME, HELLO_WORLD_CLIENT_BUNDLE)
+ .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
+ .attribute("Import-Package", "org.apache.aries.sample")
+ .attribute(Constants.BUNDLE_VERSION, "1.0.0").end()
+ .binary("org/apache/aries/application/helloworld/client/HelloWorldClientImpl.class",
+ BasicAppManagerTest.class.getClassLoader().getResourceAsStream("org/apache/aries/application/helloworld/client/HelloWorldClientImpl.class"))
+ .binary("OSGI-INF/blueprint/helloClient.xml",
+ BasicAppManagerTest.class.getClassLoader().getResourceAsStream("obr/hello-world-client.xml"))
+ .end();
+
+
+ fout = new FileOutputStream(HELLO_WORLD_CLIENT_BUNDLE + ".jar");
+ bundle.writeOut(fout);
+ fout.close();
+
+
+ //create two helloworld services
+ // create the 1st helloworld service
+ bundle = ArchiveFixture.newJar().manifest()
+ .attribute(Constants.BUNDLE_SYMBOLICNAME, HELLO_WORLD_SERVICE_BUNDLE1)
+ .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
+ .attribute("Import-Package", "org.apache.aries.sample")
+ .attribute(Constants.BUNDLE_VERSION, "1.0.0").end()
+ .binary("org/apache/aries/sample/impl/HelloWorldImpl.class",
+ BasicAppManagerTest.class.getClassLoader().getResourceAsStream("org/apache/aries/sample/impl/HelloWorldImpl.class"))
+ .binary("OSGI-INF/blueprint/sample-blueprint.xml",
+ BasicAppManagerTest.class.getClassLoader().getResourceAsStream("basic/sample-blueprint.xml"))
+ .end();
+
+ //create the 2nd helloworld service
+ fout = new FileOutputStream(HELLO_WORLD_SERVICE_BUNDLE1 + ".jar");
+ bundle.writeOut(fout);
+ fout.close();
+
+ bundle = ArchiveFixture.newJar().manifest()
+ .attribute(Constants.BUNDLE_SYMBOLICNAME, HELLO_WORLD_SERVICE_BUNDLE2)
+ .attribute(Constants.BUNDLE_MANIFESTVERSION, "2")
+ .attribute("Import-Package", "org.apache.aries.sample")
+ .attribute(Constants.BUNDLE_VERSION, "1.0.0").end()
+ .binary("org/apache/aries/sample/impl/HelloWorldImpl.class",
+ BasicAppManagerTest.class.getClassLoader().getResourceAsStream("org/apache/aries/sample/impl/HelloWorldImpl.class"))
+ .binary("OSGI-INF/blueprint/sample-blueprint.xml",
+ BasicAppManagerTest.class.getClassLoader().getResourceAsStream("basic/sample-blueprint.xml"))
+ .end();
+
+ fout = new FileOutputStream(HELLO_WORLD_SERVICE_BUNDLE2 + ".jar");
+ bundle.writeOut(fout);
+ fout.close();
+
+ //Create a helloworld eba with the client included
+ ZipFixture multiServiceHelloEba = ArchiveFixture.newZip()
+ .binary(HELLO_WORLD_CLIENT_BUNDLE + ".jar", new FileInputStream(HELLO_WORLD_CLIENT_BUNDLE + ".jar")).end();
+
+ fout = new FileOutputStream("hello.eba");
+ multiServiceHelloEba.writeOut(fout);
+ fout.close();
+
+ }
+
+ @Test(expected=ResolverException.class)
+ public void testDemoAppResolveFail() throws ResolverException, Exception
+ {
+ // do not provision against the local runtime
+ System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
+ generateOBRRepoXML(false, TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + "_0.0.0.jar", USE_BUNDLE_BY_REFERENCE+".jar");
+
+ RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
+
+ Repository[] repos = repositoryAdmin.listRepositories();
+ for (Repository repo : repos) {
+ repositoryAdmin.removeRepository(repo.getURI());
+ }
+
+ repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
+
+ AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
+ AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("demo.eba")));
+
+ app = manager.resolve(app);
+
+
+ }
+
+ @Test
+ public void testDemoApp() throws Exception
+ {
+ // do not provision against the local runtime
+ System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
+ generateOBRRepoXML(false, TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + ".jar", USE_BUNDLE_BY_REFERENCE+".jar");
+
+ RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
+
+ Repository[] repos = repositoryAdmin.listRepositories();
+ for (Repository repo : repos) {
+ repositoryAdmin.removeRepository(repo.getURI());
+ }
+
+ repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
+
+ AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
+ AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("demo.eba")));
+ //installing requires a valid url for the bundle in repository.xml.
+
+ app = manager.resolve(app);
+
+ DeploymentMetadata depMeta = app.getDeploymentMetadata();
+
+ List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
+ Collection<DeploymentContent> useBundles = depMeta.getDeployedUseBundle();
+ Collection<Content> importPackages = depMeta.getImportPackage();
+ assertEquals(provision.toString(), 2, provision.size());
+ assertEquals(useBundles.toString(), 1, useBundles.size());
+ assertEquals(importPackages.toString(), 4, importPackages.size());
+
+ List<String> bundleSymbolicNames = new ArrayList<String>();
+
+ for (DeploymentContent dep : provision) {
+ bundleSymbolicNames.add(dep.getContentName());
+ }
+
+ assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_REFERENCE));
+ assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_VALUE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_VALUE));
+ bundleSymbolicNames.clear();
+ for (DeploymentContent dep : useBundles) {
+ bundleSymbolicNames.add(dep.getContentName());
+ }
+ assertTrue("Bundle " + USE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(USE_BUNDLE_BY_REFERENCE));
+ Collection<String> packages = new ArrayList<String>();
+ NameValueMap<String, String> maps = new NameValueMap<String, String>();
+ maps.put("version", "0.0.0");
+ maps.put("bundle-symbolic-name", "use.bundle.by.reference");
+ maps.put("bundle-version", "[1.0.0,1.0.0]");
+ Content useContent = ManifestHeaderProcessor.parseContent("a.b.c", maps);
+ assertTrue("Use Bundle not found in import packags", importPackages.contains(useContent));
+
+ for (Content c : importPackages) {
+ packages.add(c.getContentName());
+ }
+
+ assertTrue("package javax.naming not found", packages.contains("javax.naming"));
+ assertTrue("package p.q.r not found", packages.contains("p.q.r"));
+ assertTrue("package x.y.z not found", packages.contains("x.y.z"));
+ assertTrue("package a.b.c not found", packages.contains("a.b.c"));
+ AriesApplicationContext ctx = manager.install(app);
+ ctx.start();
+
+ Set<Bundle> bundles = ctx.getApplicationContent();
+
+ assertEquals("Number of bundles provisioned in the app", 5, bundles.size());
+
+ ctx.stop();
+ manager.uninstall(ctx);
+
+ }
+
+ /**
+ * This test just verifies whether every entry in the MANIFEST.MF was fed into the repository generator.
+ * Since the IBM JRE generates a slightly different repository file from the Sun JRE as far as the order of xml elements is concerned. It is not feasible
+ * to perform a file comparison.
+ * @throws Exception
+ */
+ @Test
+ public void testRepo() throws Exception {
+ // do not provision against the local runtime
+ System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
+ generateOBRRepoXML(true, REPO_BUNDLE+".jar");
+ //print out the repository.xml
+ BufferedReader reader = new BufferedReader(new FileReader(new File("repository.xml")));
+ String line;
+ while (( line = reader.readLine()) != null) {
+ System.out.println(line);
+ }
+ // compare the generated with the expected file
+ Document real_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File("repository.xml"));
+ Document expected_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("/obr/aries.bundle1/expectedRepository.xml"));
+ // parse two documents to make sure they have the same number of elements
+ Element element_real = real_doc.getDocumentElement();
+ Element element_expected = expected_doc.getDocumentElement();
+ NodeList nodes_real = element_real.getElementsByTagName("capability");
+ NodeList nodes_expected = element_expected.getElementsByTagName("capability");
+ assertEquals("The number of capability is not expected. ", nodes_expected.getLength(), nodes_real.getLength());
+ nodes_real = element_real.getElementsByTagName("require");
+ nodes_expected = element_expected.getElementsByTagName("require");
+ assertEquals("The number of require elements is not expected. ", nodes_expected.getLength(), nodes_real.getLength());
+ nodes_real = element_real.getElementsByTagName("p");
+ nodes_expected = element_expected.getElementsByTagName("p");
+ assertEquals("The number of properties is not expected. ", nodes_expected.getLength(), nodes_real.getLength());
+ // Let's verify all p elements are shown as expected.
+ for (int index=0; index < nodes_expected.getLength(); index++) {
+ Node node = nodes_expected.item(index);
+ boolean contains = false;
+ // make sure the node exists in the real generated repository
+ for (int i=0; i<nodes_real.getLength(); i++) {
+ Node real_node = nodes_real.item(i);
+ if (node.isEqualNode(real_node)) {
+ contains = true;
+ break;
+ }
+ }
+ assertTrue("The node " + node.toString() + "should exist.", contains);
+ }
+ }
+
+ @Test
+ public void testMutlipleServices() throws Exception{
+ // provision against the local runtime
+ System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
+ generateOBRRepoXML(false, HELLO_WORLD_SERVICE_BUNDLE1 + ".jar", HELLO_WORLD_SERVICE_BUNDLE2 + ".jar");
+
+ RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
+
+ Repository[] repos = repositoryAdmin.listRepositories();
+ for (Repository repo : repos) {
+ repositoryAdmin.removeRepository(repo.getURI());
+ }
+
+ repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
+
+ AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
+ AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("hello.eba")));
+ AriesApplicationContext ctx = manager.install(app);
+ ctx.start();
+
+ // Wait 5 seconds just to give the blueprint-managed beans a chance to come up
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException ix) {}
+
+ HelloWorld hw = getOsgiService(HelloWorld.class);
+ String result = hw.getMessage();
+ assertEquals (result, "hello world");
+
+
+ // Uncomment the block below after https://issues.apache.org/jira/browse/FELIX-2546,
+ // "Only one service is provisioned even when specifying for mulitple services"
+ // is fixed. This tracks the problem of provisioning only one service even when we
+ // specify multiple services.
+
+ /** HelloWorldManager hwm = getOsgiService(HelloWorldManager.class);
+ * int numberOfServices = hwm.getNumOfHelloServices();
+ * assertEquals(2, numberOfServices);
+ */
+ ctx.stop();
+ manager.uninstall(ctx);
+
+ }
+
+
+
+ //Test for JIRA-461 which currently fails.
+ @Test
+ public void testTwitter() throws Exception
+ {
+ // provision against the local runtime
+ System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
+ RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
+ Repository[] repos = repositoryAdmin.listRepositories();
+ for (Repository repo : repos) {
+ repositoryAdmin.removeRepository(repo.getURI());
+ }
+
+
+ // Use the superclasses' getUrlToEba() method instead of the pax-exam mavenBundle() method because pax-exam is running in a
+ // diffference bundle which doesn't have visibility to the META-INF/maven/dependencies.properties file used to figure out the
+ // version of the maven artifact.
+ URL twitterEbaUrl = getUrlToEba("org.apache.aries.application.itest.twitter",
+ "org.apache.aries.application.itest.twitter.eba");
+ URL twitterCommonLangJar_url = getUrlToBundle("commons-lang", "commons-lang");
+ URL twitterJar_url = getUrlToBundle("org.apache.aries.application", "twitter4j");
+
+ // add the repository xml to the repository admin
+ StringBuilder repositoryXML = new StringBuilder();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/obr/twitter/TwitterRepository.xml")));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ repositoryXML.append(line);
+ repositoryXML.append("\r\n");
+ }
+ //replace the jar file url with the real url related to the environment
+ String repo = repositoryXML.toString().replaceAll("commons.lang.location", twitterCommonLangJar_url.toExternalForm());
+ repo = repo.replaceAll("twitter4j.location", twitterJar_url.toExternalForm());
+
+ FileWriter writer = new FileWriter("twitterRepo.xml");
+ writer.write(repo);
+ writer.close();
+ repositoryAdmin.addRepository(new File("twitterRepo.xml").toURI().toURL());
+ AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
+ AriesApplication app = manager.createApplication(twitterEbaUrl);
+ app = manager.resolve(app);
+ DeploymentMetadata depMeta = app.getDeploymentMetadata();
+ List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
+ Collection<DeploymentContent> useBundles = depMeta.getDeployedUseBundle();
+ Collection<DeploymentContent> appContent = depMeta.getApplicationDeploymentContents();
+ // We cannot be sure whether there are two or three provision bundles pulled in by Felix OBR as there is an outstanding defect
+ // https://issues.apache.org/jira/browse/FELIX-2672
+ // The workaround is to check we get the two bundles we are looking for, instead of insisting on just having two bundles.
+
+ List<String> provisionBundleSymbolicNames = new ArrayList<String>();
+ for (DeploymentContent dep : provision) {
+ provisionBundleSymbolicNames.add(dep.getContentName());
+ }
+ String provision_bundle1 = "org.apache.commons.lang";
+ String provision_bundle2 = "twitter4j";
+ assertTrue("Bundle " + provision_bundle1 + " not found.", provisionBundleSymbolicNames.contains(provision_bundle1));
+ assertTrue("Bundle " + provision_bundle2 + " not found.", provisionBundleSymbolicNames.contains(provision_bundle2));
+ assertEquals(useBundles.toString(), 0, useBundles.size());
+ assertEquals(appContent.toString(), 1, appContent.size());
+ AriesApplicationContext ctx = manager.install(app);
+ ctx.start();
+ }
+
+ private void generateOBRRepoXML(boolean nullURI, String ... bundleFiles) throws Exception
+ {
+ Set<ModelledResource> mrs = new HashSet<ModelledResource>();
+ FileOutputStream fout = new FileOutputStream("repository.xml");
+ RepositoryGenerator repositoryGenerator = getOsgiService(RepositoryGenerator.class);
+ ModelledResourceManager modelledResourceManager = getOsgiService(ModelledResourceManager.class);
+ for (String fileName : bundleFiles) {
+ File bundleFile = new File(fileName);
+ IDirectory jarDir = FileSystem.getFSRoot(bundleFile);
+ String uri = "";
+ if (!!!nullURI) {
+ uri = bundleFile.toURI().toString();
+ }
+ mrs.add(modelledResourceManager.getModelledResource(uri, jarDir));
+ }
+ repositoryGenerator.generateRepository("Test repo description", mrs, fout);
+ fout.close();
+ }
+
+ @After
+ public void clearRepository() {
+ RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
+ Repository[] repos = repositoryAdmin.listRepositories();
+ if ((repos != null) && (repos.length >0)) {
+ for (Repository repo : repos) {
+ repositoryAdmin.removeRepository(repo.getURI());
+ }
+ }
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+ // this is how you set the default log level when using pax
+ // logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.api"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.utils"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.management"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.default.local.platform"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.noop.platform.repo"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.noop.postresolve.process"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.runtime"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.resolver.obr"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.deployment.management"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.modeller"),
+ mavenBundle("org.apache.felix", "org.apache.felix.bundlerepository"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.runtime.itest.interfaces"),
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+ mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit"),
+ /* For debugging, uncomment the next two lines */
+ /*vmOption ("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5010"),
+ waitForFrameworkStartup(), */
+
+ /* For debugging, add these imports:
+ import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartup;
+ import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
+ */
+
+ equinox().version("3.5.0"));
+ options = updateOptions(options);
+ return options;
+ }
}
\ No newline at end of file
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverTest.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverTest.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverTest.java Mon Dec 13 18:26:19 2010
@@ -42,6 +42,7 @@ import org.apache.aries.application.mana
import org.apache.aries.application.management.spi.repository.RepositoryGenerator;
import org.apache.aries.application.modelling.ModelledResource;
import org.apache.aries.application.modelling.ModelledResourceManager;
+import org.apache.aries.application.utils.AppConstants;
import org.apache.aries.application.utils.filesystem.FileSystem;
import org.apache.aries.unittest.fixture.ArchiveFixture;
import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
@@ -148,6 +149,8 @@ public class OBRResolverTest extends Abs
@Test(expected=ResolverException.class)
public void testBlogAppResolveFail() throws ResolverException, Exception
{
+ // provision against the local runtime
+ System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
generateOBRRepoXML(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + "_0.0.0.jar");
RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
@@ -165,10 +168,41 @@ public class OBRResolverTest extends Abs
app = manager.resolve(app);
}
+ /**
+ * Test the resolution should fail because the required package org.apache.aries.util is provided by the local runtime,
+ * which is not included when provisioning.
+ *
+ * @throws Exception
+ */
+ @Test(expected=ResolverException.class)
+ public void testProvisionExcludeLocalRepo() throws Exception {
+ // do not provision against the local runtime
+ System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
+ generateOBRRepoXML(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + ".jar");
+
+ RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
+
+ Repository[] repos = repositoryAdmin.listRepositories();
+ for (Repository repo : repos) {
+ repositoryAdmin.removeRepository(repo.getURI());
+ }
+
+ repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
+
+ AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
+ AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("blog.eba")));
+ //installing requires a valid url for the bundle in repository.xml.
+
+ app = manager.resolve(app);
+
+
+ }
@Test
public void testBlogApp() throws Exception
{
+ // provision against the local runtime
+ System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
generateOBRRepoXML(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + ".jar");
RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);