Search in sources :

Example 61 with FeaturesService

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

the class ApplicationServiceImplTest method getAppServiceWithBundleInGivenState.

/**
     * Returns an {@code ApplicationService} that contains one bundle in the
     * received bundle state and the rest of the bundles in an {code
     * Bundle#ACTIVE} state.
     *
     * @param repository  The {@link Repository} from which to build the
     *                    {@code ApplicationService}.
     * @param bundleState The state, as defined in the {@link Bundle} interface, to set
     *                    for one of the {@code Bundle}s in the
     *                    {@code ApplicationService}
     * @return An {@link ApplicationService} with one bundle set to the received
     * bundle state and the rest of the {@code Bundle}s set to the
     * {@link Bundle#ACTIVE} state
     * @throws Exception
     */
private ApplicationService getAppServiceWithBundleInGivenState(Repository repository, int bundleState) throws Exception {
    ApplicationService appService = null;
    FeaturesService featuresService = createMockFeaturesService(repository, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    Bundle bundle = getAnyBundleFromFeaturesService(featuresService);
    if (null != bundle) {
        when(bundle.getState()).thenReturn(bundleState);
        appService = createPermittedApplicationServiceImpl();
    }
    return appService;
}
Also used : Bundle(org.osgi.framework.Bundle) FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService)

Example 62 with FeaturesService

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

the class ApplicationServiceImplTest method testGetAllFeatures.

/**
     * Tests the {@link ApplicationServiceImpl#getAllFeatures()} method
     *
     * @throws Exception
     */
@Test
public void testGetAllFeatures() 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();
    List<FeatureDetails> result = appService.getAllFeatures();
    assertThat("Returned features should match features in mainFeatureRepo.", result.get(0).getName(), is(mainFeatureRepo.getFeatures()[0].getName()));
    assertThat("Returned features should match features in mainFeatureRepo.", result.get(0).getId(), is(mainFeatureRepo.getFeatures()[0].getId()));
    assertThat("Should return seven features.", result.size(), is(7));
}
Also used : Repository(org.apache.karaf.features.Repository) FeatureDetails(org.codice.ddf.admin.application.rest.model.FeatureDetails) FeaturesService(org.apache.karaf.features.FeaturesService) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 63 with FeaturesService

use of org.apache.karaf.features.FeaturesService 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 64 with FeaturesService

use of org.apache.karaf.features.FeaturesService 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 65 with FeaturesService

use of org.apache.karaf.features.FeaturesService 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)

Aggregations

FeaturesService (org.apache.karaf.features.FeaturesService)71 Test (org.junit.Test)61 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)51 HashSet (java.util.HashSet)48 Repository (org.apache.karaf.features.Repository)43 Feature (org.apache.karaf.features.Feature)29 Application (org.codice.ddf.admin.application.service.Application)19 Mockito.anyString (org.mockito.Mockito.anyString)13 Logger (org.slf4j.Logger)12 Appender (ch.qos.logback.core.Appender)10 URI (java.net.URI)10 ArgumentMatcher (org.mockito.ArgumentMatcher)10 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)9 EnumSet (java.util.EnumSet)6 Bundle (org.osgi.framework.Bundle)6 URL (java.net.URL)5 ArrayList (java.util.ArrayList)4 BundleInfo (org.apache.karaf.features.BundleInfo)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2