Search in sources :

Example 1 with ZipFixture

use of org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture in project aries by apache.

the class OBRAppManagerTest method createApplications.

@Before
public void createApplications() throws Exception {
    if (createdApplications) {
        return;
    }
    ZipFixture testBundle = ArchiveFixture.newZip().manifest().symbolicName("org.apache.aries.sample.bundle").attribute("Bundle-Version", "1.0.0").attribute("Import-Package", "org.apache.aries.sample").attribute("Export-Package", "org.apache.aries.sample.impl").end().binary("org/apache/aries/sample/impl/HelloWorldImpl.class", OBRAppManagerTest.class.getClassLoader().getResourceAsStream("org/apache/aries/sample/impl/HelloWorldImpl.class")).end();
    FileOutputStream fout = new FileOutputStream("bundle.jar");
    testBundle.writeOut(fout);
    fout.close();
    ZipFixture testEba = ArchiveFixture.newZip().jar("sample.jar").manifest().symbolicName("org.apache.aries.sample").attribute("Bundle-Version", "1.0.0").attribute("Import-Package", "org.apache.aries.sample.impl,org.apache.aries.sample").end().binary("OSGI-INF/blueprint/sample-blueprint.xml", OBRAppManagerTest.class.getClassLoader().getResourceAsStream("basic/sample-blueprint.xml")).end().binary("META-INF/APPLICATION.MF", OBRAppManagerTest.class.getClassLoader().getResourceAsStream("basic/APPLICATION.MF")).end();
    fout = new FileOutputStream("test.eba");
    testEba.writeOut(fout);
    fout.close();
    StringBuilder repositoryXML = new StringBuilder();
    BufferedReader reader = new BufferedReader(new InputStreamReader(OBRAppManagerTest.class.getResourceAsStream("/obr/repository.xml")));
    String line;
    while ((line = reader.readLine()) != null) {
        repositoryXML.append(line);
        repositoryXML.append("\r\n");
    }
    String repo = repositoryXML.toString().replaceAll("bundle_location", new File("bundle.jar").toURI().toString());
    System.out.println(repo);
    FileWriter writer = new FileWriter("repository.xml");
    writer.write(repo);
    writer.close();
    createdApplications = true;
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) InputStreamReader(java.io.InputStreamReader) FileOutputStream(java.io.FileOutputStream) FileWriter(java.io.FileWriter) BufferedReader(java.io.BufferedReader) File(java.io.File) Before(org.junit.Before)

Example 2 with ZipFixture

use of org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture in project aries by apache.

the class OBRResolverAdvancedTest method testModellerException.

@Test(expected = ModellerException.class)
public void testModellerException() 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("delete.jar");
    bundle.writeOut(fout);
    fout.close();
    generateOBRRepoXML(false, "delete.jar");
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) FileOutputStream(java.io.FileOutputStream) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with ZipFixture

use of org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture in project aries by apache.

the class OBRResolverTest method createApplications.

/* 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 void createApplications() throws Exception {
    ZipFixture bundle = ArchiveFixture.newJar().manifest().attribute(BUNDLE_SYMBOLICNAME, CORE_BUNDLE_BY_VALUE).attribute(BUNDLE_MANIFESTVERSION, "2").attribute(IMPORT_PACKAGE, "p.q.r, x.y.z, javax.naming, " + BUNDLE_IN_FRAMEWORK).attribute(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(BUNDLE_SYMBOLICNAME, TRANSITIVE_BUNDLE_BY_VALUE).attribute(BUNDLE_MANIFESTVERSION, "2").attribute(EXPORT_PACKAGE, "p.q.r").attribute(BUNDLE_VERSION, "1.0.0").end();
    fout = new FileOutputStream(TRANSITIVE_BUNDLE_BY_VALUE + ".jar");
    bundle.writeOut(fout);
    fout.close();
    bundle = ArchiveFixture.newJar().manifest().attribute(BUNDLE_SYMBOLICNAME, TRANSITIVE_BUNDLE_BY_REFERENCE).attribute(BUNDLE_MANIFESTVERSION, "2").attribute(EXPORT_PACKAGE, "x.y.z").attribute(BUNDLE_VERSION, "1.0.0").end();
    fout = new FileOutputStream(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar");
    bundle.writeOut(fout);
    fout.close();
    bundle = ArchiveFixture.newJar().manifest().attribute(BUNDLE_SYMBOLICNAME, CORE_BUNDLE_BY_REFERENCE).attribute(BUNDLE_MANIFESTVERSION, "2").attribute(EXPORT_PACKAGE, "d.e.f").attribute(BUNDLE_VERSION, "1.0.0").end();
    fout = new FileOutputStream(CORE_BUNDLE_BY_REFERENCE + ".jar");
    bundle.writeOut(fout);
    fout.close();
    bundle = ArchiveFixture.newJar().manifest().attribute(BUNDLE_SYMBOLICNAME, CORE_BUNDLE_BY_REFERENCE).attribute(BUNDLE_MANIFESTVERSION, "2").attribute(EXPORT_PACKAGE, "d.e.f").end();
    fout = new FileOutputStream(CORE_BUNDLE_BY_REFERENCE + "_0.0.0.jar");
    bundle.writeOut(fout);
    fout.close();
    ZipFixture testEba = ArchiveFixture.newZip().binary("META-INF/APPLICATION.MF", OBRResolverTest.class.getClassLoader().getResourceAsStream("obr/APPLICATION.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("blog.eba");
    testEba.writeOut(fout);
    fout.close();
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 4 with ZipFixture

use of org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture 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();
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) RichBundleContext(org.apache.aries.itest.RichBundleContext) URLStreamHandlerService(org.osgi.service.url.URLStreamHandlerService) MavenArtifactProvisionOption(org.ops4j.pax.exam.options.MavenArtifactProvisionOption) URL(java.net.URL) Before(org.junit.Before)

Example 5 with ZipFixture

use of org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture in project aries by apache.

the class BasicAppManagerTest method createApplications.

@Before
public void createApplications() throws Exception {
    if (createdApplications) {
        return;
    }
    ZipFixture testEba = ArchiveFixture.newZip().jar("sample.jar").manifest().symbolicName("org.apache.aries.sample").attribute("Bundle-Version", "1.0.0").attribute("Import-Package", "org.apache.aries.sample").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();
    FileOutputStream fout = new FileOutputStream("test.eba");
    testEba.writeOut(fout);
    fout.close();
    ZipFixture testEba2 = testEba.binary("META-INF/APPLICATION.MF", BasicAppManagerTest.class.getClassLoader().getResourceAsStream("basic/APPLICATION.MF")).end();
    fout = new FileOutputStream("test2.eba");
    testEba2.writeOut(fout);
    fout.close();
    createdApplications = true;
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) FileOutputStream(java.io.FileOutputStream) Before(org.junit.Before)

Aggregations

ZipFixture (org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture)15 FileOutputStream (java.io.FileOutputStream)13 Before (org.junit.Before)9 File (java.io.File)6 FileInputStream (java.io.FileInputStream)4 BufferedReader (java.io.BufferedReader)2 FileWriter (java.io.FileWriter)2 InputStreamReader (java.io.InputStreamReader)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)1 RichBundleContext (org.apache.aries.itest.RichBundleContext)1 IDirectory (org.apache.aries.util.filesystem.IDirectory)1 MavenArtifactProvisionOption (org.ops4j.pax.exam.options.MavenArtifactProvisionOption)1 BundleException (org.osgi.framework.BundleException)1