Search in sources :

Example 11 with ApplicationServiceException

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

the class ApplicationServiceImplTest method testStartApplicationASE.

/**
     * Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
     * for the case where an exception is thrown
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testStartApplicationASE() 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);
    Feature testFeature = mock(Feature.class);
    when(testFeature.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testApp.getAutoInstallFeatures()).thenReturn(new HashSet<>(Arrays.asList(testFeature)));
    doThrow(new ApplicationServiceException()).when(featuresService).installFeatures(anySet(), any(EnumSet.class));
    appService.startApplication(testApp);
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Repository(org.apache.karaf.features.Repository) EnumSet(java.util.EnumSet) FeaturesService(org.apache.karaf.features.FeaturesService) 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 12 with ApplicationServiceException

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

the class ApplicationServiceBeanTest method testStopApplicationException.

/**
     * Tests the {@link ApplicationServiceBean#stopApplication(String)} method for the case where
     * an exception is thrown
     *
     * @throws Exception
     */
@Test
public void testStopApplicationException() throws Exception {
    ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
    doThrow(new ApplicationServiceException()).when(testAppService).stopApplication(TEST_APP_NAME);
    assertFalse(serviceBean.stopApplication(TEST_APP_NAME));
    verify(testAppService).stopApplication(TEST_APP_NAME);
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Test(org.junit.Test)

Example 13 with ApplicationServiceException

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

the class ApplicationServiceBeanTest method testAddApplicationsASE.

/**
     * Tests the {@link ApplicationServiceBean#addApplications(List)} method
     * for the case where an ApplicationServiceException is thrown
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testAddApplicationsASE() 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);
    root.setLevel(Level.ALL);
    ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
    List<Map<String, Object>> testURLList = new ArrayList<>();
    Map<String, Object> testURLMap1 = mock(HashMap.class);
    when(testURLMap1.get("value")).thenReturn(TEST_URL);
    Map<String, Object> testURLMap2 = mock(HashMap.class);
    when(testURLMap2.get("value")).thenReturn(TEST_URL);
    testURLList.add(testURLMap1);
    testURLList.add(testURLMap2);
    doThrow(new ApplicationServiceException()).when(testAppService).addApplication(any(URI.class));
    serviceBean.addApplications(testURLList);
    verify(mockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(ADD_APP_ASE);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger) URI(java.net.URI) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ArgumentMatcher(org.mockito.ArgumentMatcher) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 14 with ApplicationServiceException

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

the class ApplicationServiceBeanTest method testGetServicesASE.

/**
     * Tests the {@link ApplicationServiceBean#getServices(String)} method
     * for the case where an ApplicationServiceException is thrown
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetServicesASE() 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);
    root.setLevel(Level.ALL);
    ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    Bundle testBundle = mock(Bundle.class);
    Bundle[] bundles = { testBundle };
    when(bundleContext.getBundles()).thenReturn(bundles);
    List<Map<String, Object>> services = new ArrayList<>();
    Map<String, Object> testService1 = new HashMap<>();
    services.add(testService1);
    doThrow(new ApplicationServiceException()).when(testApp).getBundles();
    when(testAppService.getApplication(TEST_APP_NAME)).thenReturn(testApp);
    when(testConfigAdminExt.listServices(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(services);
    serviceBean.getServices(TEST_APP_NAME);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(GET_SERV_ASE);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ArgumentMatcher(org.mockito.ArgumentMatcher) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 15 with ApplicationServiceException

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

the class ProfileInstallCommandTest method testExtraProfileInvalidAppInstall.

@Test(expected = ApplicationServiceException.class)
public void testExtraProfileInvalidAppInstall() throws Exception {
    profileInstallCommand.profileName = "invalidApp";
    doThrow(new ApplicationServiceException()).when(applicationService).startApplication("badApp");
    profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
    verify(applicationService, times(2)).startApplication(anyString());
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Test(org.junit.Test)

Aggregations

ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)27 Test (org.junit.Test)14 Application (org.codice.ddf.admin.application.service.Application)9 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)7 Logger (org.slf4j.Logger)7 Appender (ch.qos.logback.core.Appender)6 SecurityServiceException (ddf.security.service.SecurityServiceException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 URI (java.net.URI)6 ArgumentMatcher (org.mockito.ArgumentMatcher)6 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)6 File (java.io.File)5 HashSet (java.util.HashSet)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)3 Feature (org.apache.karaf.features.Feature)3 Repository (org.apache.karaf.features.Repository)3