Search in sources :

Example 1 with MapConfiguration

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

the class ImporterTest method init.

@Before
public void init() throws URISyntaxException, IOException {
    mapper = TestSyncUtils.getTestSyncUtils(new MapConfiguration(new HashMap<String, String>() {

        {
            put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false");
        }
    }));
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    config = new CandlepinCommonTestConfig();
    pc = Mockito.mock(ProductCurator.class);
    ec = Mockito.mock(EntitlementCurator.class);
    this.environmentCurator = Mockito.mock(EnvironmentCurator.class);
    ProductCachedSerializationModule productCachedModule = new ProductCachedSerializationModule(pc);
    su = new SyncUtils(config, productCachedModule);
    PrintStream ps = new PrintStream(new File(this.getClass().getClassLoader().getResource("version.properties").toURI()));
    ps.println("version=0.0.3");
    ps.println("release=1");
    ps.close();
    mockJsPath = new File(folder.getRoot(), "empty.js").getPath();
    this.mockSubReconciler = Mockito.mock(SubscriptionReconciler.class);
    this.consumerTypeCurator = Mockito.mock(ConsumerTypeCurator.class);
    oc = mock(OwnerCurator.class);
    this.translator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.oc);
}
Also used : EntitlementCurator(org.candlepin.model.EntitlementCurator) PrintStream(java.io.PrintStream) ConsumerTypeCurator(org.candlepin.model.ConsumerTypeCurator) MapConfiguration(org.candlepin.common.config.MapConfiguration) StandardTranslator(org.candlepin.dto.StandardTranslator) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) OwnerCurator(org.candlepin.model.OwnerCurator) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) ProductCurator(org.candlepin.model.ProductCurator) EnvironmentCurator(org.candlepin.model.EnvironmentCurator) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Before(org.junit.Before)

Example 2 with MapConfiguration

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

the class ConsumerImporterTest method importFailsOnUnknownPropertiesWithNonDefaultConfig.

@Test(expected = JsonMappingException.class)
public void importFailsOnUnknownPropertiesWithNonDefaultConfig() throws Exception {
    // Override default config to error out on unknown properties:
    Map<String, String> configProps = new HashMap<>();
    configProps.put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "true");
    mapper = TestSyncUtils.getTestSyncUtils(new MapConfiguration(configProps));
    importer.createObject(mapper, new StringReader("{\"uuid\":\"test-uuid\", \"unknown\":\"notreal\"}"));
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 3 with MapConfiguration

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

the class ConsumerImporterTest method importHandlesUnknownPropertiesGracefully.

@Test
public void importHandlesUnknownPropertiesGracefully() throws Exception {
    // Override default config to error out on unknown properties:
    Map<String, String> configProps = new HashMap<>();
    configProps.put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false");
    mapper = TestSyncUtils.getTestSyncUtils(new MapConfiguration(configProps));
    ConsumerDTO consumer = importer.createObject(mapper, new StringReader("{\"uuid\":\"test-uuid\", \"unknown\":\"notreal\"}"));
    assertEquals("test-uuid", consumer.getUuid());
}
Also used : HashMap(java.util.HashMap) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) MapConfiguration(org.candlepin.common.config.MapConfiguration) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 4 with MapConfiguration

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

the class MetaExporterTest method testMetaExporter.

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

        {
            put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false");
        }
    }));
    MetaExporter metaEx = new MetaExporter();
    StringWriter writer = new StringWriter();
    Meta meta = new Meta();
    Date now = new Date();
    String nowString = mapper.convertValue(now, String.class);
    meta.setVersion("0.1.0");
    meta.setCreated(now);
    meta.setPrincipalName("myUsername");
    meta.setWebAppPrefix("webapp_prefix");
    meta.setCdnLabel("test-cdn");
    metaEx.export(mapper, writer, meta);
    StringBuffer json = new StringBuffer();
    json.append("{\"version\":\"0.1.0\",\"created\":\"").append(nowString);
    json.append("\",\"principalName\":\"myUsername\",");
    json.append("\"webAppPrefix\":\"webapp_prefix\",");
    json.append("\"cdnLabel\":\"test-cdn\"}");
    assertTrue(TestUtil.isJsonEqual(json.toString(), writer.toString()));
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date) Test(org.junit.Test)

Example 5 with MapConfiguration

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

the class CandlepinContextListener method readConfiguration.

protected Configuration readConfiguration(ServletContext context) throws ConfigurationException {
    // Use StandardCharsets.UTF_8 when we move to Java 7
    Charset utf8 = Charset.forName("UTF-8");
    EncryptedConfiguration systemConfig = new EncryptedConfiguration();
    systemConfig.setEncoding(utf8);
    File configFile = new File(ConfigProperties.DEFAULT_CONFIG_FILE);
    if (configFile.canRead()) {
        log.debug("Loading system configuration");
        // First, read the system configuration
        systemConfig.load(configFile);
        log.debug("System configuration: " + systemConfig);
    }
    systemConfig.use(PASSPHRASE_SECRET_FILE).toDecrypt(ENCRYPTED_PROPERTIES);
    // load the defaults
    MapConfiguration defaults = new MapConfiguration(ConfigProperties.DEFAULT_PROPERTIES);
    // Default to Postgresql if jpa.config.hibernate.dialect is unset
    DatabaseConfigFactory.SupportedDatabase db = determinDatabaseConfiguration(systemConfig.getString("jpa.config.hibernate.dialect", PostgreSQLDialect.class.getName()));
    log.info("Running under {}", db.getLabel());
    Configuration databaseConfig = DatabaseConfigFactory.fetchConfig(db);
    // users should be doing unbidden so it is undocumented.
    return EncryptedConfiguration.merge(systemConfig, databaseConfig, defaults);
}
Also used : MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) EncryptedConfiguration(org.candlepin.common.config.EncryptedConfiguration) MapConfiguration(org.candlepin.common.config.MapConfiguration) Charset(java.nio.charset.Charset) EncryptedConfiguration(org.candlepin.common.config.EncryptedConfiguration) File(java.io.File) DatabaseConfigFactory(org.candlepin.config.DatabaseConfigFactory)

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