use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class ImporterTest method testReturnsSubscriptionsFromManifest.
@Test
public void testReturnsSubscriptionsFromManifest() throws IOException, ImporterException {
Owner owner = new Owner("admin", "Admin Owner");
ExporterMetadataCurator emc = mock(ExporterMetadataCurator.class);
when(emc.lookupByTypeAndOwner("per_user", owner)).thenReturn(null);
ConsumerType stype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
stype.setId("test-ctype");
when(consumerTypeCurator.lookupByLabel(eq("system"))).thenReturn(stype);
when(consumerTypeCurator.find(eq(stype.getId()))).thenReturn(stype);
OwnerCurator oc = mock(OwnerCurator.class);
when(oc.lookupWithUpstreamUuid(any(String.class))).thenReturn(null);
PoolManager pm = mock(PoolManager.class);
Refresher refresher = mock(Refresher.class);
when(pm.getRefresher(any(SubscriptionServiceAdapter.class), any(OwnerServiceAdapter.class))).thenReturn(refresher);
Map<String, File> importFiles = new HashMap<>();
File ruleDir = mock(File.class);
File[] rulesFiles = createMockJsFile(mockJsPath);
when(ruleDir.listFiles()).thenReturn(rulesFiles);
File actualmeta = createFile("meta.json", "0.0.3", new Date(), "test_user", "prefix");
importFiles.put(ImportFile.META.fileName(), actualmeta);
ConsumerDTO consumerDTO = new ConsumerDTO();
consumerDTO.setUuid("eb5e04bf-be27-44cf-abe3-0c0b1edd523e");
consumerDTO.setName("mymachine");
ConsumerTypeDTO typeDTO = new ConsumerTypeDTO();
typeDTO.setLabel("candlepin");
typeDTO.setManifest(true);
consumerDTO.setType(typeDTO);
consumerDTO.setUrlWeb("foo.example.com/subscription");
consumerDTO.setUrlApi("/candlepin");
consumerDTO.setContentAccessMode("");
OwnerDTO ownerDTO = new OwnerDTO();
ownerDTO.setKey("admin");
ownerDTO.setDisplayName("Admin Owner");
consumerDTO.setOwner(ownerDTO);
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
ctype.setId("test-ctype");
when(consumerTypeCurator.lookupByLabel(eq("candlepin"))).thenReturn(ctype);
when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
File consumerFile = new File(folder.getRoot(), "consumer.json");
mapper.writeValue(consumerFile, consumerDTO);
importFiles.put(ImportFile.CONSUMER.fileName(), consumerFile);
File cTypes = mock(File.class);
when(cTypes.listFiles()).thenReturn(new File[] {});
importFiles.put(ImportFile.CONSUMER_TYPE.fileName(), cTypes);
Product prod = new Product("prodId", "prodTest", null);
prod.setDependentProductIds(null);
File prodFile = new File(folder.getRoot(), "product.json");
mapper.writeValue(prodFile, prod);
File products = mock(File.class);
when(products.listFiles()).thenReturn(new File[] { prodFile });
importFiles.put(ImportFile.PRODUCTS.fileName(), products);
Entitlement ent = new Entitlement();
Pool pool = new Pool();
pool.setProduct(prod);
ent.setPool(pool);
ent.setQuantity(2);
File entFile = new File(folder.getRoot(), "entitlement.json");
mapper.writeValue(entFile, ent);
File entitlements = mock(File.class);
when(entitlements.listFiles()).thenReturn(new File[] { entFile });
importFiles.put(ImportFile.ENTITLEMENTS.fileName(), entitlements);
RulesImporter ri = mock(RulesImporter.class);
importFiles.put(ImportFile.RULES_FILE.fileName(), rulesFiles[0]);
ConflictOverrides co = mock(ConflictOverrides.class);
Importer i = new Importer(consumerTypeCurator, pc, ri, oc, null, null, pm, null, config, emc, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
List<Subscription> subscriptions = i.importObjects(owner, importFiles, co);
assertEquals(1, subscriptions.size());
assertEquals("prodId", subscriptions.get(0).getProduct().getId());
assertEquals(2, subscriptions.get(0).getQuantity().longValue());
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class ImporterTest method testRecordImportIgnoresUpstreamConsumerIfNotSetOnOwner.
@Test
public void testRecordImportIgnoresUpstreamConsumerIfNotSetOnOwner() {
String expectedOwnerKey = "TEST_OWNER";
Owner owner = new Owner(expectedOwnerKey);
EventSink eventSinkMock = mock(EventSink.class);
ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
Map<String, Object> data = new HashMap<>();
data.put("meta", meta);
data.put("subscriptions", new ArrayList<Subscription>());
ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
assertNull(record.getUpstreamConsumer());
verify(importRecordCurator).create(eq(record));
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class ImporterTest method testRecordImportSuccess.
@Test
public void testRecordImportSuccess() {
String expectedOwnerKey = "TEST_OWNER";
Owner owner = new Owner(expectedOwnerKey);
EventSink eventSinkMock = mock(EventSink.class);
ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
List<Subscription> subscriptions = new ArrayList<>();
Subscription subscription = new Subscription();
subscriptions.add(subscription);
Map<String, Object> data = new HashMap<>();
data.put("meta", meta);
data.put("subscriptions", subscriptions);
ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
assertEquals(meta.getPrincipalName(), record.getGeneratedBy());
assertEquals(meta.getCreated(), record.getGeneratedDate());
assertEquals(ImportRecord.Status.SUCCESS, record.getStatus());
assertEquals(owner.getKey() + " file imported successfully.", record.getStatusMessage());
assertEquals("test.zip", record.getFileName());
verify(importRecordCurator).create(eq(record));
verify(eventSinkMock, never()).emitSubscriptionExpired(subscription);
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class TestUtil method createSubscription.
public static Subscription createSubscription(Owner owner, ProductData dto, Collection<ProductData> providedProductsData) {
Set<ProductData> providedProductsSet = new HashSet<>();
providedProductsSet.addAll(providedProductsData);
Subscription sub = new Subscription(owner, dto, providedProductsSet, 1000L, createDate(2000, 1, 1), createDate(2050, 1, 1), createDate(2000, 1, 1));
sub.setId("test-sub-" + randomInt());
return sub;
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method createPoolsForExistingSubscriptionsMasterExist.
@Test
public void createPoolsForExistingSubscriptionsMasterExist() {
Owner owner = this.getOwner();
PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
List<Subscription> subscriptions = new ArrayList<>();
Product prod = TestUtil.createProduct();
Set<Product> products = new HashSet<>();
products.add(prod);
// productCache.addProducts(products);
prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
Subscription s = TestUtil.createSubscription(owner, prod);
subscriptions.add(s);
this.mockProducts(owner, prod);
when(mockSubAdapter.getSubscriptions(any(Owner.class))).thenReturn(subscriptions);
when(mockConfig.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
List<Pool> existingPools = new LinkedList<>();
Pool p = TestUtil.createPool(prod);
p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
existingPools.add(p);
List<Pool> newPools = pRules.createAndEnrichPools(s, existingPools);
assertEquals(newPools.size(), 1);
assertEquals(newPools.get(0).getSourceSubscription().getSubscriptionSubKey(), "derived");
}
Aggregations