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);
}
}
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));
}
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));
}
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));
}
Aggregations