Search in sources :

Example 31 with Pool

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

the class PoolResourceTest method testListConsumerFiltering.

@Test
public void testListConsumerFiltering() {
    setupPrincipal(new ConsumerPrincipal(passConsumer, owner1));
    List<PoolDTO> pools = poolResource.list(null, passConsumer.getUuid(), null, false, null, adminPrincipal, null);
    assertEquals(2, pools.size());
    verify(attrUtil, times(1)).setCalculatedAttributes((List<Pool>) argThat(IsCollectionWithSize.hasSize(2)), any(Date.class));
}
Also used : PoolDTO(org.candlepin.dto.api.v1.PoolDTO) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Pool(org.candlepin.model.Pool) Date(java.util.Date) Test(org.junit.Test)

Example 32 with Pool

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

the class ConsumerBindUtilTest method registerFailWithNoGoodKeyPool.

@Test(expected = BadRequestException.class)
public void registerFailWithNoGoodKeyPool() throws Exception {
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    keys.add(key1);
    Product prod1 = TestUtil.createProduct();
    Pool ghost = TestUtil.createPool(owner, prod1, 5);
    ghost.setId("ghost-pool");
    key1.addPool(ghost, 10L);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    when(entitler.bindByPoolQuantity(eq(consumer), eq(ghost.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 33 with Pool

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

the class ConsumerBindUtilTest method registerPassWhenAutobindDisabledForOwnerAndKeyHasAutobindEnabled.

@Test
public void registerPassWhenAutobindDisabledForOwnerAndKeyHasAutobindEnabled() throws Exception {
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    key1.setAutoAttach(true);
    keys.add(key1);
    Product prod1 = TestUtil.createProduct();
    Pool pool1 = TestUtil.createPool(owner, prod1, 5);
    pool1.setId("pool1");
    key1.addPool(pool1, 10L);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    when(entitler.bindByPoolQuantity(eq(consumer), eq(pool1.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
    consumerBindUtil.handleActivationKeys(consumer, keys, true);
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 34 with Pool

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

the class EntitlementImporterTest method fullImport.

@Test
public void fullImport() throws Exception {
    Product parentProduct = TestUtil.createProduct();
    Product derivedProduct = TestUtil.createProduct();
    Product provided1 = TestUtil.createProduct();
    Set<Product> providedProducts = new HashSet<>();
    providedProducts.add(new Product(provided1));
    Product derivedProvided1 = TestUtil.createProduct();
    Set<Product> derivedProvidedProducts = new HashSet<>();
    derivedProvidedProducts.add(new Product(derivedProvided1));
    Pool pool = TestUtil.createPool(owner, parentProduct, new HashSet<>(), derivedProduct, new HashSet<>(), 3);
    pool.setProvidedProducts(providedProducts);
    pool.setDerivedProvidedProducts(derivedProvidedProducts);
    Entitlement ent = TestUtil.createEntitlement(owner, consumer, pool, cert);
    ent.setQuantity(3);
    EntitlementDTO dtoEnt = this.translator.translate(ent, EntitlementDTO.class);
    when(om.readValue(reader, EntitlementDTO.class)).thenReturn(dtoEnt);
    // Create our expected products
    Map<String, ProductDTO> productsById = buildProductCache(parentProduct, provided1, derivedProduct, derivedProvided1);
    Subscription sub = importer.importObject(om, reader, owner, productsById, consumerDTO.getUuid(), meta);
    assertEquals(pool.getId(), sub.getUpstreamPoolId());
    assertEquals(consumer.getUuid(), sub.getUpstreamConsumerId());
    assertEquals(ent.getId(), sub.getUpstreamEntitlementId());
    assertEquals(owner, sub.getOwner());
    assertEquals(ent.getStartDate(), sub.getStartDate());
    assertEquals(ent.getEndDate(), sub.getEndDate());
    assertEquals(pool.getAccountNumber(), sub.getAccountNumber());
    assertEquals(pool.getContractNumber(), sub.getContractNumber());
    assertEquals(pool.getOrderNumber(), sub.getOrderNumber());
    assertEquals(ent.getQuantity().intValue(), sub.getQuantity().intValue());
    assertEquals(parentProduct.toDTO(), sub.getProduct());
    assertEquals(providedProducts.size(), sub.getProvidedProducts().size());
    assertEquals(provided1.getId(), sub.getProvidedProducts().iterator().next().getId());
    assertEquals(derivedProduct.toDTO(), sub.getDerivedProduct());
    assertEquals(1, sub.getDerivedProvidedProducts().size());
    assertEquals(derivedProvided1.getId(), sub.getDerivedProvidedProducts().iterator().next().getId());
    assertNotNull(sub.getCertificate());
    CertificateSerial serial = sub.getCertificate().getSerial();
    assertEquals(cert.getSerial().isCollected(), serial.isCollected());
    assertEquals(cert.getSerial().getExpiration(), serial.getExpiration());
    assertEquals(cert.getSerial().getCreated(), serial.getCreated());
    assertEquals(cert.getSerial().getUpdated(), serial.getUpdated());
    assertEquals(sub.getCdn().getLabel(), meta.getCdnLabel());
}
Also used : EntitlementDTO(org.candlepin.dto.manifest.v1.EntitlementDTO) Product(org.candlepin.model.Product) CertificateSerial(org.candlepin.model.CertificateSerial) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Subscription(org.candlepin.model.dto.Subscription) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with Pool

use of org.candlepin.model.Pool 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)

Aggregations

Pool (org.candlepin.model.Pool)508 Test (org.junit.Test)358 Product (org.candlepin.model.Product)217 Entitlement (org.candlepin.model.Entitlement)125 Consumer (org.candlepin.model.Consumer)115 ValidationResult (org.candlepin.policy.ValidationResult)111 ArrayList (java.util.ArrayList)100 LinkedList (java.util.LinkedList)100 Owner (org.candlepin.model.Owner)80 HashSet (java.util.HashSet)76 HashMap (java.util.HashMap)67 PoolQuantity (org.candlepin.model.PoolQuantity)66 Date (java.util.Date)65 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)62 Subscription (org.candlepin.model.dto.Subscription)60 List (java.util.List)48 ConsumerType (org.candlepin.model.ConsumerType)48 SourceSubscription (org.candlepin.model.SourceSubscription)47 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)38 Matchers.anyString (org.mockito.Matchers.anyString)30