Search in sources :

Example 61 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testRemoveApplicationURIParam.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(URI)} method
     *
     * @throws Exception
     */
@Test
public void testRemoveApplicationURIParam() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Repository[] repoList = { mainFeatureRepo };
    URI testURL = mainFeatureRepo.getURI();
    Feature[] featureList = mainFeatureRepo.getFeatures();
    when(featuresService.listRepositories()).thenReturn(repoList);
    appService.removeApplication(testURL);
    verify(featuresService).removeRepository(testURL, false);
    verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
    verify(featuresService).uninstallFeature(featureList[1].getName(), featureList[1].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) URI(java.net.URI) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 62 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testStopApplicationMainFeatureStringParam.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(String)} method
     * for the case where a main feature exists
     *
     * @throws Exception
     */
@Test
public void testStopApplicationMainFeatureStringParam() 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();
    Feature[] featureList = mainFeatureRepo.getFeatures();
    appService.stopApplication(TEST_APP);
    verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 63 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testRemoveApplicationASE.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
     * for the case where an exception is thrown
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testRemoveApplicationASE() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, 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[] repoList = { mainFeatureRepo };
    URI testURL = mainFeatureRepo.getURI();
    when(featuresService.listRepositories()).thenReturn(repoList);
    doThrow(new Exception()).when(featuresService).removeRepository(Mockito.any(URI.class), eq(false));
    appService.removeApplication(testURL);
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) URI(java.net.URI) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 64 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testStartApplicationMainFeature.

/**
     * Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
     * for the case where there a main feature exists
     *
     * @throws Exception
     */
@Test
public void testStartApplicationMainFeature() 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);
    Set<Feature> features = new HashSet<>(Arrays.asList(testFeature));
    Set<String> featureNames = new HashSet<>(features.size());
    features.forEach(f -> featureNames.add(f.getName()));
    when(testApp.getAutoInstallFeatures()).thenReturn(features);
    appService.startApplication(testApp);
    verify(featuresService, atLeastOnce()).installFeatures(featureNames, EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Mockito.anyString(org.mockito.Mockito.anyString) 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 65 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testStopApplicationException.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
     * for the case where an Exception is thrown
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testStopApplicationException() 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);
    when(testApp.getMainFeature()).thenReturn(mainFeatureRepo.getFeatures()[1]);
    doThrow(new NullPointerException()).when(testApp).getFeatures();
    appService.stopApplication(testApp);
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Application(org.codice.ddf.admin.application.service.Application) 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