Search in sources :

Example 11 with Configuration

use of org.candlepin.common.config.Configuration 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 12 with Configuration

use of org.candlepin.common.config.Configuration 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)

Example 13 with Configuration

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

the class CustomizableModulesTest method shouldFailWhenConfigurationContainsMissingClass.

// TODO: We should probably be more specific...
@Test(expected = RuntimeException.class)
public void shouldFailWhenConfigurationContainsMissingClass() throws Exception {
    Configuration config = new PropertiesFileConfiguration(getAbsolutePath("customizable_modules_with_missing_class.conf"));
    new CustomizableModules().load(config);
}
Also used : PropertiesFileConfiguration(org.candlepin.common.config.PropertiesFileConfiguration) Configuration(org.candlepin.common.config.Configuration) PropertiesFileConfiguration(org.candlepin.common.config.PropertiesFileConfiguration) Test(org.junit.Test)

Example 14 with Configuration

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

the class EventResourceTest method init.

@Before
public void init() {
    Configuration config = mock(Configuration.class);
    ec = mock(EventCurator.class);
    translator = mock(ModelTranslator.class);
    injector = Guice.createInjector(new TestingModules.MockJpaModule(), new TestingModules.StandardTest(config), new TestingModules.ServletEnvironmentModule());
}
Also used : Configuration(org.candlepin.common.config.Configuration) ModelTranslator(org.candlepin.dto.ModelTranslator) EventCurator(org.candlepin.model.EventCurator) Before(org.junit.Before)

Example 15 with Configuration

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

the class HypervisorResourceTest method setupTest.

@Before
public void setupTest() {
    Configuration config = new CandlepinCommonTestConfig();
    testMigration = new GuestMigration(consumerCurator);
    migrationProvider = Providers.of(testMigration);
    this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    this.hypervisorType = new ConsumerType(ConsumerTypeEnum.HYPERVISOR);
    this.hypervisorType.setId("test-hypervisor-ctype");
    this.mockConsumerType(this.hypervisorType);
    this.modelTranslator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
    this.consumerResource = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, this.subscriptionService, this.ownerService, null, this.idCertService, null, this.i18n, this.sink, this.eventFactory, null, null, this.userService, null, null, this.ownerCurator, this.activationKeyCurator, null, this.complianceRules, this.deletedConsumerCurator, null, null, config, null, null, null, this.consumerBindUtil, null, null, new FactValidator(config, this.i18n), null, consumerEnricher, migrationProvider, modelTranslator);
    this.guestIdResource = new GuestIdResource(this.guestIdCurator, this.consumerCurator, this.consumerTypeCurator, this.consumerResource, this.i18n, this.eventFactory, this.sink, migrationProvider, modelTranslator);
    this.hypervisorResource = new HypervisorResource(consumerResource, consumerCurator, consumerTypeCurator, i18n, ownerCurator, migrationProvider, modelTranslator, guestIdResource);
    // Ensure that we get the consumer that was passed in back from the create call.
    when(consumerCurator.create(any(Consumer.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[0];
        }
    });
    when(consumerCurator.create(any(Consumer.class), any(Boolean.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[0];
        }
    });
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class), any(Boolean.class))).thenReturn(new ComplianceStatus(new Date()));
    when(ownerCurator.lookupByKey(any(String.class))).thenReturn(new Owner());
    when(eventFactory.getEventBuilder(any(Target.class), any(Type.class))).thenReturn(consumerEventBuilder);
    when(consumerEventBuilder.setEventData(any(Consumer.class))).thenReturn(consumerEventBuilder);
}
Also used : FactValidator(org.candlepin.util.FactValidator) Owner(org.candlepin.model.Owner) Configuration(org.candlepin.common.config.Configuration) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) StandardTranslator(org.candlepin.dto.StandardTranslator) Date(java.util.Date) GuestMigration(org.candlepin.resource.util.GuestMigration) Target(org.candlepin.audit.Event.Target) Type(org.candlepin.audit.Event.Type) ConsumerType(org.candlepin.model.ConsumerType) Consumer(org.candlepin.model.Consumer) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConsumerType(org.candlepin.model.ConsumerType) Before(org.junit.Before)

Aggregations

Configuration (org.candlepin.common.config.Configuration)20 MapConfiguration (org.candlepin.common.config.MapConfiguration)9 Test (org.junit.Test)9 Before (org.junit.Before)7 JobDetail (org.quartz.JobDetail)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)3 JobCleaner (org.candlepin.pinsetter.tasks.JobCleaner)3 CronTrigger (org.quartz.CronTrigger)3 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ServletContext (javax.servlet.ServletContext)2 Target (org.candlepin.audit.Event.Target)2 Type (org.candlepin.audit.Event.Type)2 ConfigurationException (org.candlepin.common.config.ConfigurationException)2 PropertiesFileConfiguration (org.candlepin.common.config.PropertiesFileConfiguration)2 StandardTranslator (org.candlepin.dto.StandardTranslator)2 Consumer (org.candlepin.model.Consumer)2