use of org.apache.aries.itest.RichBundleContext in project aries by apache.
the class IsolatedCfgAdminRuntimeTest method constructApplications.
/**
* Creates two applications, as follows:
* <p/>
* - helloworld-bp.eba ------
* |
* | This application contains a helloworld bundle which contains an interface and impl for HelloWorld. Upon being started
* | blueprint will create a new container for this bundle and register the HelloWorld service. The service will be injected
* | with a message coming from the ConfigurationAdmin service using the PID: helloworld-bp. As a CM property placeholder is
* | used, a ManagedService will also be registered on the bundles behalf so that further updates can be captured. Note that
* | the blueprint configuration is wired to reload the container on a configuration update (to allow easier tracking of when
* | to test service contents etc).
* |
* | The application also contains a configuration admin bundle (pulled from Maven).
* ---------------------------
* <p/>
* - helloworld-mn.eba -------
* |
* | This application contains a helloworld bundle containing an activator that will register itself as a ManagedService for the
* | PID: helloworld-mn. The activator will also expose out a HelloWorld service. Upon recieving an update from the packaged
* | Configuration Admin service, the HelloWorld service will be re-registered using the latest configuration, namely the "message".
* |
* | The application also contains a configuration admin bundle (pulled from Maven).
* ---------------------------
*
* @throws Exception
*/
@Before
public void constructApplications() throws Exception {
Assert.assertNotNull("Could not find Maven URL handler", (new RichBundleContext(context())).getService(URLStreamHandlerService.class, "url.handler.protocol=mvn", 300000));
MavenArtifactProvisionOption configAdminProvisionOption = mavenBundleInTest(getClass().getClassLoader(), "org.apache.felix", "org.apache.felix.configadmin");
Assert.assertNotNull("Unable to lookup config admin maven bundle", configAdminProvisionOption);
URL configAdminUrl = new URL(configAdminProvisionOption.getURL());
ZipFixture helloWorldBluePrintEba = ArchiveFixture.newZip().binary("META-INF/APPLICATION.MF", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/config/APPLICATION-BP.MF")).binary("org.apache.felix.configadmin.jar", configAdminUrl.openStream()).jar("helloworld-bundle.jar").manifest().symbolicName("org.apache.aries.isolated.helloworldbp").attribute("Bundle-Version", "1.0.0").attribute("Import-Package", "org.osgi.service.cm").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("OSGI-INF/blueprint/blueprint.xml", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/config/blueprint.xml")).end();
ZipFixture helloWorldManualEba = ArchiveFixture.newZip().binary("META-INF/APPLICATION.MF", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/config/APPLICATION-MN.MF")).binary("org.apache.felix.configadmin.jar", configAdminUrl.openStream()).jar("helloworld-bundle.jar").manifest().symbolicName("org.apache.aries.isolated.helloworldmn").attribute("Bundle-Version", "1.0.0").attribute("Bundle-Activator", "org.apache.aries.isolated.config.HelloWorldManagedServiceImpl").attribute("Import-Package", "org.osgi.framework,org.osgi.service.cm").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("org/apache/aries/isolated/config/HelloWorldManagedServiceImpl.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/config/HelloWorldManagedServiceImpl.class")).end();
FileOutputStream fout = new FileOutputStream(APP_HWBP);
helloWorldBluePrintEba.writeOut(fout);
fout.close();
fout = new FileOutputStream(APP_HWMN);
helloWorldManualEba.writeOut(fout);
fout.close();
}
use of org.apache.aries.itest.RichBundleContext in project aries by apache.
the class ModelledResourceManagerTest method setUp.
public void setUp() throws Exception {
super.setUp();
RichBundleContext rootContext = context(getRootSubsystem());
assertNull("Modeller is installed", rootContext.getBundleByName("org.apache.aries.application.modeller"));
assertNull("Blueprint is installed", rootContext.getBundleByName("org.apache.aries.blueprint"));
assertNull("Proxy is installed", rootContext.getBundleByName("org.apache.aries.proxy"));
}
use of org.apache.aries.itest.RichBundleContext in project aries by apache.
the class ConfigurationPostResolverTest method validatePostResolveTransform.
/**
* This test validates that the transformer is correctly detecting the config admin package. Checks
* are performed to validate that an existing import package is still honored etc.
*
* @throws Exception
*/
@Test
public void validatePostResolveTransform() throws Exception {
RichBundleContext ctx = new RichBundleContext(bundleContext);
PostResolveTransformer transformer = ctx.getService(PostResolveTransformer.class);
Assert.assertNotNull("Unable to locate transformer", transformer);
/**
* Try processing deployed content that doesn't have any import for the
* org.osgi.service.cm package, the resultant imports should be unaffected.
*/
ApplicationMetadata mockApplicationMetadata = Skeleton.newMock(ApplicationMetadata.class);
MockDeployedBundles originalDeployedBundles = new MockDeployedBundles();
originalDeployedBundles.setDeployedContent(getNonConfigModelledResources());
DeployedBundles transformedDeployedBundles = transformer.postResolveProcess(mockApplicationMetadata, originalDeployedBundles);
Assert.assertNotNull("An instance should have been returned", transformedDeployedBundles);
Assert.assertEquals(originalDeployedBundles.getImportPackage(), transformedDeployedBundles.getImportPackage());
/**
* Now try processing a deployed bundles instances that has an import for the org.osgi.service.cm package in multiple
* modelled resources with an empty import package set in the mock deployed bundles instance.
*/
originalDeployedBundles = new MockDeployedBundles();
originalDeployedBundles.setDeployedContent(getConfigModelledResources());
transformedDeployedBundles = transformer.postResolveProcess(mockApplicationMetadata, originalDeployedBundles);
Assert.assertNotNull("An instance should have been returned", transformedDeployedBundles);
Assert.assertNotSame("Missing config package", originalDeployedBundles.getImportPackage(), transformedDeployedBundles.getImportPackage());
Assert.assertEquals("Missing config package", "org.osgi.service.cm;version=\"1.2.0\"", transformedDeployedBundles.getImportPackage());
/**
* Now try processing a deployed bundles instances that has an import for the org.osgi.service.cm package in multiple
* modelled resources with a populated import package set in the mock deployed bundles instance.
*/
originalDeployedBundles = new MockDeployedBundles();
originalDeployedBundles.setDeployedContent(getConfigModelledResources());
originalDeployedBundles.setImportPackage("org.foo.bar;version=\1.0.0\",org.bar.foo;version=\"1.0.0\"");
transformedDeployedBundles = transformer.postResolveProcess(mockApplicationMetadata, originalDeployedBundles);
Assert.assertNotNull("An instance should have been returned", transformedDeployedBundles);
Assert.assertNotSame("Missing config package", originalDeployedBundles.getImportPackage(), transformedDeployedBundles.getImportPackage());
Assert.assertEquals("Missing config package", "org.foo.bar;version=\1.0.0\",org.bar.foo;version=\"1.0.0\",org.osgi.service.cm;version=\"1.2.0\"", transformedDeployedBundles.getImportPackage());
}
use of org.apache.aries.itest.RichBundleContext in project aries by apache.
the class BlueprintTest method checkBlueprint.
@Test
public void checkBlueprint() throws Exception {
Subsystem subsystem = installSubsystemFromFile(BLUEPRINT_ESA);
try {
startSubsystem(subsystem);
BundleContext bc = subsystem.getBundleContext();
Hello h = new RichBundleContext(bc).getService(Hello.class);
String message = h.saySomething();
assertEquals("Wrong message back", "messageFromBlueprint", message);
} finally {
stopSubsystem(subsystem);
uninstallSubsystem(subsystem);
}
}
use of org.apache.aries.itest.RichBundleContext in project aries by apache.
the class HelloWorldTest method checkHelloSubsystem.
void checkHelloSubsystem(Subsystem helloSubsystem) throws Exception {
helloSubsystem.start();
BundleContext bc = helloSubsystem.getBundleContext();
Hello h = new RichBundleContext(bc).getService(Hello.class);
String message = h.saySomething();
assertEquals("Wrong message back", "something", message);
helloSubsystem.stop();
}
Aggregations