Search in sources :

Example 71 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService 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 72 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService 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 73 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService 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 74 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService 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 75 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService 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

ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)82 Test (org.junit.Test)79 FeaturesService (org.apache.karaf.features.FeaturesService)51 HashSet (java.util.HashSet)45 Repository (org.apache.karaf.features.Repository)37 Application (org.codice.ddf.admin.application.service.Application)26 Feature (org.apache.karaf.features.Feature)19 Logger (org.slf4j.Logger)14 Appender (ch.qos.logback.core.Appender)13 URI (java.net.URI)13 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)13 ArgumentMatcher (org.mockito.ArgumentMatcher)13 Mockito.anyString (org.mockito.Mockito.anyString)10 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)9 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 EnumSet (java.util.EnumSet)3 ApplicationNode (org.codice.ddf.admin.application.service.ApplicationNode)3 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)3 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)3