Search in sources :

Example 6 with ZipFixture

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

the class BasicNoOpResolverTest 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)

Example 7 with ZipFixture

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

the class MinimumImportsTest method createApplications.

@Before
public void createApplications() throws Exception {
    if (createdApplications) {
        return;
    }
    // need to fake a application manager to export the service in order to pass the resolving for the client
    // In the real situation, we don't allow customers' bundles to explicitly import the runtime services.
    ZipFixture bundle = ArchiveFixture.newJar().manifest().attribute(Constants.BUNDLE_SYMBOLICNAME, fake_app_management).attribute(Constants.BUNDLE_MANIFESTVERSION, "2").attribute(Constants.BUNDLE_VERSION, "1.0.0").end();
    OutputStream out = new FileOutputStream(fake_app_management + ".jar");
    bundle.writeOut(out);
    out.close();
    ZipFixture testEba = ArchiveFixture.newZip().jar("org.apache.aries.application.itests.minimports.jar").manifest().symbolicName("org.apache.aries.application.itests.minimports").attribute("Bundle-Version", "1.0.0").attribute("Import-Package", "org.apache.aries.application.management").end().binary("org/apache/aries/application/sample/appmgrclient/AppMgrClient.class", MinimumImportsTest.class.getClassLoader().getResourceAsStream("org/apache/aries/application/sample/appmgrclient/AppMgrClient.class")).binary("OSGI-INF/blueprint/app-mgr-client.xml", MinimumImportsTest.class.getClassLoader().getResourceAsStream("app-mgr-client.xml")).end();
    FileOutputStream fout = new FileOutputStream("appmgrclienttest.eba");
    testEba.writeOut(fout);
    fout.close();
    StringBuilder repositoryXML = new StringBuilder();
    BufferedReader reader = new BufferedReader(new InputStreamReader(MinimumImportsTest.class.getResourceAsStream("/basic/fakeAppMgrServiceRepo.xml")));
    String line;
    while ((line = reader.readLine()) != null) {
        repositoryXML.append(line);
        repositoryXML.append("\r\n");
    }
    String repo = repositoryXML.toString().replaceAll("bundle_location", new File(fake_app_management + ".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) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileWriter(java.io.FileWriter) BufferedReader(java.io.BufferedReader) File(java.io.File) Before(org.junit.Before)

Example 8 with ZipFixture

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

the class FileUtilsTest method testGetBundlesRecursive.

/**
   * Make sure we get the bundles files recursively regardless of the file extension.
   * @throws IOException
   */
@Test
public void testGetBundlesRecursive() throws IOException {
    File tmpDir = new File("../src/test/resources/tmpJars");
    tmpDir.mkdirs();
    for (int n = 0; n < 2; n++) {
        ZipFixture bundle = ArchiveFixture.newJar().manifest().attribute(Constants.BUNDLE_SYMBOLICNAME, "aa" + n).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(new File(tmpDir.getAbsoluteFile(), "aa" + n + ((n == 0) ? ".jar" : ".war")));
        bundle.writeOut(fout);
        fout.close();
    }
    File subDir = new File(tmpDir, "subDir");
    subDir.mkdirs();
    for (int n = 0; n < 2; n++) {
        ZipFixture bundle = ArchiveFixture.newJar().manifest().attribute(Constants.BUNDLE_SYMBOLICNAME, "aa" + n).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(new File(subDir.getAbsoluteFile(), "aa" + n + ((n == 0) ? ".jar" : ".war")));
        bundle.writeOut(fout);
        fout.close();
    }
    for (int n = 0; n < 2; n++) {
        ZipFixture bundle = ArchiveFixture.newJar().manifest().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(new File(tmpDir, "bb" + n + ".jar"));
        bundle.writeOut(fout);
        fout.close();
    }
    IOUtils.writeOut(tmpDir, "simple.jar", new ByteArrayInputStream("abc".getBytes()));
    IOUtils.writeOut(tmpDir, "simple.war", new ByteArrayInputStream("sss".getBytes()));
    IOUtils.writeOut(tmpDir, "simple.txt", new ByteArrayInputStream("abc".getBytes()));
    IOUtils.writeOut(tmpDir, "some/relative/directory/complex.jar", new ByteArrayInputStream("def".getBytes()));
    IOUtils.writeOut(tmpDir, "some/relative/directory/aa/complex2.war", new ByteArrayInputStream("ghi".getBytes()));
    IOUtils.writeOut(tmpDir, "simple", new ByteArrayInputStream("abc".getBytes()));
    List<URI> jarFiles = FileUtils.getBundlesRecursive(tmpDir.toURI());
    assertEquals("There should be 4 entries.", 4, jarFiles.size());
    assertTrue("The entry should contain this aa0.jar", jarFiles.contains(new File(tmpDir, "aa0.jar").toURI()));
    assertTrue("The entry should contain this aa1.war", jarFiles.contains(new File(tmpDir, "aa1.war").toURI()));
    assertTrue("The entry should contain this aa0.jar", jarFiles.contains(new File(subDir, "aa0.jar").toURI()));
    assertTrue("The entry should contain this aa1.war", jarFiles.contains(new File(subDir, "aa1.war").toURI()));
    IOUtils.deleteRecursive(tmpDir);
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Example 9 with ZipFixture

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

the class UpdateAppTest method createApplications.

@Before
public void createApplications() throws Exception {
    if (createdApplications) {
        return;
    }
    ZipFixture testEba = ArchiveFixture.newZip().binary("META-INF/APPLICATION.MF", UpdateAppTest.class.getClassLoader().getResourceAsStream("isolated/APPLICATION.MF")).jar("sample.jar").manifest().symbolicName("org.apache.aries.isolated.sample").attribute("Bundle-Version", "1.0.0").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", UpdateAppTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", UpdateAppTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("OSGI-INF/blueprint/aries.xml", UpdateAppTest.class.getClassLoader().getResourceAsStream("isolated/sample-blueprint.xml")).end();
    FileOutputStream fout = new FileOutputStream("test.eba");
    testEba.writeOut(fout);
    fout.close();
    ZipFixture sample2 = ArchiveFixture.newJar().manifest().symbolicName("org.apache.aries.isolated.sample").attribute("Bundle-Version", "2.0.0").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("OSGI-INF/blueprint/aries.xml", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/sample2-blueprint.xml")).end();
    fout = new FileOutputStream("sample_2.0.0.jar");
    sample2.writeOut(fout);
    fout.close();
    createdApplications = true;
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) FileOutputStream(java.io.FileOutputStream) Before(org.junit.Before)

Example 10 with ZipFixture

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

the class IsolatedRuntimeTest method createApplications.

@Before
public void createApplications() throws Exception {
    if (createdApplications) {
        return;
    }
    ZipFixture testEba = ArchiveFixture.newZip().jar("sample.jar").manifest().symbolicName("org.apache.aries.isolated.sample").attribute("Bundle-Version", "1.0.0").attribute("Import-Package", "org.osgi.service.blueprint, org.apache.aries.isolated.shared").attribute("Bundle-ActivationPolicy", "lazy").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("org/apache/aries/isolated/sample/SharedImpl.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/SharedImpl.class")).binary("OSGI-INF/blueprint/sample-blueprint.xml", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/sample-blueprint.xml")).end().jar("shared.jar").manifest().symbolicName("org.apache.aries.isolated.shared").attribute("Bundle-Version", "1.0.0").attribute("Export-Package", "org.apache.aries.isolated.shared").end().binary("org/apache/aries/isolated/shared/Shared.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/shared/Shared.class")).end();
    FileOutputStream fout = new FileOutputStream("test.eba");
    testEba.writeOut(fout);
    fout.close();
    ZipFixture testEba2 = testEba.binary("META-INF/APPLICATION.MF", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/APPLICATION.MF")).end();
    fout = new FileOutputStream("test2.eba");
    testEba2.writeOut(fout);
    fout.close();
    ZipFixture sampleJar2 = ArchiveFixture.newJar().manifest().symbolicName("org.apache.aries.isolated.sample").attribute("Bundle-Version", "2.0.0").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("OSGI-INF/blueprint/aries.xml", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/sample2-blueprint.xml")).end();
    fout = new FileOutputStream("sample_2.0.0.jar");
    sampleJar2.writeOut(fout);
    fout.close();
    ZipFixture ebaWithFragment = ArchiveFixture.newZip().jar("sample.jar").manifest().symbolicName("org.apache.aries.isolated.sample").attribute("Bundle-Version", "1.0.0").end().end().jar("fragment.jar").manifest().symbolicName("org.apache.aries.isolated.fragment").attribute("Bundle-Version", "1.0.0").attribute("Fragment-Host", "org.apache.aries.isolated.sample").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("OSGI-INF/blueprint/sample-blueprint.xml", IsolatedRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/sample-blueprint.xml")).end();
    fout = new FileOutputStream("withFragment.eba");
    ebaWithFragment.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