use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationUninstallAllFeaturesException.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
* for the case where an exception is thrown within uninstallAllFeatures(Application)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationUninstallAllFeaturesException() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Application testApp = mock(ApplicationImpl.class);
Feature testFeature1 = mock(Feature.class);
Feature testFeature2 = mock(Feature.class);
Set<Feature> featureSet = new HashSet<>();
featureSet.add(testFeature1);
featureSet.add(testFeature2);
when(featuresService.isInstalled(any(Feature.class))).thenReturn(true);
when(testApp.getFeatures()).thenReturn(featureSet);
doThrow(new Exception()).when(featuresService).uninstallFeature(anyString(), anyString(), any(EnumSet.class));
appService.removeApplication(testApp);
verify(mockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(UNINSTALL_FAIL);
}
}));
}
use of org.codice.ddf.admin.application.service.ApplicationService 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());
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsUnknownWhenBundleStateServiceStateIsGracePeriod.
/**
* 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#GracePeriod} state and the rest of the
* bundles are in an {@link BundleState#Active} state.
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsUnknownWhenBundleStateServiceStateIsGracePeriod() throws Exception {
ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo2, BundleState.GracePeriod);
assertNotNull("Repository \"" + mainFeatureRepo2.getName() + "\" does not contain any bundles", appService);
assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.UNKNOWN, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
use of org.codice.ddf.admin.application.service.ApplicationService 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));
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedWhenBundleStateServiceStateIsInstalled.
/**
* 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#Installed} state and the rest of the
* bundles are in an {@link BundleState#Active} state.
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsFailedWhenBundleStateServiceStateIsInstalled() throws Exception {
ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo2, BundleState.Installed);
assertNotNull("Repository \"" + mainFeatureRepo2.getName() + "\" does not contain any bundles", appService);
assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Aggregations