Search in sources :

Example 6 with StandardTranslator

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);
}
Also used : FactValidator(org.candlepin.util.FactValidator) GuestMigration(org.candlepin.resource.util.GuestMigration) Target(org.candlepin.audit.Event.Target) Type(org.candlepin.audit.Event.Type) ConsumerType(org.candlepin.model.ConsumerType) Consumer(org.candlepin.model.Consumer) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 7 with StandardTranslator

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);
}
Also used : GuestMigration(org.candlepin.resource.util.GuestMigration) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 8 with StandardTranslator

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");
}
Also used : Owner(org.candlepin.model.Owner) AutobindRules(org.candlepin.policy.js.autobind.AutobindRules) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) InputStream(java.io.InputStream) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) JsRunner(org.candlepin.policy.js.JsRunner) Rules(org.candlepin.model.Rules) AutobindRules(org.candlepin.policy.js.autobind.AutobindRules) StandardTranslator(org.candlepin.dto.StandardTranslator) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) Consumer(org.candlepin.model.Consumer) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) ConsumerType(org.candlepin.model.ConsumerType) Before(org.junit.Before)

Example 9 with StandardTranslator

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);
}
Also used : FactValidator(org.candlepin.util.FactValidator) Owner(org.candlepin.model.Owner) Configuration(org.candlepin.common.config.Configuration) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) StandardTranslator(org.candlepin.dto.StandardTranslator) Date(java.util.Date) GuestMigration(org.candlepin.resource.util.GuestMigration) Target(org.candlepin.audit.Event.Target) Type(org.candlepin.audit.Event.Type) ConsumerType(org.candlepin.model.ConsumerType) Consumer(org.candlepin.model.Consumer) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConsumerType(org.candlepin.model.ConsumerType) Before(org.junit.Before)

Example 10 with StandardTranslator

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()));
}
Also used : StringWriter(java.io.StringWriter) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) ConsumerType(org.candlepin.model.ConsumerType) StandardTranslator(org.candlepin.dto.StandardTranslator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

StandardTranslator (org.candlepin.dto.StandardTranslator)20 Before (org.junit.Before)17 Owner (org.candlepin.model.Owner)10 ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)9 ConsumerType (org.candlepin.model.ConsumerType)9 Consumer (org.candlepin.model.Consumer)8 Date (java.util.Date)7 Rules (org.candlepin.model.Rules)7 JsRunnerProvider (org.candlepin.policy.js.JsRunnerProvider)7 RulesObjectMapper (org.candlepin.policy.js.RulesObjectMapper)7 InputStream (java.io.InputStream)6 CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)5 GuestMigration (org.candlepin.resource.util.GuestMigration)5 MapConfiguration (org.candlepin.common.config.MapConfiguration)4 ConsumerTypeCurator (org.candlepin.model.ConsumerTypeCurator)4 EnvironmentCurator (org.candlepin.model.EnvironmentCurator)4 OwnerCurator (org.candlepin.model.OwnerCurator)4 ComplianceStatus (org.candlepin.policy.js.compliance.ComplianceStatus)4 FactValidator (org.candlepin.util.FactValidator)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3