Search in sources :

Example 1 with FrameworkInstaller

use of org.apache.felix.fileinstall.plugins.installer.FrameworkInstaller in project felix by apache.

the class InstallerIntegrationTest method testAddRemoveBundles.

@Test
public void testAddRemoveBundles() throws Exception {
    // Precondition: no example bundles
    assertNull("example bundle already present - broken prior test?", findBundle("org.example.a"));
    assertNull("example bundle already present - broken prior test?", findBundle("org.example.b"));
    FrameworkInstaller installer = this.fwkInstallerTracker.getService();
    assertNotNull("installer service not found", installer);
    // Install bundles and check they were installed
    File fileA = new File(this.dataDir, "org.example.a.jar");
    File fileB = new File(this.dataDir, "org.example.b.jar");
    List<String> locations = Stream.of(fileA, fileB).map(File::toURI).map(URI::toString).collect(Collectors.toList());
    Object sponsor = new Object();
    List<Bundle> installed = installer.addLocations(sponsor, locations);
    assertEquals(2, installed.size());
    assertEquals("org.example.a", installed.get(0).getSymbolicName());
    assertEquals("org.example.b", installed.get(1).getSymbolicName());
    assertNotNull("example bundle not present after install", findBundle("org.example.a"));
    assertNotNull("example bundle not present after install", findBundle("org.example.b"));
    // Uninstall bundles and check they are gone
    Set<String> removed = installer.removeSponsor(sponsor).stream().map(Bundle::getSymbolicName).collect(Collectors.toSet());
    assertEquals(2, removed.size());
    assertTrue(removed.contains("org.example.a"));
    assertTrue(removed.contains("org.example.b"));
    assertNull("example bundle still present after uninstall", findBundle("org.example.a"));
    assertNull("example bundle still present after uninstall", findBundle("org.example.b"));
}
Also used : Bundle(org.osgi.framework.Bundle) FrameworkInstaller(org.apache.felix.fileinstall.plugins.installer.FrameworkInstaller) File(java.io.File) Test(org.junit.Test)

Example 2 with FrameworkInstaller

use of org.apache.felix.fileinstall.plugins.installer.FrameworkInstaller in project felix by apache.

the class InstallerIntegrationTest method testAddRemoveOverlappingBundles.

@Test
public void testAddRemoveOverlappingBundles() throws Exception {
    // Precondition: no example bundles
    assertNull("example bundle already present - broken prior test?", findBundle("org.example.a"));
    assertNull("example bundle already present - broken prior test?", findBundle("org.example.b"));
    assertNull("example bundle already present - broken prior test?", findBundle("org.example.c"));
    FrameworkInstaller installer = this.fwkInstallerTracker.getService();
    assertNotNull("installer service not found", installer);
    File fileA = new File(this.dataDir, "org.example.a.jar");
    File fileB = new File(this.dataDir, "org.example.b.jar");
    File fileC = new File(this.dataDir, "org.example.c.jar");
    // Install first set including A and B
    Object sponsor1 = new Object();
    List<String> locations1 = Stream.of(fileA, fileB).map(File::toURI).map(URI::toString).collect(Collectors.toList());
    List<Bundle> installed1 = installer.addLocations(sponsor1, locations1);
    assertEquals(2, installed1.size());
    assertEquals("org.example.a", installed1.get(0).getSymbolicName());
    assertEquals("org.example.b", installed1.get(1).getSymbolicName());
    assertNotNull("example bundle not present after install", findBundle("org.example.a"));
    assertNotNull("example bundle not present after install", findBundle("org.example.b"));
    assertNull("incorrect bundle installed", findBundle("org.example.c"));
    // Install second set including A and C
    Object sponsor2 = new Object();
    List<String> locations2 = Stream.of(fileA, fileC).map(File::toURI).map(URI::toString).collect(Collectors.toList());
    List<Bundle> installed2 = installer.addLocations(sponsor2, locations2);
    assertEquals(1, installed2.size());
    assertEquals("org.example.c", installed2.get(0).getSymbolicName());
    assertNotNull("example bundle not present after install", findBundle("org.example.a"));
    assertNotNull("example bundle not present after install", findBundle("org.example.b"));
    assertNotNull("example bundle not present after install", findBundle("org.example.c"));
    // Uninstall first set - bundle B should go away but not A
    Set<String> removed1 = installer.removeSponsor(sponsor1).stream().map(Bundle::getSymbolicName).collect(Collectors.toSet());
    assertEquals(1, removed1.size());
    assertTrue(removed1.contains("org.example.b"));
    assertNotNull("example bundle should still be present", findBundle("org.example.a"));
    assertNull("example bundle still present after uninstall", findBundle("org.example.b"));
    assertNotNull("example bundle should still be present", findBundle("org.example.c"));
    // Uninstall second set - all bundles should go away
    Set<String> removed2 = installer.removeSponsor(sponsor2).stream().map(Bundle::getSymbolicName).collect(Collectors.toSet());
    assertEquals(2, removed2.size());
    assertTrue(removed2.contains("org.example.a"));
    assertTrue(removed2.contains("org.example.c"));
    assertNull("example bundle still present after uninstall", findBundle("org.example.a"));
    assertNull("example bundle still present after uninstall", findBundle("org.example.b"));
    assertNull("example bundle still present after uninstall", findBundle("org.example.c"));
}
Also used : Bundle(org.osgi.framework.Bundle) FrameworkInstaller(org.apache.felix.fileinstall.plugins.installer.FrameworkInstaller) File(java.io.File) Test(org.junit.Test)

Example 3 with FrameworkInstaller

use of org.apache.felix.fileinstall.plugins.installer.FrameworkInstaller in project felix by apache.

the class InstallerIntegrationTest method testDontRemoveExistingBundle.

@Test
public void testDontRemoveExistingBundle() throws Exception {
    // Precondition: no example bundles
    assertNull("example bundle already present - broken prior test?", findBundle("org.example.a"));
    assertNull("example bundle already present - broken prior test?", findBundle("org.example.b"));
    FrameworkInstaller installer = this.fwkInstallerTracker.getService();
    assertNotNull("installer service not found", installer);
    Bundle existingBundle = findBundle("org.apache.felix.scr");
    assertNotNull("SCR bundle has been uninstalled -- broken prior test?", existingBundle);
    String locationA = new File(this.dataDir, "org.example.a.jar").toURI().toString();
    String locationB = new File(this.dataDir, "org.example.b.jar").toURI().toString();
    String existingLocation = existingBundle.getLocation();
    // Install set including A, B and SCR
    Object sponsor = new Object();
    List<String> locations = Arrays.asList(locationA, locationB, existingLocation);
    installer.addLocations(sponsor, locations);
    assertNotNull("example bundle not present after install", findBundle("org.example.a"));
    assertNotNull("example bundle not present after install", findBundle("org.example.b"));
    assertNotNull("preexisting bundle not present after install", findBundle("org.apache.felix.scr"));
    // Uninstall set - bundles A and B should go away but not SCR
    installer.removeSponsor(sponsor);
    assertNull("example bundle still present after uninstall", findBundle("org.example.a"));
    assertNull("example bundle still present after uninstall", findBundle("org.example.b"));
    assertNotNull("preexisting bundle uninstalled", findBundle("org.apache.felix.scr"));
}
Also used : Bundle(org.osgi.framework.Bundle) FrameworkInstaller(org.apache.felix.fileinstall.plugins.installer.FrameworkInstaller) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)3 FrameworkInstaller (org.apache.felix.fileinstall.plugins.installer.FrameworkInstaller)3 Test (org.junit.Test)3 Bundle (org.osgi.framework.Bundle)3