Search in sources :

Example 46 with Application

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

Example 47 with Application

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

the class ApplicationServiceImplTest method testRemoveApplicationApplicationParam.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
     *
     * @throws Exception
     */
@Test
public void testRemoveApplicationApplicationParam() 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);
    Feature testFeature1 = mock(Feature.class);
    Feature testFeature2 = mock(Feature.class);
    Set<Feature> featureSet = new HashSet<>();
    featureSet.add(testFeature1);
    featureSet.add(testFeature2);
    featuresService.installFeature(testFeature1, EnumSet.noneOf(Option.class));
    featuresService.installFeature(testFeature2, EnumSet.noneOf(Option.class));
    when(testApp.getFeatures()).thenReturn(featureSet);
    when(featuresService.isInstalled(testFeature1)).thenReturn(true);
    when(featuresService.isInstalled(testFeature2)).thenReturn(true);
    when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testFeature1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
    when(testFeature2.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testFeature2.getVersion()).thenReturn(TEST_FEATURE_VERSION);
    when(testApp.getURI()).thenReturn(null);
    appService.removeApplication(testApp);
    verify(testApp).getURI();
    verify(featuresService, Mockito.times(2)).uninstallFeature(TEST_FEATURE_1_NAME, TEST_FEATURE_VERSION, EnumSet.of(Option.NoAutoRefreshBundles));
    verify(featuresService).removeRepository(null, false);
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Option(org.apache.karaf.features.FeaturesService.Option) 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 48 with Application

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

the class ApplicationImplTest method testNoMainFeature.

/**
     * Verifies if an app does NOT have a main feature that operations can still
     * be performed.
     *
     * @throws Exception
     */
@Test
public void testNoMainFeature() throws Exception {
    String mainFeatureVersion = "1.0.0";
    String mainFeatureDescription = null;
    String appToString = TEST_APP + " - " + mainFeatureVersion;
    RepositoryImpl repo = new RepositoryImpl(getClass().getClassLoader().getResource(FILE_NO_MAIN_FEATURES).toURI());
    repo.load();
    Application testApp = new ApplicationImpl(repo);
    assertEquals(TEST_APP, testApp.getName());
    assertEquals(mainFeatureVersion, testApp.getVersion());
    assertEquals(mainFeatureDescription, testApp.getDescription());
    assertNotNull(testApp.toString());
    assertEquals(appToString, testApp.toString());
    assertNull(testApp.getMainFeature());
}
Also used : RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) Application(org.codice.ddf.admin.application.service.Application) Test(org.junit.Test)

Example 49 with Application

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

the class ApplicationImplTest method testGetURI.

/**
     * Tests the {@link ApplicationImpl#getURI()} method
     *
     * @throws Exception
     */
@Test
public void testGetURI() throws Exception {
    URI testURI = getClass().getClassLoader().getResource(FILE_MAIN_FEATURE).toURI();
    RepositoryImpl repo1 = new RepositoryImpl(testURI);
    repo1.load();
    Application testApp1 = new ApplicationImpl(repo1);
    assertEquals(testURI, testApp1.getURI());
}
Also used : RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) URI(java.net.URI) Application(org.codice.ddf.admin.application.service.Application) Test(org.junit.Test)

Example 50 with Application

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

the class ApplicationNodeImplTest method testGetters.

/**
     * Tests the 'getters' to make sure that they return the correct values
     * after initialization and after setting the child and parent.
     */
@Test
public void testGetters() {
    Application testApp = mock(Application.class);
    when(testApp.getName()).thenReturn(APP_NAME);
    when(testApp.getVersion()).thenReturn(APP_VERSION);
    when(testApp.getDescription()).thenReturn(APP_DESCRIPTION);
    ApplicationNodeImpl testNode = new ApplicationNodeImpl(testApp);
    // initialization test
    assertTrue(testNode.getChildren().isEmpty());
    assertNull(testNode.getParent());
    assertEquals(testApp, testNode.getApplication());
    // test after setting child and parent
    Application testChildApp = mock(Application.class);
    when(testChildApp.getName()).thenReturn(APP2_NAME);
    when(testChildApp.getVersion()).thenReturn(APP2_VERSION);
    when(testChildApp.getDescription()).thenReturn(APP2_DESCRIPTION);
    ApplicationNodeImpl testChildNode = new ApplicationNodeImpl(testChildApp);
    testChildNode.setParent(testNode);
    testNode.getChildren().add(testChildNode);
    assertEquals(1, testNode.getChildren().size());
    assertEquals(testChildNode, testNode.getChildren().iterator().next());
    assertNotNull(testChildNode.getParent());
    assertEquals(testNode, testChildNode.getParent());
}
Also used : Application(org.codice.ddf.admin.application.service.Application) Test(org.junit.Test)

Aggregations

Application (org.codice.ddf.admin.application.service.Application)55 Test (org.junit.Test)43 HashSet (java.util.HashSet)28 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)26 Repository (org.apache.karaf.features.Repository)21 FeaturesService (org.apache.karaf.features.FeaturesService)19 Feature (org.apache.karaf.features.Feature)14 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)13 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)13 ApplicationNode (org.codice.ddf.admin.application.service.ApplicationNode)11 ArrayList (java.util.ArrayList)9 RepositoryImpl (org.apache.karaf.features.internal.service.RepositoryImpl)7 HashMap (java.util.HashMap)5 Logger (org.slf4j.Logger)5 Appender (ch.qos.logback.core.Appender)4 URI (java.net.URI)4 TreeSet (java.util.TreeSet)4 ArgumentMatcher (org.mockito.ArgumentMatcher)4 Mockito.anyString (org.mockito.Mockito.anyString)4 SecurityServiceException (ddf.security.service.SecurityServiceException)3