Search in sources :

Example 51 with ArgumentMatcher

use of org.mockito.ArgumentMatcher 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 52 with ArgumentMatcher

use of org.mockito.ArgumentMatcher in project ddf by codice.

the class ApplicationConfigInstallerTest method testRunConfigFileNotExist.

/**
     * Tests the {@link ApplicationConfigInstaller#run()} method for the case
     * where the configFile doesn't exist
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunConfigFileNotExist() 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);
    ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(BAD_FILE, null, null, START_FEATURE, STOP_FEATURE);
    configInstaller.run();
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

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

Example 53 with ArgumentMatcher

use of org.mockito.ArgumentMatcher in project ddf by codice.

the class ApplicationFileInstallerTest method testInstall.

/**
     * Tests the {@link ApplicationFileInstaller#install(File)} method
     *
     * @Throws Exception
     */
@Test
public void testInstall() throws Exception {
    ApplicationFileInstaller testInstaller = new ApplicationFileInstaller();
    File testFile = new File(File.class.getResource(TEST_FILE_NAME).getPath());
    URI appResource = ApplicationFileInstaller.install(testFile);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(IOEX_STRING);
        }
    }));
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Example 54 with ArgumentMatcher

use of org.mockito.ArgumentMatcher in project ddf by codice.

the class ApplicationFileInstallerTest method testInstallInvalidZip.

/**
     * Tests the {@link ApplicationFileInstaller#install(File)} method
     * for the case where the file given is not a valid zip file
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testInstallInvalidZip() throws Exception {
    ApplicationFileInstaller testInstaller = new ApplicationFileInstaller();
    File testFile = new File(File.class.getResource(BAD_FILE_NAME).getPath());
    testInstaller.install(testFile);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(INVALID_ZIP_STRING);
        }
    }));
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) File(java.io.File) Test(org.junit.Test)

Example 55 with ArgumentMatcher

use of org.mockito.ArgumentMatcher in project hadoop by apache.

the class TestRMAppAttemptTransitions method testAppAttemptSubmittedToFailedState.

/**
   * {@link RMAppAttemptState#SUBMITTED} -> {@link RMAppAttemptState#FAILED}
   */
private void testAppAttemptSubmittedToFailedState(String diagnostics) {
    sendAttemptUpdateSavedEvent(applicationAttempt);
    assertEquals(RMAppAttemptState.FAILED, applicationAttempt.getAppAttemptState());
    assertEquals(diagnostics, applicationAttempt.getDiagnostics());
    assertEquals(0, applicationAttempt.getJustFinishedContainers().size());
    assertNull(applicationAttempt.getMasterContainer());
    assertEquals(0.0, (double) applicationAttempt.getProgress(), 0.0001);
    assertEquals(0, application.getRanNodes().size());
    assertNull(applicationAttempt.getFinalApplicationStatus());
    // Check events
    verify(masterService).unregisterAttempt(applicationAttempt.getAppAttemptId());
    // ATTEMPT_FAILED should be notified to app if app attempt is submitted to
    // failed state.
    ArgumentMatcher<RMAppEvent> matcher = new ArgumentMatcher<RMAppEvent>() {

        @Override
        public boolean matches(Object o) {
            RMAppEvent event = (RMAppEvent) o;
            return event.getType() == RMAppEventType.ATTEMPT_FAILED;
        }
    };
    verify(application).handle(argThat(matcher));
    verifyTokenCount(applicationAttempt.getAppAttemptId(), 1);
    verifyApplicationAttemptFinished(RMAppAttemptState.FAILED);
}
Also used : RMAppEvent(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppEvent) ArgumentMatcher(org.mockito.ArgumentMatcher)

Aggregations

ArgumentMatcher (org.mockito.ArgumentMatcher)104 Test (org.junit.Test)82 Appender (ch.qos.logback.core.Appender)23 Logger (org.slf4j.Logger)23 ArrayList (java.util.ArrayList)19 Context (android.content.Context)14 Channel (com.microsoft.azure.mobile.channel.Channel)13 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Intent (android.content.Intent)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)10 FeaturesService (org.apache.karaf.features.FeaturesService)10 ResolveInfo (android.content.pm.ResolveInfo)9 File (java.io.File)9 Repository (org.apache.karaf.features.Repository)9 Matchers.anyString (org.mockito.Matchers.anyString)9 UUID (java.util.UUID)8 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 Log (com.microsoft.azure.mobile.ingestion.models.Log)7