Search in sources :

Example 21 with ApplicationServiceException

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

the class ApplicationServiceImplTest method testRemoveApplicationApplicationServiceException.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
     * for the case where an ApplicationServiceException is thrown within uninstallAllFeatures(..)
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationApplicationServiceException() 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 = createPermittedApplicationServiceImpl();
    Application testApp = mock(ApplicationImpl.class);
    doThrow(new ApplicationServiceException()).when(testApp).getFeatures();
    appService.removeApplication(testApp);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(UNINSTALL_ASE);
        }
    }));
}
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) 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 22 with ApplicationServiceException

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

the class TestApplicationService method dTestAppAddRemove.

@Test
public void dTestAppAddRemove() throws ApplicationServiceException {
    systemSubject.execute(() -> {
        ApplicationService applicationService = getServiceManager().getService(ApplicationService.class);
        Application sdkApp = applicationService.getApplication(SDK_APP);
        URI sdkUri = sdkApp.getURI();
        // Remove
        try {
            applicationService.removeApplication(sdkApp);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to remove {}: {}", sdkApp.getName(), e.getMessage());
            fail();
        }
        Set<Application> apps = applicationService.getApplications();
        assertThat(apps, not(hasItem(sdkApp)));
        // Add
        try {
            applicationService.addApplication(sdkUri);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to add {}: {}", sdkUri, e.getMessage());
            fail();
        }
        sdkApp = applicationService.getApplication(SDK_APP);
        assertThat(sdkApp.getName(), is(SDK_APP));
        assertThat(sdkApp.getURI(), is(sdkUri));
        ApplicationStatus status = applicationService.getApplicationStatus(sdkApp);
        assertThat(status.getState(), is(INACTIVE));
        apps = applicationService.getApplications();
        assertThat(apps, hasItem(sdkApp));
        // Test Commands
        // Remove
        String response = console.runCommand(REMOVE_COMMAND + SDK_APP);
        assertThat("Should be empty response after " + REMOVE_COMMAND, response, isEmptyString());
        response = console.runCommand(STATUS_COMMAND + SDK_APP);
        assertThat(SDK_APP + " should be not be found after " + REMOVE_COMMAND, response, containsString("No application found with name " + SDK_APP));
        // Add
        response = console.runCommand(ADD_COMMAND + sdkUri.toString());
        assertThat("Should be empty response after " + ADD_COMMAND, response, isEmptyString());
        response = console.runCommand(STATUS_COMMAND + SDK_APP);
        assertThat(SDK_APP + " should be INACTIVE after " + STATUS_COMMAND, response, containsString(INACTIVE_APP));
        try {
            applicationService.startApplication(SDK_APP);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to restart {}: {}", sdkUri, e.getMessage());
            fail();
        }
    });
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Application(org.codice.ddf.admin.application.service.Application) URI(java.net.URI) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest)

Example 23 with ApplicationServiceException

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

the class ApplicationServiceBeanTest method testRemoveApplicationASE.

/**
     * Tests the {@link ApplicationServiceBean#removeApplication(String)} method
     * for the case where an ApplicationServiceException is thrown by the AppService
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationASE() 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);
    doThrow(new ApplicationServiceException()).when(testAppService).removeApplication(any(String.class));
    serviceBean.removeApplication(TEST_APP_NAME);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

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

Example 24 with ApplicationServiceException

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

the class ApplicationServiceBeanTest method testStartApplicationException.

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

Example 25 with ApplicationServiceException

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

the class ApplicationFileInstaller method install.

/**
     * Installs the given application file to the system repository.
     *
     * @param application
     *            Application file to install.
     * @return A string URI that points to the main feature file for the
     *         application that was just installed.
     * @throws ApplicationServiceException
     *             If any errors occur while trying to install the application.
     */
public static URI install(File application) throws ApplicationServiceException {
    // Extract files to local repo
    ZipFile appZip = null;
    try {
        appZip = new ZipFile(application);
        if (isFileValid(appZip)) {
            LOGGER.debug("Installing {} to the system repository.", application.getAbsolutePath());
            String featureLocation = installToRepo(appZip);
            String uri = new File("").getAbsolutePath() + File.separator + REPO_LOCATION + featureLocation;
            // It fails on windows if we do not use.
            return Paths.get(uri).toUri();
        }
    } catch (ZipException ze) {
        LOGGER.warn("Got an error when trying to read the application as a zip file.", ze);
    } catch (IOException ioe) {
        LOGGER.warn("Got an error when trying to read the incoming application.", ioe);
    } finally {
        IOUtils.closeQuietly(appZip);
    }
    throw new ApplicationServiceException("Could not install application.");
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ZipFile(java.util.zip.ZipFile) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) File(java.io.File) ZipFile(java.util.zip.ZipFile)

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