Search in sources :

Example 11 with MapConfiguration

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

the class CertificateReaderTest method readkey.

@Test
public void readkey() throws Exception {
    Configuration config = new MapConfiguration(new HashMap<String, String>() {

        {
            put(ConfigProperties.CA_CERT, "target/test/resources/certs/test.crt");
            put(ConfigProperties.CA_CERT_UPSTREAM, "target/test/resources/certs/upstream");
            put(ConfigProperties.CA_KEY, "target/test/resources/keys/pkcs1-des-encrypted.pem");
            put(ConfigProperties.CA_KEY_PASSWORD, "password");
        }
    });
    new CertificateReader(config, new PrivateKeyReader());
}
Also used : MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) MapConfiguration(org.candlepin.common.config.MapConfiguration) PrivateKeyReader(org.candlepin.pki.PrivateKeyReader) CertificateReader(org.candlepin.pki.CertificateReader) Test(org.junit.Test)

Example 12 with MapConfiguration

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

the class LoggingConfiguratorTest method configure.

@Test
public void configure() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger l = context.getLogger(LoggingConfiguratorTest.class);
    assertNotNull(l);
    assertNull(l.getLevel());
    Map<String, String> logLevels = new HashMap<>();
    String key = ConfigurationPrefixes.LOGGING_CONFIG_PREFIX + LoggingConfiguratorTest.class.getName();
    logLevels.put(key, "DEBUG");
    LoggingConfigurator.init(new MapConfiguration(logLevels));
    assertNotNull(l.getLevel());
    assertEquals(Level.DEBUG, l.getLevel());
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 13 with MapConfiguration

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

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

the class ConsumerExporterTest method testConsumerExport.

@Test
public void testConsumerExport() throws IOException {
    ObjectMapper mapper = TestSyncUtils.getTestSyncUtils(new MapConfiguration(new HashMap<String, String>() {

        {
            put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false");
        }
    }));
    translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, ownerCurator);
    ConsumerExporter exporter = new ConsumerExporter(translator);
    ConsumerType ctype = new ConsumerType("candlepin");
    ctype.setId("8888");
    ctype.setManifest(true);
    StringWriter writer = new StringWriter();
    Consumer consumer = new Consumer();
    consumer.setUuid("test-uuid");
    consumer.setName("testy consumer");
    consumer.setType(ctype);
    consumer.setContentAccessMode("access_mode");
    when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    exporter.export(mapper, writer, consumer, "/subscriptions", "/candlepin");
    StringBuffer json = new StringBuffer();
    json.append("{\"uuid\":\"").append(consumer.getUuid()).append("\",");
    json.append("\"name\":\"").append(consumer.getName()).append("\",");
    json.append("\"type\":");
    json.append("{\"id\":\"").append(ctype.getId()).append("\",");
    json.append("\"label\":\"").append(ctype.getLabel()).append("\",");
    json.append("\"manifest\":").append(ctype.isManifest()).append("},");
    json.append("\"owner\":null,");
    json.append("\"urlWeb\":\"/subscriptions\",");
    json.append("\"urlApi\":\"/candlepin\",");
    json.append("\"contentAccessMode\":\"access_mode\"}");
    assertTrue(json.toString() + "\n" + writer.toString(), TestUtil.isJsonEqual(json.toString(), writer.toString()));
    // change sibling order to ensure that isJsonEqual can reconcile
    json = new StringBuffer();
    json.append("{\"uuid\":\"").append(consumer.getUuid()).append("\",");
    json.append("\"type\":");
    json.append("{\"id\":\"").append(ctype.getId()).append("\",");
    json.append("\"label\":\"").append(ctype.getLabel()).append("\",");
    json.append("\"manifest\":").append(ctype.isManifest()).append("},");
    json.append("\"owner\":null,");
    json.append("\"name\":\"").append(consumer.getName()).append("\",");
    json.append("\"urlApi\":\"/candlepin\",");
    json.append("\"urlWeb\":\"/subscriptions\",");
    json.append("\"contentAccessMode\":\"access_mode\"}");
    assertTrue(TestUtil.isJsonEqual(json.toString(), writer.toString()));
}
Also used : StringWriter(java.io.StringWriter) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) ConsumerType(org.candlepin.model.ConsumerType) StandardTranslator(org.candlepin.dto.StandardTranslator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 15 with MapConfiguration

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

the class ConsumerTypeExporterTest method testConsumerTypeExport.

@Test
public void testConsumerTypeExport() throws IOException {
    ObjectMapper mapper = TestSyncUtils.getTestSyncUtils(new MapConfiguration(new HashMap<String, String>() {

        {
            put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false");
        }
    }));
    translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, ownerCurator);
    ConsumerTypeExporter consumerType = new ConsumerTypeExporter(translator);
    StringWriter writer = new StringWriter();
    ConsumerType type = new ConsumerType("TESTTYPE");
    consumerType.export(mapper, writer, type);
    StringBuffer json = new StringBuffer();
    json.append("{\"id\":null,\"label\":\"TESTTYPE\",");
    json.append("\"manifest\":false}");
    assertTrue(TestUtil.isJsonEqual(json.toString(), writer.toString()));
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) ConsumerType(org.candlepin.model.ConsumerType) StandardTranslator(org.candlepin.dto.StandardTranslator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

MapConfiguration (org.candlepin.common.config.MapConfiguration)20 Test (org.junit.Test)16 HashMap (java.util.HashMap)15 JobCleaner (org.candlepin.pinsetter.tasks.JobCleaner)8 Configuration (org.candlepin.common.config.Configuration)7 JobDetail (org.quartz.JobDetail)7 HashSet (java.util.HashSet)6 CronTrigger (org.quartz.CronTrigger)6 JobKey (org.quartz.JobKey)6 JobStatus (org.candlepin.pinsetter.core.model.JobStatus)5 ImportRecordJob (org.candlepin.pinsetter.tasks.ImportRecordJob)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 StringWriter (java.io.StringWriter)4 StandardTranslator (org.candlepin.dto.StandardTranslator)4 Before (org.junit.Before)3 Trigger (org.quartz.Trigger)3 TriggerKey (org.quartz.TriggerKey)3 File (java.io.File)2 StringReader (java.io.StringReader)2 Date (java.util.Date)2