use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testFindFeature.
/**
* Tests the {@link ApplicationServiceImpl#findFeature(Feature)} method
*
* @throws Exception
*/
@Test
public void testFindFeature() 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 testFeature = mainFeatureRepo.getFeatures()[0];
Application result = appService.findFeature(testFeature);
assertTrue("Check that the returned application is the correct one.", result.getFeatures().contains(testFeature));
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedWhenBundleStateServiceStateIsFailure.
/**
* 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#Failure} state and the rest of the
* bundles are in an {@link BundleState#Active} state.
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsFailedWhenBundleStateServiceStateIsFailure() throws Exception {
ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo2, BundleState.Failure);
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());
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testStartApplicationNoMainFeature.
/**
* Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
* for the case where there is no main feature, but other features exist
*
* @throws Exception
*/
@Test
public void testStartApplicationNoMainFeature() 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 testFeature1 = mock(Feature.class);
Feature testFeature2 = mock(Feature.class);
Set<Feature> featureSet = new HashSet<Feature>();
featureSet.add(testFeature1);
featureSet.add(testFeature2);
when(testApp.getName()).thenReturn(TEST_APP_NAME);
when(testApp.getAutoInstallFeatures()).thenReturn(featureSet);
when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testFeature2.getName()).thenReturn(TEST_FEATURE_2_NAME);
Set<String> featureNames = new HashSet<>(featureSet.size());
featureSet.forEach(f -> featureNames.add(f.getName()));
appService.startApplication(testApp);
verify(featuresService).installFeatures(featureNames, EnumSet.of(Option.NoAutoRefreshBundles));
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedStatusWhenFeatureDependencyContainsInactiveBundle.
/**
* Test method for
* {@link ApplicationService#getApplicationStatus(Application)}
* <p>
* Verifies method returns an {@link ApplicationState#FAILED } state for an
* {@code Application} under the following conditions:
* <p>
* <ul>
* <li>Main feature is installed</li>
* <li>All dependency features are installed</li>
* <li>One dependency feature contains a Bundle that is in an inactive state
* </li>
* </ul>
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsFailedStatusWhenFeatureDependencyContainsInactiveBundle() throws Exception {
// Verify the pre-conditions
int bundleInclusionCount = 0;
for (Feature feature : mainFeatureRepo2.getFeatures()) {
for (BundleInfo bundleInfo : feature.getBundles()) {
if (bundleInfo.getLocation().equals(TEST_MAIN_FEATURES_2_UNIQUE_BUNDLE_LOCATION)) {
++bundleInclusionCount;
}
}
}
assertEquals("Bundle is not included in repository the expected number of times", 1, bundleInclusionCount);
// Execute test
Set<String> inactiveBundleNames = new HashSet<String>();
inactiveBundleNames.add(TEST_MAIN_FEATURES_2_UNIQUE_BUNDLE_LOCATION);
FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo2, null, inactiveBundleNames);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
assertEquals(ApplicationService.class.getName() + " does not contain the expected number of Applications", 1, appService.getApplications().size());
assertEquals(mainFeatureRepo2.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 testGetApplicationStatusReturnsUnknownWhenBundleStateServiceStateIsWaiting.
/**
* 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 an {@link BundleState#Waiting} state and the rest of the
* bundles are in an {@link BundleState#Active} state.
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsUnknownWhenBundleStateServiceStateIsWaiting() throws Exception {
ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo2, BundleState.Waiting);
assertNotNull("Repository \"" + mainFeatureRepo.getName() + "\" does not contain any bundles", appService);
assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.UNKNOWN, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Aggregations