use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationMainFeature.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
* for the case where a main feature exists
*
* @throws Exception
*/
@Test
public void testStopApplicationMainFeature() 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 testApp1 = mock(ApplicationImpl.class);
Feature testFeature1 = mock(Feature.class);
Dependency testDependency1 = mock(Dependency.class);
List<Dependency> dependencyList1 = new ArrayList<>();
Set<Feature> featureSet1 = new HashSet<>();
dependencyList1.add(testDependency1);
featureSet1.add(testFeature1);
when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testApp1.getMainFeature()).thenReturn(testFeature1);
when(testApp1.getFeatures()).thenReturn(featureSet1);
when(featuresService.isInstalled(testFeature1)).thenReturn(true);
when(testFeature1.getDependencies()).thenReturn(dependencyList1);
when(testDependency1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
when(testFeature1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
appService.stopApplication(testApp1);
verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_1_NAME, TEST_FEATURE_VERSION, EnumSet.of(Option.NoAutoRefreshBundles));
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testStartApplicationStringParamASE.
/**
* Tests the {@link ApplicationServiceImpl#startApplication(String)} method
* for the case where the application cannot be found
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testStartApplicationStringParamASE() 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();
//Shouldn't find this
appService.startApplication("");
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testInstallProfileFeatures.
/**
* Tests install profile and make sure they load correctly.
*
* @throws Exception
*/
@Test
public void testInstallProfileFeatures() throws Exception {
Repository mainFeaturesRepo2 = createRepo(TEST_INSTALL_PROFILE_FILE_NAME);
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, mainFeaturesRepo2, noMainFeatureRepo1));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
List<Feature> profiles = appService.getInstallationProfiles();
assertNotNull(profiles);
assertEquals(2, profiles.size());
// Ensure order
Feature profile1 = profiles.get(0);
Feature profile2 = profiles.get(1);
assertEquals("profile-b-test1", profile1.getName());
assertEquals("Desc1", profile1.getDescription());
List<String> featureNames = getFeatureNames(profile1.getDependencies());
assertEquals(1, featureNames.size());
assertTrue(featureNames.contains("main-feature"));
assertEquals("profile-a-test2", profile2.getName());
assertEquals("Desc2", profile2.getDescription());
featureNames = getFeatureNames(profile2.getDependencies());
assertEquals(2, featureNames.size());
assertTrue(featureNames.contains("main-feature"));
assertTrue(featureNames.contains("main-feature2"));
}
use of org.apache.karaf.features.Repository 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.apache.karaf.features.Repository 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);
}
}));
}
Aggregations