Search in sources :

Example 1 with ClassLoaderManager

use of nl.nn.adapterframework.configuration.ClassLoaderManager in project iaf by ibissource.

the class DatabaseClassLoaderTest method testExceptionHandlingERROR.

/**
 * This test makes sure that when the config can't be found, it throws an ConfigurationException
 * @throws Exception
 */
@Test
public void testExceptionHandlingERROR() throws Exception {
    mockDatabase(true);
    appConstants.put("configurations." + getConfigurationName() + ".reportLevel", "ERROR");
    ClassLoaderManager manager = new ClassLoaderManager(ibisContext);
    ClassLoader config = null;
    boolean makeSureAnExceptionIsThrown = false;
    try {
        config = manager.get(getConfigurationName());
    } catch (ClassLoaderException e) {
        String msg = e.getMessage();
        assertTrue(msg.startsWith("Could not get config"));
        assertTrue(msg.endsWith("from database"));
        makeSureAnExceptionIsThrown = true;
    } finally {
        assertNull(config);
        assertTrue(makeSureAnExceptionIsThrown);
    }
}
Also used : ClassLoaderException(nl.nn.adapterframework.configuration.ClassLoaderException) ClassLoaderManager(nl.nn.adapterframework.configuration.ClassLoaderManager) Test(org.junit.Test)

Example 2 with ClassLoaderManager

use of nl.nn.adapterframework.configuration.ClassLoaderManager in project iaf by ibissource.

the class DatabaseClassLoaderTest method testExceptionHandlingWARN.

/**
 * This test makes sure that when the config can't be found, it only throws a WARN error in the log4j logger
 * @throws Exception
 */
@Test
public void testExceptionHandlingWARN() throws Exception {
    TestAppender appender = TestAppender.newBuilder().build();
    TestAppender.addToRootLogger(appender);
    boolean makeSureNoExceptionIsThrown = false;
    try {
        mockDatabase(true);
        appConstants.put("configurations." + getConfigurationName() + ".reportLevel", "WARN");
        ClassLoaderManager manager = new ClassLoaderManager(ibisContext);
        // Does not throw an exception
        ClassLoader config = manager.get(getConfigurationName());
        makeSureNoExceptionIsThrown = true;
        assertNull(config);
    } finally {
        TestAppender.removeAppender(appender);
        assertTrue(makeSureNoExceptionIsThrown);
    }
    List<LogEvent> log = appender.getLogEvents();
    LogEvent firstLogEntry = log.get(log.size() - 1);
    assertEquals(ClassLoaderManager.class.getCanonicalName(), firstLogEntry.getLoggerName());
    assertEquals(Level.WARN, firstLogEntry.getLevel());
    String msg = firstLogEntry.getMessage().getFormattedMessage();
    assertThat(msg, Matchers.startsWith(ERROR_PREFIX));
    assertThat(msg, Matchers.endsWith(ERROR_SUFFIX));
}
Also used : TestAppender(nl.nn.adapterframework.testutil.TestAppender) LogEvent(org.apache.logging.log4j.core.LogEvent) ClassLoaderManager(nl.nn.adapterframework.configuration.ClassLoaderManager) Test(org.junit.Test)

Example 3 with ClassLoaderManager

use of nl.nn.adapterframework.configuration.ClassLoaderManager in project iaf by ibissource.

the class DatabaseClassLoaderTest method testExceptionHandlingDEBUG.

/**
 * This test makes sure that when the config can't be found, it only throws a DEBUG error in the log4j logger
 * @throws Exception
 */
@Test
public void testExceptionHandlingDEBUG() throws Exception {
    TestAppender appender = TestAppender.newBuilder().build();
    TestAppender.addToRootLogger(appender);
    boolean makeSureNoExceptionIsThrown = false;
    try {
        mockDatabase(true);
        appConstants.put("configurations." + getConfigurationName() + ".reportLevel", "DEBUG");
        ClassLoaderManager manager = new ClassLoaderManager(ibisContext);
        // Does not throw an exception
        ClassLoader config = manager.get(getConfigurationName());
        makeSureNoExceptionIsThrown = true;
        assertNull(config);
    } finally {
        TestAppender.removeAppender(appender);
    }
    assertTrue(makeSureNoExceptionIsThrown);
    List<LogEvent> log = appender.getLogEvents();
    LogEvent firstLogEntry = log.get(log.size() - 1);
    assertEquals(ClassLoaderManager.class.getCanonicalName(), firstLogEntry.getLoggerName());
    assertEquals(Level.DEBUG, firstLogEntry.getLevel());
    String msg = firstLogEntry.getMessage().getFormattedMessage();
    assertThat(msg, Matchers.startsWith(ERROR_PREFIX));
    assertThat(msg, Matchers.endsWith(ERROR_SUFFIX));
}
Also used : TestAppender(nl.nn.adapterframework.testutil.TestAppender) LogEvent(org.apache.logging.log4j.core.LogEvent) ClassLoaderManager(nl.nn.adapterframework.configuration.ClassLoaderManager) Test(org.junit.Test)

Example 4 with ClassLoaderManager

use of nl.nn.adapterframework.configuration.ClassLoaderManager in project iaf by ibissource.

the class DatabaseClassLoaderTest method testExceptionHandlingINFO.

/**
 * This test makes sure that when the config can't be found, it only throws an INFO error in the log4j logger
 * @throws Exception
 */
@Test
public void testExceptionHandlingINFO() throws Exception {
    TestAppender appender = TestAppender.newBuilder().build();
    TestAppender.addToRootLogger(appender);
    boolean makeSureNoExceptionIsThrown = false;
    try {
        mockDatabase(true);
        appConstants.put("configurations." + getConfigurationName() + ".reportLevel", "INFO");
        ClassLoaderManager manager = new ClassLoaderManager(ibisContext);
        // Does not throw an exception
        ClassLoader config = manager.get(getConfigurationName());
        makeSureNoExceptionIsThrown = true;
        assertNull(config);
    } finally {
        TestAppender.removeAppender(appender);
    }
    assertTrue(makeSureNoExceptionIsThrown);
    List<LogEvent> log = appender.getLogEvents();
    LogEvent firstLogEntry = log.get(log.size() - 1);
    assertEquals(ApplicationMessageEvent.class.getCanonicalName(), firstLogEntry.getLoggerName());
    assertEquals(Level.INFO, firstLogEntry.getLevel());
    String msg = firstLogEntry.getMessage().getFormattedMessage();
    // Ignore the log4j prefix
    assertThat(msg, StringContains.containsString(ERROR_PREFIX));
    assertThat(msg, Matchers.endsWith(ERROR_SUFFIX));
}
Also used : TestAppender(nl.nn.adapterframework.testutil.TestAppender) LogEvent(org.apache.logging.log4j.core.LogEvent) ClassLoaderManager(nl.nn.adapterframework.configuration.ClassLoaderManager) ApplicationMessageEvent(nl.nn.adapterframework.lifecycle.ApplicationMessageEvent) Test(org.junit.Test)

Aggregations

ClassLoaderManager (nl.nn.adapterframework.configuration.ClassLoaderManager)4 Test (org.junit.Test)4 TestAppender (nl.nn.adapterframework.testutil.TestAppender)3 LogEvent (org.apache.logging.log4j.core.LogEvent)3 ClassLoaderException (nl.nn.adapterframework.configuration.ClassLoaderException)1 ApplicationMessageEvent (nl.nn.adapterframework.lifecycle.ApplicationMessageEvent)1