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