Search in sources :

Example 1 with FeatureDetails

use of org.codice.ddf.admin.application.rest.model.FeatureDetails in project ddf by codice.

the class ApplicationServiceImplTest method testGetAllFeaturesFTRException.

/**
 * Tests the {@link ApplicationServiceImpl#getAllFeatures()} method for the case where an
 * exception is thrown in getFeatureToRepository(..)
 */
@Test
public void testGetAllFeaturesFTRException() throws Exception {
    Set<Repository> activeRepos = new HashSet<>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl(featuresService);
    doThrow(new NullPointerException()).when(featuresService).listRepositories();
    List<FeatureDetails> details = appService.getAllFeatures();
    assertThat("List of feature details should have 7 entries", details, hasSize(4));
    details.forEach(d -> assertThat(d.getName() + " should not have a mapped repository", d.getRepository(), is(nullValue())));
}
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 2 with FeatureDetails

use of org.codice.ddf.admin.application.rest.model.FeatureDetails in project ddf by codice.

the class ApplicationServiceBean method getFeatureMap.

private List<Map<String, Object>> getFeatureMap(List<FeatureDetails> featureViews) {
    List<Map<String, Object>> features = new ArrayList<>();
    for (FeatureDetails feature : featureViews) {
        Map<String, Object> featureMap = new HashMap<>();
        featureMap.put(MAP_NAME, feature.getName());
        featureMap.put(MAP_VERSION, feature.getVersion());
        featureMap.put(MAP_STATUS, feature.getStatus());
        featureMap.put(MAP_REPOSITORY, feature.getRepository());
        features.add(featureMap);
    }
    return features;
}
Also used : FeatureDetails(org.codice.ddf.admin.application.rest.model.FeatureDetails) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 3 with FeatureDetails

use of org.codice.ddf.admin.application.rest.model.FeatureDetails in project ddf by codice.

the class ApplicationServiceBeanTest method testFindApplicationFeatures.

/**
     * Tests the {@link ApplicationServiceBean#findApplicationFeatures(String)} method
     *
     * @throws Exception
     */
@Test
public void testFindApplicationFeatures() throws Exception {
    ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
    List<FeatureDetails> testFeatureDetailsList = new ArrayList<>();
    FeatureDetails testFeatureDetails1 = mock(FeatureDetails.class);
    testFeatureDetailsList.add(testFeatureDetails1);
    when(testFeatureDetails1.getName()).thenReturn(TEST_FEATURE_DETAILS);
    when(testFeatureDetails1.getVersion()).thenReturn(TEST_VERSION);
    when(testFeatureDetails1.getStatus()).thenReturn(TEST_FEATURE_STATUS);
    when(testFeatureDetails1.getRepository()).thenReturn(TEST_REPO_NAME);
    when(testAppService.findApplicationFeatures(TEST_APP_NAME)).thenReturn(testFeatureDetailsList);
    assertThat("Features returned should match testFeatureDetailsList features", (String) serviceBean.findApplicationFeatures(TEST_APP_NAME).get(0).get("name"), is(testFeatureDetailsList.get(0).getName()));
    verify(testAppService).findApplicationFeatures(TEST_APP_NAME);
}
Also used : FeatureDetails(org.codice.ddf.admin.application.rest.model.FeatureDetails) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with FeatureDetails

use of org.codice.ddf.admin.application.rest.model.FeatureDetails in project ddf by codice.

the class ApplicationServiceImplTest method testFindApplicationFeatures.

/**
     * Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
     *
     * @throws Exception
     */
@Test
public void testFindApplicationFeatures() 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 testFeature1 = mock(Feature.class);
    Feature[] featureList = { testFeature1 };
    Repository testRepo = mock(Repository.class);
    when(testFeature1.getRepositoryUrl()).thenReturn(TEST_REPO_URI);
    when(testRepo.getURI()).thenReturn(new URI(TEST_REPO_URI));
    when(testRepo.getFeatures()).thenReturn(featureList);
    Repository[] repositoryList = { testRepo };
    when(featuresService.getFeature(TEST_APP_NAME)).thenReturn(testFeature1);
    when(featuresService.listRepositories()).thenReturn(repositoryList);
    when(featuresService.isInstalled(testFeature1)).thenReturn(true);
    List<FeatureDetails> result = appService.findApplicationFeatures(TEST_APP_NAME);
    assertThat("Should return one feature.", result.size(), is(1));
}
Also used : Repository(org.apache.karaf.features.Repository) FeatureDetails(org.codice.ddf.admin.application.rest.model.FeatureDetails) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) URI(java.net.URI) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 5 with FeatureDetails

use of org.codice.ddf.admin.application.rest.model.FeatureDetails in project ddf by codice.

the class ApplicationServiceBeanTest method testGetAllFeatures.

/**
 * Tests the {@link ApplicationServiceBean#getAllFeatures()} method
 *
 * @throws Exception
 */
@Test
public void testGetAllFeatures() throws Exception {
    ApplicationServiceBean serviceBean = newApplicationServiceBean();
    List<FeatureDetails> testFeatureDetailsList = new ArrayList<>();
    FeatureDetails testFeatureDetails1 = mock(FeatureDetails.class);
    testFeatureDetailsList.add(testFeatureDetails1);
    when(testFeatureDetails1.getName()).thenReturn(TEST_FEATURE_DETAILS);
    when(testFeatureDetails1.getVersion()).thenReturn(TEST_VERSION);
    when(testFeatureDetails1.getStatus()).thenReturn(TEST_FEATURE_STATUS);
    when(testFeatureDetails1.getRepository()).thenReturn(TEST_REPO_NAME);
    when(testAppService.getAllFeatures()).thenReturn(testFeatureDetailsList);
    assertThat("Features returned should match testFeatureDetailsList features", (String) serviceBean.getAllFeatures().get(0).get("name"), is(testFeatureDetailsList.get(0).getName()));
    verify(testAppService).getAllFeatures();
}
Also used : FeatureDetails(org.codice.ddf.admin.application.rest.model.FeatureDetails) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

FeatureDetails (org.codice.ddf.admin.application.rest.model.FeatureDetails)6 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 FeaturesService (org.apache.karaf.features.FeaturesService)3 Repository (org.apache.karaf.features.Repository)3 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)3 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Feature (org.apache.karaf.features.Feature)1