use of org.apache.aries.application.DeploymentMetadata in project aries by apache.
the class AriesApplicationManagerImplTest method testUpdateWithIncorrectDepMf.
@Test(expected = IllegalArgumentException.class)
public void testUpdateWithIncorrectDepMf() throws Exception {
AriesApplication app = createApplication(TEST_EBA);
DeploymentMetadata depMf = Skeleton.newMock(DeploymentMetadata.class);
Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationSymbolicName"), "random.app");
Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationVersion"), new Version("1.0.0"));
AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
_appMgr.setApplicationContextManager(ctxMgr);
_appMgr.update(app, depMf);
}
use of org.apache.aries.application.DeploymentMetadata in project aries by apache.
the class AriesApplicationManagerImplTest method testFailedUpdate.
@Test
public void testFailedUpdate() throws Exception {
AriesApplication app = createApplication(TEST_EBA);
DeploymentMetadata depMf = createUpdateDepMf();
AriesApplicationContext ctx = Skeleton.newMock(AriesApplicationContext.class);
Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(AriesApplicationContext.class, "getApplication"), app);
AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
Skeleton.getSkeleton(ctxMgr).setReturnValue(new MethodCall(AriesApplicationContextManager.class, "getApplicationContexts"), Collections.singleton(ctx));
Skeleton.getSkeleton(ctxMgr).setThrows(new MethodCall(AriesApplicationContextManager.class, "update", AriesApplication.class, DeploymentMetadata.class), new UpdateException("", null, false, null));
_appMgr.setApplicationContextManager(ctxMgr);
try {
_appMgr.update(app, depMf);
fail("Update should have failed.");
} catch (UpdateException e) {
assertTrue("Deployment.mf should have been updated", app.getDeploymentMetadata() == depMf);
}
}
use of org.apache.aries.application.DeploymentMetadata in project aries by apache.
the class AriesApplicationManagerImplTest method testCreateAndConversion.
@Test
public void testCreateAndConversion() throws Exception {
AriesApplication app = createApplication(CONVERSION_EBA);
ApplicationMetadata appMeta = app.getApplicationMetadata();
assertEquals(appMeta.getApplicationName(), "conversion.eba");
assertEquals(appMeta.getApplicationSymbolicName(), "conversion.eba");
assertEquals(appMeta.getApplicationVersion(), new Version("0.0"));
List<Content> appContent = appMeta.getApplicationContents();
assertEquals(2, appContent.size());
Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
assertTrue(appContent.contains(fbw));
assertTrue(appContent.contains(mbl));
DeploymentMetadata dm = app.getDeploymentMetadata();
List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
assertEquals(2, dcList.size());
DeploymentContent dc1 = new DeploymentContentImpl("hello.world.jar;deployed-version=1.1.0");
DeploymentContent dc2 = new DeploymentContentImpl("helloWorld.war;deployed-version=0.0.0");
DeploymentContent dc3 = new DeploymentContentImpl("a.handy.persistence.library;deployed-version=1.1.0");
assertTrue(dcList.contains(dc1));
assertTrue(dcList.contains(dc2));
dcList = dm.getApplicationProvisionBundles();
assertEquals(1, dcList.size());
assertTrue(dcList.contains(dc3));
assertEquals(2, app.getBundleInfo().size());
BundleInfo info;
info = findBundleInfo(app.getBundleInfo(), "hello.world.jar");
assertNotNull(info);
assertEquals("HelloWorldJar", info.getHeaders().get(Constants.BUNDLE_NAME));
info = findBundleInfo(app.getBundleInfo(), "helloWorld.war");
assertNotNull(info);
assertEquals("helloWorld.war", info.getHeaders().get(Constants.BUNDLE_NAME));
assertEquals("/test", info.getHeaders().get("Bundle-ContextPath"));
}
use of org.apache.aries.application.DeploymentMetadata in project aries by apache.
the class BundleFrameworkConfigurationFactoryImpl method createBundleFrameworkConfig.
public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId, BundleContext parentCtx, AriesApplication app) {
BundleFrameworkConfiguration config = null;
DeploymentMetadata metadata = app.getDeploymentMetadata();
/**
* Set up framework config properties
*/
Properties frameworkConfig = new Properties();
// Problems occur if the parent framework has osgi.console set because the child framework
// will also attempt to listen on the same port which will cause port clashs. Setting this
// to null essentially turns the console off.
frameworkConfig.put("osgi.console", "none");
String flowedSystemPackages = EquinoxFrameworkUtils.calculateSystemPackagesToFlow(EquinoxFrameworkUtils.getSystemExtraPkgs(parentCtx), metadata.getImportPackage());
frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, flowedSystemPackages);
/**
* Set up BundleManifest for the framework bundle
*/
Properties frameworkBundleManifest = new Properties();
frameworkBundleManifest.put(Constants.BUNDLE_SYMBOLICNAME, metadata.getApplicationSymbolicName());
frameworkBundleManifest.put(Constants.BUNDLE_VERSION, metadata.getApplicationVersion().toString());
/**
* Set up Import-Package header for framework manifest
*/
// Extract the import packages and remove anything we already have available in the current framework
Collection<Content> imports = EquinoxFrameworkUtils.calculateImports(metadata.getImportPackage(), EquinoxFrameworkUtils.getExportPackages(parentCtx));
if (imports != null && !imports.isEmpty()) {
StringBuffer buffer = new StringBuffer();
for (Content i : imports) buffer.append(EquinoxFrameworkUtils.contentToString(i) + ",");
frameworkBundleManifest.put(Constants.IMPORT_PACKAGE, buffer.substring(0, buffer.length() - 1));
}
/**
* Set up CompositeServiceFilter-Import header for framework manifest
*/
StringBuilder serviceImportFilter = new StringBuilder();
String txRegsitryImport = "(" + Constants.OBJECTCLASS + "=" + EquinoxFrameworkConstants.TRANSACTION_REGISTRY_BUNDLE + ")";
Collection<Filter> deployedServiceImports = metadata.getDeployedServiceImport();
//if there are more services than the txRegistry import a OR group is required for the Filter
if (deployedServiceImports.size() > 0) {
serviceImportFilter.append("(|");
}
for (Filter importFilter : metadata.getDeployedServiceImport()) {
serviceImportFilter.append(importFilter.toString());
}
serviceImportFilter.append(txRegsitryImport);
//close the OR group if needed
if (deployedServiceImports.size() > 0) {
serviceImportFilter.append(")");
}
frameworkBundleManifest.put(EquinoxFrameworkConstants.COMPOSITE_SERVICE_FILTER_IMPORT, serviceImportFilter.toString());
config = new BundleFrameworkConfigurationImpl(frameworkId, frameworkConfig, frameworkBundleManifest);
return config;
}
use of org.apache.aries.application.DeploymentMetadata in project aries by apache.
the class TwitterTest method testTwitter.
/**
* Test for ARIES-461
* Application that bring in dependency bundles from a bundle repository doesn't deploy
*
* @throws Exception
*/
@Test
public void testTwitter() throws Exception {
// provision against the local runtime
System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
deleteRepos();
MavenArtifactUrlReference twitterEbaUrl = maven("org.apache.aries.samples.twitter", "org.apache.aries.samples.twitter.eba").versionAsInProject().type("eba");
MavenArtifactUrlReference twitterCommonLangJar = maven("commons-lang", "commons-lang").versionAsInProject();
MavenArtifactUrlReference twitterJar = maven("org.apache.aries.samples.twitter", "org.apache.aries.samples.twitter.twitter4j").versionAsInProject();
// add the repository xml to the repository admin
String repositoryXML = getRepoContent("/obr/twitter/TwitterRepository.xml");
// replace the jar file url with the real url related to the environment
String repo = repositoryXML.replaceAll("commons.lang.location", twitterCommonLangJar.getURL()).replaceAll("twitter4j.location", twitterJar.getURL());
URL url = getRepoUrl(repo);
repositoryAdmin.addRepository(url);
AriesApplication app = manager.createApplication(new URL(twitterEbaUrl.getURL()));
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();
}
Aggregations