Search in sources :

Example 1 with OwnerCurator

use of org.candlepin.model.OwnerCurator in project candlepin by candlepin.

the class OwnerResourceTest method testCreateUeberCertificateFromScratch.

@Test
public void testCreateUeberCertificateFromScratch() {
    Principal principal = setupPrincipal(owner, Access.ALL);
    Owner owner = TestUtil.createOwner();
    UeberCertificate entCert = mock(UeberCertificate.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    EntitlementCurator ec = mock(EntitlementCurator.class);
    CandlepinPoolManager cpm = mock(CandlepinPoolManager.class);
    EntitlementCertificateCurator ecc = mock(EntitlementCertificateCurator.class);
    UeberCertificateCurator uc = mock(UeberCertificateCurator.class);
    UeberCertificateGenerator ucg = mock(UeberCertificateGenerator.class);
    OwnerResource resource = new OwnerResource(oc, pc, null, cc, i18n, null, null, null, null, null, cpm, null, null, null, null, null, ecc, ec, uc, ucg, null, null, null, null, null, null, null, null, null, this.modelTranslator);
    when(oc.lookupByKey(eq("admin"))).thenReturn(owner);
    when(ucg.generate(eq(owner.getKey()), eq(principal))).thenReturn(entCert);
    UeberCertificate result = resource.createUeberCertificate(principal, owner.getKey());
    assertEquals(entCert, result);
}
Also used : EntitlementCurator(org.candlepin.model.EntitlementCurator) OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) ProductCurator(org.candlepin.model.ProductCurator) UeberCertificateCurator(org.candlepin.model.UeberCertificateCurator) EntitlementCertificateCurator(org.candlepin.model.EntitlementCertificateCurator) UeberCertificateGenerator(org.candlepin.model.UeberCertificateGenerator) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) ConsumerCurator(org.candlepin.model.ConsumerCurator) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) Test(org.junit.Test)

Example 2 with OwnerCurator

use of org.candlepin.model.OwnerCurator in project candlepin by candlepin.

the class OwnerResourceTest method testActivationKeyRequiresName.

@Test(expected = BadRequestException.class)
public void testActivationKeyRequiresName() {
    OwnerCurator oc = mock(OwnerCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    Owner o = new Owner();
    o.setKey("owner-key");
    OwnerResource ownerres = new OwnerResource(oc, pc, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, this.modelTranslator);
    when(oc.lookupByKey(anyString())).thenReturn(o);
    ActivationKeyDTO key = new ActivationKeyDTO();
    key = ownerres.createActivationKey(owner.getKey(), key);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ActivationKeyDTO(org.candlepin.dto.api.v1.ActivationKeyDTO) ProductCurator(org.candlepin.model.ProductCurator) Test(org.junit.Test)

Example 3 with OwnerCurator

use of org.candlepin.model.OwnerCurator in project candlepin by candlepin.

the class OwnerResourceTest method getEntitlementsForNonExistantOwner.

@Test(expected = NotFoundException.class)
public void getEntitlementsForNonExistantOwner() {
    PageRequest req = new PageRequest();
    req.setPage(1);
    req.setPerPage(10);
    OwnerCurator oc = mock(OwnerCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    OwnerResource ownerres = new OwnerResource(oc, pc, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, this.modelTranslator);
    ownerres.ownerEntitlements("Taylor Swift", null, null, null, req);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) PageRequest(org.candlepin.common.paging.PageRequest) ProductCurator(org.candlepin.model.ProductCurator) Test(org.junit.Test)

Example 4 with OwnerCurator

use of org.candlepin.model.OwnerCurator 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());
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ExporterMetadataCurator(org.candlepin.model.ExporterMetadataCurator) Product(org.candlepin.model.Product) OwnerCurator(org.candlepin.model.OwnerCurator) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) Subscription(org.candlepin.model.dto.Subscription) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) Refresher(org.candlepin.controller.Refresher) PoolManager(org.candlepin.controller.PoolManager) Date(java.util.Date) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) Entitlement(org.candlepin.model.Entitlement) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Example 5 with OwnerCurator

use of org.candlepin.model.OwnerCurator 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));
}
Also used : Owner(org.candlepin.model.Owner) BouncyCastlePKIUtility(org.candlepin.pki.impl.BouncyCastlePKIUtility) BouncyCastlePKIUtility(org.candlepin.pki.impl.BouncyCastlePKIUtility) PKIUtility(org.candlepin.pki.PKIUtility) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) Date(java.util.Date) CertificateSerialCurator(org.candlepin.model.CertificateSerialCurator) OwnerCurator(org.candlepin.model.OwnerCurator) IdentityCertificateCurator(org.candlepin.model.IdentityCertificateCurator) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) ConsumerType(org.candlepin.model.ConsumerType) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Aggregations

OwnerCurator (org.candlepin.model.OwnerCurator)21 Owner (org.candlepin.model.Owner)20 Test (org.junit.Test)19 ProductCurator (org.candlepin.model.ProductCurator)9 File (java.io.File)8 ImportFile (org.candlepin.sync.Importer.ImportFile)8 Principal (org.candlepin.auth.Principal)4 Date (java.util.Date)3 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)3 UserPrincipal (org.candlepin.auth.UserPrincipal)3 CandlepinPoolManager (org.candlepin.controller.CandlepinPoolManager)3 ActivationKeyDTO (org.candlepin.dto.api.v1.ActivationKeyDTO)3 ConsumerCurator (org.candlepin.model.ConsumerCurator)3 ConsumerType (org.candlepin.model.ConsumerType)3 ConsumerTypeCurator (org.candlepin.model.ConsumerTypeCurator)3 Product (org.candlepin.model.Product)3 Reader (java.io.Reader)2 HashMap (java.util.HashMap)2 StandardTranslator (org.candlepin.dto.StandardTranslator)2 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)2