use of org.candlepin.dto.api.v1.ConsumerDTO 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.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ImporterTest method importConsumer.
@Test
public void importConsumer() throws Exception {
PKIUtility pki = new BouncyCastlePKIUtility(null, null, null);
OwnerCurator oc = mock(OwnerCurator.class);
ConsumerType type = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
type.setId("test-ctype");
when(consumerTypeCurator.lookupByLabel(eq("candlepin"))).thenReturn(type);
when(consumerTypeCurator.find(eq(type.getId()))).thenReturn(type);
Importer i = new Importer(consumerTypeCurator, null, null, oc, mock(IdentityCertificateCurator.class), null, null, pki, null, null, mock(CertificateSerialCurator.class), null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
File[] upstream = createUpstreamFiles();
Owner owner = new Owner("admin", "Admin Owner");
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("access_mode");
OwnerDTO ownerDTO = new OwnerDTO();
ownerDTO.setKey("admin");
ownerDTO.setDisplayName("Admin Owner");
consumerDTO.setOwner(ownerDTO);
File consumerfile = new File(folder.getRoot(), "consumer.json");
mapper.writeValue(consumerfile, consumerDTO);
ConflictOverrides forcedConflicts = mock(ConflictOverrides.class);
when(forcedConflicts.isForced(any(Importer.Conflict.class))).thenReturn(false);
Meta meta = new Meta("1.0", new Date(), "admin", "/candlepin/owners", null);
i.importConsumer(owner, consumerfile, upstream, forcedConflicts, meta);
verify(oc).merge(eq(owner));
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerImporterTest method importConsumerWithSameUuidOnOwnerShouldDoNothing.
@Test
public void importConsumerWithSameUuidOnOwnerShouldDoNothing() throws ImporterException {
Owner owner = mock(Owner.class);
OwnerDTO ownerDTO = mock(OwnerDTO.class);
ConsumerDTO consumer = mock(ConsumerDTO.class);
ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
when(owner.getUpstreamUuid()).thenReturn("test-uuid");
when(consumer.getUuid()).thenReturn("test-uuid");
when(consumer.getOwner()).thenReturn(ownerDTO);
when(consumer.getType()).thenReturn(type);
IdentityCertificate idCert = new IdentityCertificate();
idCert.setSerial(new CertificateSerial());
importer.store(owner, consumer, new ConflictOverrides(), idCert);
// now verify that the owner didn't change
// arg.getValue() returns the Owner being stored
ArgumentCaptor<Owner> arg = ArgumentCaptor.forClass(Owner.class);
verify(curator).merge(arg.capture());
assertEquals("test-uuid", arg.getValue().getUpstreamUuid());
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerImporterTest method importConsumerWithNullIdCertShouldNotFail.
/*
* BZ#966860
*/
@Test
public void importConsumerWithNullIdCertShouldNotFail() throws ImporterException {
Owner owner = mock(Owner.class);
OwnerDTO ownerDTO = mock(OwnerDTO.class);
ConsumerDTO consumer = mock(ConsumerDTO.class);
ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
when(owner.getUpstreamUuid()).thenReturn("test-uuid");
when(consumer.getUuid()).thenReturn("test-uuid");
when(consumer.getOwner()).thenReturn(ownerDTO);
when(consumer.getType()).thenReturn(type);
importer.store(owner, consumer, new ConflictOverrides(), null);
// now verify that the owner has the upstream consumer set
ArgumentCaptor<UpstreamConsumer> arg = ArgumentCaptor.forClass(UpstreamConsumer.class);
verify(owner).setUpstreamConsumer(arg.capture());
assertEquals("test-uuid", arg.getValue().getUuid());
verify(curator).merge(owner);
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerImporterTest method importShouldCreateAValidConsumer.
@Test
public void importShouldCreateAValidConsumer() throws IOException {
ConsumerDTO consumer = importer.createObject(mapper, new StringReader("{\"uuid\":\"test-uuid\",\"name\":\"test-name\"}"));
assertEquals("test-uuid", consumer.getUuid());
assertEquals("test-name", consumer.getName());
}
Aggregations