use of org.codice.ddf.admin.application.service.Application 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.Application 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());
}
use of org.codice.ddf.admin.application.service.Application in project ddf by codice.
the class ApplicationServiceImplTest method testStartApplicationASE.
/**
* Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
* for the case where an exception is thrown
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testStartApplicationASE() throws Exception {
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 = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Application testApp = mock(ApplicationImpl.class);
Feature testFeature = mock(Feature.class);
when(testFeature.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testApp.getAutoInstallFeatures()).thenReturn(new HashSet<>(Arrays.asList(testFeature)));
doThrow(new ApplicationServiceException()).when(featuresService).installFeatures(anySet(), any(EnumSet.class));
appService.startApplication(testApp);
}
use of org.codice.ddf.admin.application.service.Application in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplications.
/**
* Tests that the {@link ApplicationServiceImpl#getApplications()} method
* returns the correct number of applications.
*
* @throws Exception
*/
@Test
public void testGetApplications() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(noMainFeatureRepo1, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Set<Application> applications = appService.getApplications();
assertNotNull(applications);
assertEquals(2, applications.size());
}
use of org.codice.ddf.admin.application.service.Application in project ddf by codice.
the class ApplicationServiceImplTest method testFindFeatureExceptions.
/**
* Tests the {@link ApplicationServiceImpl#findFeature(Feature)} method
* for the case where exceptions are thrown inside findFeature(Feature, Set<Application>)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix and un-ignore
@Test
@Ignore
public void testFindFeatureExceptions() 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);
Application testApp = mock(ApplicationImpl.class);
final Set<Application> applicationSet = new HashSet<>();
applicationSet.add(testApp);
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
@Override
public Set<Application> getApplications() {
return applicationSet;
}
@Override
public boolean isPermittedToViewFeature(String featureName) {
return true;
}
};
Feature testFeature = mock(Feature.class);
doThrow(new NullPointerException()).when(testApp).getFeatures();
appService.findFeature(testFeature);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(FIND_FEAT_EX);
}
}));
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(FIND_FEAT_EX2);
}
}));
}
Aggregations