use of org.candlepin.dto.StandardTranslator in project candlepin by candlepin.
the class ConsumerResourceTest method setUp.
@Before
public void setUp() {
this.config = new CandlepinCommonTestConfig();
this.translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, mockOwnerCurator);
this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
when(eventBuilder.setEventData(any(Consumer.class))).thenReturn(eventBuilder);
when(eventFactory.getEventBuilder(any(Target.class), any(Type.class))).thenReturn(eventBuilder);
this.factValidator = new FactValidator(this.config, this.i18n);
testMigration = new GuestMigration(mockConsumerCurator);
migrationProvider = Providers.of(testMigration);
}
use of org.candlepin.dto.StandardTranslator in project candlepin by candlepin.
the class GuestIdResourceTest method setUp.
@Before
public void setUp() {
testMigration = Mockito.spy(new GuestMigration(consumerCurator));
migrationProvider = Providers.of(testMigration);
this.modelTranslator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
owner = new Owner("test-owner", "Test Owner");
ct = new ConsumerType(ConsumerTypeEnum.SYSTEM);
ct.setId("test-system-ctype");
consumer = new Consumer("consumer", "test", owner, ct);
guestIdResource = new GuestIdResource(guestIdCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, eventFactory, sink, migrationProvider, this.modelTranslator);
when(consumerCurator.findByUuid(consumer.getUuid())).thenReturn(consumer);
when(consumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
}
use of org.candlepin.dto.StandardTranslator in project candlepin by candlepin.
the class AutobindRulesTest method createEnforcer.
@Before
public void createEnforcer() throws Exception {
MockitoAnnotations.initMocks(this);
when(config.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
Rules rules = new Rules(Util.readFile(is));
when(rulesCurator.getRules()).thenReturn(rules);
when(rulesCurator.getUpdated()).thenReturn(TestDateUtil.date(2010, 1, 1));
when(cacheProvider.get()).thenReturn(cache);
JsRunner jsRules = new JsRunnerProvider(rulesCurator, cacheProvider).get();
translator = new StandardTranslator(consumerTypeCurator, environmentCurator, mockOwnerCurator);
autobindRules = new AutobindRules(jsRules, mockProductCurator, consumerTypeCurator, mockOwnerCurator, new RulesObjectMapper(new ProductCachedSerializationModule(mockProductCurator)), translator);
owner = new Owner();
owner.setId(TestUtil.randomString());
when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
ctype.setId("test-ctype");
consumer = new Consumer("test consumer", "test user", owner, ctype);
when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
when(consumerTypeCurator.lookupByLabel(eq(ctype.getLabel()))).thenReturn(ctype);
when(consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
compliance = new ComplianceStatus();
activeGuestAttrs = new HashMap<>();
activeGuestAttrs.put("virtWhoType", "libvirt");
activeGuestAttrs.put("active", "1");
}
use of org.candlepin.dto.StandardTranslator in project candlepin by candlepin.
the class HypervisorResourceTest method setupTest.
@Before
public void setupTest() {
Configuration config = new CandlepinCommonTestConfig();
testMigration = new GuestMigration(consumerCurator);
migrationProvider = Providers.of(testMigration);
this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
this.hypervisorType = new ConsumerType(ConsumerTypeEnum.HYPERVISOR);
this.hypervisorType.setId("test-hypervisor-ctype");
this.mockConsumerType(this.hypervisorType);
this.modelTranslator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
this.consumerResource = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, this.subscriptionService, this.ownerService, null, this.idCertService, null, this.i18n, this.sink, this.eventFactory, null, null, this.userService, null, null, this.ownerCurator, this.activationKeyCurator, null, this.complianceRules, this.deletedConsumerCurator, null, null, config, null, null, null, this.consumerBindUtil, null, null, new FactValidator(config, this.i18n), null, consumerEnricher, migrationProvider, modelTranslator);
this.guestIdResource = new GuestIdResource(this.guestIdCurator, this.consumerCurator, this.consumerTypeCurator, this.consumerResource, this.i18n, this.eventFactory, this.sink, migrationProvider, modelTranslator);
this.hypervisorResource = new HypervisorResource(consumerResource, consumerCurator, consumerTypeCurator, i18n, ownerCurator, migrationProvider, modelTranslator, guestIdResource);
// Ensure that we get the consumer that was passed in back from the create call.
when(consumerCurator.create(any(Consumer.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0];
}
});
when(consumerCurator.create(any(Consumer.class), any(Boolean.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0];
}
});
when(complianceRules.getStatus(any(Consumer.class), any(Date.class), any(Boolean.class))).thenReturn(new ComplianceStatus(new Date()));
when(ownerCurator.lookupByKey(any(String.class))).thenReturn(new Owner());
when(eventFactory.getEventBuilder(any(Target.class), any(Type.class))).thenReturn(consumerEventBuilder);
when(consumerEventBuilder.setEventData(any(Consumer.class))).thenReturn(consumerEventBuilder);
}
use of org.candlepin.dto.StandardTranslator 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()));
}
Aggregations