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