use of org.candlepin.common.config.MapConfiguration in project candlepin by candlepin.
the class ProductExporterTest method testProductExport.
@Test
public void testProductExport() throws IOException {
ObjectMapper mapper = TestSyncUtils.getTestSyncUtils(new MapConfiguration(new HashMap<String, String>() {
{
put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false");
}
}));
ProductExporter exporter = new ProductExporter(new StandardTranslator(new ConsumerTypeCurator(), new EnvironmentCurator(), new OwnerCurator()));
StringWriter writer = new StringWriter();
Owner owner = TestUtil.createOwner("Example-Corporation");
Product product = TestUtil.createProduct("my-id", "product name");
exporter.export(mapper, writer, product);
String s = writer.toString();
assertTrue(s.contains("\"name\":\"product name\""));
assertTrue(s.contains("\"id\":\"my-id\""));
assertTrue(s.contains("\"productContent\":[]"));
assertTrue(s.contains("\"attributes\":[]"));
assertTrue(s.contains("\"multiplier\":1"));
}
use of org.candlepin.common.config.MapConfiguration in project candlepin by candlepin.
the class ProductResourceTest method testRefreshPoolsByProduct.
@Test
public void testRefreshPoolsByProduct() {
Configuration config = new MapConfiguration(this.config);
config.setProperty(ConfigProperties.STANDALONE, "false");
ProductResource productResource = new ProductResource(this.productCurator, this.ownerCurator, this.productCertificateCurator, config, this.i18n, this.modelTranslator);
List<Owner> owners = this.setupDBForOwnerProdTests();
Owner owner1 = owners.get(0);
Owner owner2 = owners.get(1);
Owner owner3 = owners.get(2);
JobDetail[] jobs;
jobs = productResource.refreshPoolsForProduct(Arrays.asList("p1"), true);
assertNotNull(jobs);
assertEquals(2, jobs.length);
this.verifyRefreshPoolsJobs(jobs, Arrays.asList(owner1, owner2), true);
jobs = productResource.refreshPoolsForProduct(Arrays.asList("p1", "p2"), false);
assertNotNull(jobs);
assertEquals(3, jobs.length);
this.verifyRefreshPoolsJobs(jobs, Arrays.asList(owner1, owner2, owner3), false);
jobs = productResource.refreshPoolsForProduct(Arrays.asList("p3"), false);
assertNotNull(jobs);
assertEquals(1, jobs.length);
this.verifyRefreshPoolsJobs(jobs, Arrays.asList(owner3), false);
jobs = productResource.refreshPoolsForProduct(Arrays.asList("nope"), false);
assertNotNull(jobs);
assertEquals(0, jobs.length);
}
use of org.candlepin.common.config.MapConfiguration in project candlepin by candlepin.
the class PinsetterKernelTest method updateMultipleSchedules.
@Test
public void updateMultipleSchedules() throws Exception {
Map<String, String> props = new HashMap<>();
props.put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
props.put("org.quartz.jobStore.isClustered", "true");
props.put("pinsetter.org.candlepin.pinsetter.tasks." + "JobCleaner.schedule", "*/1 * * * * ?");
Configuration config = new MapConfiguration(props);
JobDetail jobDetail = mock(JobDetail.class);
// Hack multiple job schedules for same job:
String crongrp = "cron group";
Set<JobKey> jobs = new HashSet<>();
JobKey key = jobKey("org.candlepin.pinsetter.tasks.JobCleaner");
jobs.add(key);
JobKey key2 = jobKey("org.candlepin.pinsetter.tasks.JobCleaner2");
jobs.add(key2);
CronTrigger cronTrigger = mock(CronTrigger.class);
when(cronTrigger.getJobKey()).thenReturn(key);
when(cronTrigger.getCronExpression()).thenReturn("*/7 * * * * ?");
when(sched.getJobKeys(eq(jobGroupEquals(crongrp)))).thenReturn(jobs);
when(sched.getTrigger(any(TriggerKey.class))).thenReturn(cronTrigger);
when(sched.getJobDetail(any(JobKey.class))).thenReturn(jobDetail);
doReturn(JobCleaner.class).when(jobDetail).getJobClass();
pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
pk.startup();
verify(sched, times(2)).deleteJob(any(JobKey.class));
verify(jcurator).create(any(JobStatus.class));
}
use of org.candlepin.common.config.MapConfiguration in project candlepin by candlepin.
the class PinsetterKernelTest method clusteredStartupWithJobs.
@Test
public void clusteredStartupWithJobs() throws Exception {
config = new MapConfiguration(new HashMap<String, String>() {
{
put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
put(ConfigProperties.TASKS, ImportRecordJob.class.getName());
put("org.quartz.jobStore.isClustered", "true");
}
});
Set<JobKey> jobs = new HashSet<>();
jobs.add(jobKey(JobCleaner.class.getName()));
jobs.add(jobKey(ImportRecordJob.class.getName()));
when(sched.getJobKeys(eq(jobGroupEquals("cron group")))).thenReturn(jobs);
pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
pk.startup();
verify(sched).start();
verify(jcurator, atMost(2)).create(any(JobStatus.class));
verify(sched, atMost(2)).scheduleJob(any(JobDetail.class), any(Trigger.class));
}
use of org.candlepin.common.config.MapConfiguration in project candlepin by candlepin.
the class PinsetterKernelTest method init.
@Before
public void init() throws SchedulerException {
sched = mock(Scheduler.class);
jfactory = mock(JobFactory.class);
jcurator = mock(JobCurator.class);
jlistener = mock(JobListener.class);
sfactory = mock(StdSchedulerFactory.class);
lm = mock(ListenerManager.class);
modeManager = mock(ModeManager.class);
triggerListener = mock(PinsetterTriggerListener.class);
config = new MapConfiguration(new HashMap<String, String>() {
{
put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
put("org.quartz.threadPool.threadCount", "25");
put("org.quartz.threadPool.threadPriority", "5");
put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
put(ConfigProperties.TASKS, ImportRecordJob.class.getName());
}
});
when(sfactory.getScheduler()).thenReturn(sched);
when(sched.getListenerManager()).thenReturn(lm);
when(modeManager.getLastCandlepinModeChange()).thenReturn(new CandlepinModeChange(new Date(System.currentTimeMillis()), CandlepinModeChange.Mode.NORMAL, CandlepinModeChange.Reason.STARTUP));
}
Aggregations