Search in sources :

Example 61 with ApplicationService

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

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

Example 63 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenBundleStateIsResolved.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#INACTIVE} is returned when
     * {@code Bundle} state is {@link Bundle#RESOLVED}
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsInactiveWhenBundleStateIsResolved() throws Exception {
    ApplicationService appService = getAppServiceWithBundleInGivenState(mainFeatureRepo2, Bundle.RESOLVED);
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.INACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 64 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.

the class ApplicationServiceImplTest method testRemoveApplicationApplicationParamASE.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
     * for the case where an exception is thrown
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testRemoveApplicationApplicationParamASE() 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();
    Application testApp = mock(ApplicationImpl.class);
    doThrow(new Exception()).when(featuresService).removeRepository(Mockito.any(URI.class), eq(false));
    appService.removeApplication(testApp);
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Application(org.codice.ddf.admin.application.service.Application) 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 65 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenBundleStateServiceStateIsResolved.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#INACTIVE} is returned when the
     * extended bundle state reported by an injection framework states that one
     * bundle is in a {@link BundleState#Resolved} state and the rest of the
     * bundles are in a {@link BundleState#Active} state.
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsInactiveWhenBundleStateServiceStateIsResolved() throws Exception {
    ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo2, BundleState.Resolved);
    assertNotNull("Repository \"" + mainFeatureRepo.getName() + "\" does not contain any bundles", appService);
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.INACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : 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