Search in sources :

Example 11 with StandardTranslator

use of org.candlepin.dto.StandardTranslator 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()));
}
Also used : StringWriter(java.io.StringWriter) 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)

Example 12 with StandardTranslator

use of org.candlepin.dto.StandardTranslator in project candlepin by candlepin.

the class EntitlementImporterTest method init.

@Before
public void init() {
    this.owner = new Owner();
    this.translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, ownerCurator);
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    this.importer = new EntitlementImporter(certSerialCurator, cdnCurator, i18n, mockProductCurator, ec, translator);
    ConsumerType ctype = TestUtil.createConsumerType();
    ctype.setId("test-ctype");
    consumer = TestUtil.createConsumer(ctype, owner);
    consumerDTO = this.translator.translate(consumer, ConsumerDTO.class);
    consumerDTO.setUrlWeb("");
    consumerDTO.setUrlApi("");
    when(this.mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(this.mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    cert = createEntitlementCertificate("my-test-key", "my-cert");
    cert.setId("test-id");
    reader = mock(Reader.class);
    meta = new Meta();
    meta.setCdnLabel("test-cdn");
    testCdn = new Cdn("test-cdn", "Test CDN", "https://test.url.com");
    when(cdnCurator.lookupByLabel("test-cdn")).thenReturn(testCdn);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) Reader(java.io.Reader) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 13 with StandardTranslator

use of org.candlepin.dto.StandardTranslator 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"));
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ConsumerTypeCurator(org.candlepin.model.ConsumerTypeCurator) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) Product(org.candlepin.model.Product) EnvironmentCurator(org.candlepin.model.EnvironmentCurator) StandardTranslator(org.candlepin.dto.StandardTranslator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 14 with StandardTranslator

use of org.candlepin.dto.StandardTranslator in project candlepin by candlepin.

the class SubscriptionReconcilerTest method init.

@Before
public void init() {
    this.owner = new Owner();
    this.reconciler = new SubscriptionReconciler(this.poolCurator);
    this.translator = new StandardTranslator(new ConsumerTypeCurator(), new EnvironmentCurator(), new OwnerCurator());
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    this.importer = new EntitlementImporter(certSerialCurator, cdnCurator, i18n, pc, ec, translator);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ConsumerTypeCurator(org.candlepin.model.ConsumerTypeCurator) EnvironmentCurator(org.candlepin.model.EnvironmentCurator) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 15 with StandardTranslator

use of org.candlepin.dto.StandardTranslator in project candlepin by candlepin.

the class QuantityRulesTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    // Load the default production rules:
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
    when(rulesCuratorMock.getRules()).thenReturn(rules);
    when(cacheProvider.get()).thenReturn(cache);
    provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
    translator = new StandardTranslator(consumerTypeCurator, environmentCurator, ownerCuratorMock);
    quantityRules = new QuantityRules(provider.get(), new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), translator);
    owner = new Owner("Test Owner " + TestUtil.randomInt());
    product = TestUtil.createProduct();
    pool = TestUtil.createPool(owner, product);
    pool.setId("fakepoolid");
    ctype = TestUtil.createConsumerType();
    consumer = TestUtil.createConsumer(owner);
    when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, new EntitlementCertificate());
    Set<Entitlement> entSet = new HashSet<>();
    entSet.add(e);
    pool.setEntitlements(entSet);
    pool.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    pool.getProduct().setAttribute(Product.Attributes.STACKING_ID, "1");
}
Also used : Owner(org.candlepin.model.Owner) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) InputStream(java.io.InputStream) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) Rules(org.candlepin.model.Rules) StandardTranslator(org.candlepin.dto.StandardTranslator) Date(java.util.Date) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Before(org.junit.Before)

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