Search in sources :

Example 66 with Repository

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

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

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

the class ApplicationServiceImplTest method testAddApplicationASE.

/**
     * Tests the {@link ApplicationServiceImpl#addApplication(URI)} method
     * for the case where an exception is thrown
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testAddApplicationASE() 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();
    doThrow(new Exception()).when(featuresService).addRepository(Mockito.any(URI.class), eq(false));
    appService.addApplication(testURI);
}
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)

Example 69 with Repository

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

the class ApplicationImplTest method testBadRepoNoName.

// There is no known reason for creating an instance of ApplicationImpl if the repository
// has no name. Getting a repositories name or its features triggers the repository to be
// loaded from storage. If that fails, it throws an exception. An Application without features
// or a name is not useful.
@Ignore
@Test
public void testBadRepoNoName() throws Exception {
    Repository repo = mock(Repository.class);
    when(repo.getURI()).thenReturn(new URI(""));
    when(repo.getFeatures()).thenThrow(new RuntimeException("Testing Exceptions."));
    new ApplicationImpl(repo).getFeatures();
}
Also used : Repository(org.apache.karaf.features.Repository) URI(java.net.URI) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 70 with Repository

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

the class ApplicationNodeImplTest method testHashCode.

/**
     * Tests the {@link ApplicationNodeImpl#hashCode()} method
     */
@Test
public void testHashCode() {
    try {
        Repository testRepo = new RepositoryImpl(ApplicationNodeImpl.class.getClassLoader().getResource(FEATURES_FILE_NAME).toURI());
        Application testApp = new ApplicationImpl(testRepo);
        ApplicationNode testNode = new ApplicationNodeImpl(testApp);
        assertEquals(testApp.hashCode(), testNode.hashCode());
    } catch (Exception e) {
        LOGGER.info("Exception: ", e);
        fail();
    }
}
Also used : Repository(org.apache.karaf.features.Repository) RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) Test(org.junit.Test)

Aggregations

Repository (org.apache.karaf.features.Repository)70 HashSet (java.util.HashSet)49 Test (org.junit.Test)46 FeaturesService (org.apache.karaf.features.FeaturesService)43 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)37 Feature (org.apache.karaf.features.Feature)31 Application (org.codice.ddf.admin.application.service.Application)21 URI (java.net.URI)15 Appender (ch.qos.logback.core.Appender)9 ArrayList (java.util.ArrayList)9 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)9 ArgumentMatcher (org.mockito.ArgumentMatcher)9 Logger (org.slf4j.Logger)9 Mockito.anyString (org.mockito.Mockito.anyString)8 IOException (java.io.IOException)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 BundleInfo (org.apache.karaf.features.BundleInfo)4 EnumSet (java.util.EnumSet)3 HashMap (java.util.HashMap)3