Search in sources :

Example 11 with FeaturesService

use of org.apache.karaf.features.FeaturesService in project ddf by codice.

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedWhenBundleStateServiceStatesIncludeActiveResolvedAndFailure.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#FAILED} is returned when the
     * extended bundle state reported by an injection framework states that one
     * bundle is in an {@link BundleState#Resolved} state, one bundle is in an
     * {@link BundleState#Installed} state and the rest of the bundles are in an
     * {@link BundleState#Active} state. This simulates a condition wherein the
     * {@code getApplicationStatus} method must discern between conditions that,
     * independent of each other, would produce
     * {@code ApplicationState#INACTIVE}, {@code ApplicationState#FAILED}, or
     * {@code ApplicationState#ACTIVE} states, respectively, and determine which
     * state to return for the overall Application.
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsFailedWhenBundleStateServiceStatesIncludeActiveResolvedAndFailure() throws Exception {
    FeaturesService featuresService = createMockFeaturesService(noMainFeatureRepo1, null, null);
    Set<Bundle> bundleSet = getXBundlesFromFeaturesService(featuresService, 2);
    assertNotNull(noMainFeatureRepo1.getName() + " does not contain 2 bundles", bundleSet);
    Bundle[] bundles = bundleSet.toArray(new Bundle[] {});
    when(bundleStateServices.get(0).getState(bundles[0])).thenReturn(BundleState.Resolved);
    when(bundleStateServices.get(0).getState(bundles[1])).thenReturn(BundleState.Failure);
    ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(noMainFeatureRepo1, BundleState.Failure);
    assertNotNull("Repository \"" + noMainFeatureRepo1.getName() + "\" does not contain any bundles", appService);
    assertEquals(noMainFeatureRepo1.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : Bundle(org.osgi.framework.Bundle) FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 12 with FeaturesService

use of org.apache.karaf.features.FeaturesService in project ddf by codice.

the class ApplicationServiceImplTest method testRemoveApplicationStringParam.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(String)} method
     *
     * @throws Exception
     */
@Test
public void testRemoveApplicationStringParam() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Feature[] featureList = mainFeatureRepo.getFeatures();
    appService.removeApplication(TEST_APP);
    verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
    verify(featuresService).uninstallFeature(featureList[1].getName(), featureList[1].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 13 with FeaturesService

use of org.apache.karaf.features.FeaturesService in project ddf by codice.

the class ApplicationServiceImplTest method testIsApplicationStartedReturnsFalseForInactiveApplicationState.

/**
     * Test method for
     * {@link ApplicationServiceImpl#isApplicationStarted(Application)}
     * <p>
     * Verifies that method returns false when application state is
     * {@link ApplicationState#INACTIVE}
     *
     * @throws Exception
     */
@Test
public void testIsApplicationStartedReturnsFalseForInactiveApplicationState() throws Exception {
    Set<String> notInstalledFeatures = new HashSet<String>();
    notInstalledFeatures.add(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME);
    FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, notInstalledFeatures, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertFalse(appService.isApplicationStarted(appService.getApplication(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME)));
}
Also used : FeaturesService(org.apache.karaf.features.FeaturesService) Mockito.anyString(org.mockito.Mockito.anyString) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 14 with FeaturesService

use of org.apache.karaf.features.FeaturesService in project ddf by codice.

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenMainFeatureNotInstalledAndAllBundlesActive.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#INACTIVE} is returned when an
     * {@code Application}'s main feature is not installed, but all of its
     * {@code Bundle}s states and extended states are {@code Bundle#ACTIVE} and
     * {@code BundleState#Active}, respectively.
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsInactiveWhenMainFeatureNotInstalledAndAllBundlesActive() throws Exception {
    Set<String> notInstalledFeatures = new HashSet<String>();
    notInstalledFeatures.add(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME);
    FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, notInstalledFeatures, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertEquals("More than one application was returned from mainFeatureRepo", 1, appService.getApplications().size());
    assertEquals("mainFeatureRepo returned unexpected state", ApplicationState.INACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : FeaturesService(org.apache.karaf.features.FeaturesService) Mockito.anyString(org.mockito.Mockito.anyString) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 15 with FeaturesService

use of org.apache.karaf.features.FeaturesService in project ddf by codice.

the class ApplicationServiceImplTest method testIgnoreApplications.

/**
     * Tests that the service properly ignores applications when checking for
     * application status.
     *
     * @throws Exception
     */
@Test
public void testIgnoreApplications() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(noMainFeatureRepo1, noMainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationServiceImpl appService = createPermittedApplicationServiceImpl();
    // just ignore the first application
    List<String> ignoredApps1 = new ArrayList<>(1);
    ignoredApps1.add(TEST_APP);
    appService.setIgnoredApplications(ignoredApps1);
    Set<Application> applications = appService.getApplications();
    assertNotNull(applications);
    assertEquals(1, applications.size());
    assertEquals(TEST_APP2, applications.iterator().next().getName());
    // now ignore both applications
    List<String> ignoredApps2 = new ArrayList<>(2);
    ignoredApps2.add(TEST_APP);
    ignoredApps2.add(TEST_APP2);
    appService.setIgnoredApplications(ignoredApps2);
    applications = appService.getApplications();
    assertNotNull(applications);
    assertEquals(0, applications.size());
    // ignore none
    List<String> ignoredApps3 = new ArrayList<>(0);
    appService.setIgnoredApplications(ignoredApps3);
    applications = appService.getApplications();
    assertNotNull(applications);
    assertEquals(2, applications.size());
}
Also used : Repository(org.apache.karaf.features.Repository) ArrayList(java.util.ArrayList) FeaturesService(org.apache.karaf.features.FeaturesService) Mockito.anyString(org.mockito.Mockito.anyString) Application(org.codice.ddf.admin.application.service.Application) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FeaturesService (org.apache.karaf.features.FeaturesService)71 Test (org.junit.Test)61 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)51 HashSet (java.util.HashSet)48 Repository (org.apache.karaf.features.Repository)43 Feature (org.apache.karaf.features.Feature)29 Application (org.codice.ddf.admin.application.service.Application)19 Mockito.anyString (org.mockito.Mockito.anyString)13 Logger (org.slf4j.Logger)12 Appender (ch.qos.logback.core.Appender)10 URI (java.net.URI)10 ArgumentMatcher (org.mockito.ArgumentMatcher)10 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)9 EnumSet (java.util.EnumSet)6 Bundle (org.osgi.framework.Bundle)6 URL (java.net.URL)5 ArrayList (java.util.ArrayList)4 BundleInfo (org.apache.karaf.features.BundleInfo)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2