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