use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testAddApplicationURIParam.
/**
* Tests the {@link ApplicationServiceImpl#addApplication(URI)} method
*
* @throws Exception
*/
@Test
public void testAddApplicationURIParam() 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 = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
URI testURI = ApplicationServiceImplTest.class.getClassLoader().getResource("test-kar.zip").toURI();
appService.addApplication(testURI);
verify(featuresService).addRepository(Mockito.any(URI.class), eq(false));
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testFindApplicationFeaturesGetRepoFeatException.
/**
* Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
* for the case where an exception is thrown in getRepositoryFeatures
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testFindApplicationFeaturesGetRepoFeatException() 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 = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Repository testRepo = mock(Repository.class);
Repository[] repoList = { testRepo };
when(featuresService.listRepositories()).thenReturn(repoList);
when(testRepo.getName()).thenReturn(TEST_APP_NAME);
doThrow(new Exception()).when(testRepo).getFeatures();
appService.findApplicationFeatures(TEST_APP_NAME);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(NO_REPO_FEATURES);
}
}));
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenBundleStateIsResolved.
/**
* Test method for
* {@link ApplicationServiceImpl#getApplicationStatus(Application)}
* <p>
* Verifies that {@link ApplicationState#INACTIVE} is returned when
* {@code Bundle} state is {@link Bundle#RESOLVED}
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsInactiveWhenBundleStateIsResolved() throws Exception {
ApplicationService appService = getAppServiceWithBundleInGivenState(mainFeatureRepo2, Bundle.RESOLVED);
assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.INACTIVE, 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 testRemoveApplicationApplicationParamASE.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
* for the case where an exception is thrown
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testRemoveApplicationApplicationParamASE() 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 = createPermittedApplicationServiceImpl();
Application testApp = mock(ApplicationImpl.class);
doThrow(new Exception()).when(featuresService).removeRepository(Mockito.any(URI.class), eq(false));
appService.removeApplication(testApp);
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenBundleStateServiceStateIsResolved.
/**
* Test method for
* {@link ApplicationServiceImpl#getApplicationStatus(Application)}
* <p>
* Verifies that {@link ApplicationState#INACTIVE} is returned when the
* extended bundle state reported by an injection framework states that one
* bundle is in a {@link BundleState#Resolved} state and the rest of the
* bundles are in a {@link BundleState#Active} state.
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsInactiveWhenBundleStateServiceStateIsResolved() throws Exception {
ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo2, BundleState.Resolved);
assertNotNull("Repository \"" + mainFeatureRepo.getName() + "\" does not contain any bundles", appService);
assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.INACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Aggregations