Search in sources :

Example 1 with ConfigurationException

use of org.candlepin.common.config.ConfigurationException in project candlepin by candlepin.

the class CandlepinContextListenerTest method tharSheBlows.

@Test(expected = RuntimeException.class)
public void tharSheBlows() {
    listener = new CandlepinContextListener() {

        protected List<Module> getModules(ServletContext context) {
            return new LinkedList<>();
        }

        protected Configuration readConfiguration(ServletContext context) throws ConfigurationException {
            throw new ConfigurationException("the ship is sinking");
        }
    };
    prepareForInitialization();
    listener.contextInitialized(evt);
}
Also used : MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) ConfigurationException(org.candlepin.common.config.ConfigurationException) ServletContext(javax.servlet.ServletContext) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test)

Example 2 with ConfigurationException

use of org.candlepin.common.config.ConfigurationException in project candlepin by candlepin.

the class CandlepinContextListenerTest method init.

@Before
public void init() {
    config = mock(Configuration.class);
    when(config.subset(eq("org.quartz"))).thenReturn(new MapConfiguration(ConfigProperties.DEFAULT_PROPERTIES));
    when(config.strippedSubset(eq(ConfigurationPrefixes.LOGGING_CONFIG_PREFIX))).thenReturn(new MapConfiguration());
    hqlistener = mock(ActiveMQContextListener.class);
    pinlistener = mock(PinsetterContextListener.class);
    buspublisher = mock(AMQPBusPublisher.class);
    executorService = mock(ScheduledExecutorService.class);
    configRead = mock(VerifyConfigRead.class);
    // for testing we override the getModules and readConfiguration methods
    // so we can insert our mock versions of listeners to verify
    // they are getting invoked properly.
    listener = new CandlepinContextListener() {

        @Override
        protected List<Module> getModules(ServletContext context) {
            List<Module> modules = new LinkedList<>();
            // tried simply overriding CandlepinModule
            // but that caused it to read the local config
            // which means the test becomes non-deterministic.
            // so just load the items we need to verify the
            // functionality.
            modules.add(new TestingModules.JpaModule());
            modules.add(new TestingModules.StandardTest(config));
            modules.add(new ContextListenerTestModule());
            return modules;
        }

        @Override
        protected Configuration readConfiguration(ServletContext context) throws ConfigurationException {
            configRead.verify(context);
            return config;
        }
    };
}
Also used : ActiveMQContextListener(org.candlepin.audit.ActiveMQContextListener) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) MapConfiguration(org.candlepin.common.config.MapConfiguration) AMQPBusPublisher(org.candlepin.audit.AMQPBusPublisher) PinsetterContextListener(org.candlepin.pinsetter.core.PinsetterContextListener) ConfigurationException(org.candlepin.common.config.ConfigurationException) ServletContext(javax.servlet.ServletContext) LinkedList(java.util.LinkedList) List(java.util.List) Before(org.junit.Before)

Aggregations

LinkedList (java.util.LinkedList)2 List (java.util.List)2 ServletContext (javax.servlet.ServletContext)2 Configuration (org.candlepin.common.config.Configuration)2 ConfigurationException (org.candlepin.common.config.ConfigurationException)2 MapConfiguration (org.candlepin.common.config.MapConfiguration)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AMQPBusPublisher (org.candlepin.audit.AMQPBusPublisher)1 ActiveMQContextListener (org.candlepin.audit.ActiveMQContextListener)1 PinsetterContextListener (org.candlepin.pinsetter.core.PinsetterContextListener)1 Before (org.junit.Before)1 Test (org.junit.Test)1