Search in sources :

Example 51 with Repository

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));
}
Also used : Repository(org.apache.karaf.features.Repository) ArrayList(java.util.ArrayList) FeaturesService(org.apache.karaf.features.FeaturesService) Dependency(org.apache.karaf.features.Dependency) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 52 with Repository

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("");
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 53 with Repository

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"));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Mockito.anyString(org.mockito.Mockito.anyString) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 54 with Repository

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));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) URI(java.net.URI) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 55 with Repository

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);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Repository(org.apache.karaf.features.Repository) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Aggregations

Repository (org.apache.karaf.features.Repository)70 HashSet (java.util.HashSet)49 Test (org.junit.Test)46 FeaturesService (org.apache.karaf.features.FeaturesService)43 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)37 Feature (org.apache.karaf.features.Feature)31 Application (org.codice.ddf.admin.application.service.Application)21 URI (java.net.URI)15 Appender (ch.qos.logback.core.Appender)9 ArrayList (java.util.ArrayList)9 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)9 ArgumentMatcher (org.mockito.ArgumentMatcher)9 Logger (org.slf4j.Logger)9 Mockito.anyString (org.mockito.Mockito.anyString)8 IOException (java.io.IOException)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 BundleInfo (org.apache.karaf.features.BundleInfo)4 EnumSet (java.util.EnumSet)3 HashMap (java.util.HashMap)3