Search in sources :

Example 46 with Pool

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

the class X509V3ExtensionUtilTest method productWithMultipleBrandNames.

@Test
public void productWithMultipleBrandNames() {
    String engProdId = "1000";
    String brandedName = "Branded Eng Product";
    Owner owner = new Owner("Test Corporation");
    Product p = new Product(engProdId, "Eng Product 1000");
    p.setAttribute(Product.Attributes.BRANDING_TYPE, "OS");
    Set<Product> prods = new HashSet<>(Arrays.asList(p));
    Product mktProd = new Product("mkt", "MKT SKU");
    Pool pool = TestUtil.createPool(mktProd);
    pool.getBranding().add(new Branding(engProdId, "OS", brandedName));
    pool.getBranding().add(new Branding(engProdId, "OS", "another brand name"));
    pool.getBranding().add(new Branding(engProdId, "OS", "number 3"));
    Set<String> possibleBrandNames = new HashSet<>();
    for (Branding b : pool.getBranding()) {
        possibleBrandNames.add(b.getName());
    }
    List<org.candlepin.model.dto.Product> certProds = util.createProducts(mktProd, prods, "", new HashMap<>(), new Consumer(), pool);
    assertEquals(1, certProds.size());
    // Should get the first name we encountered
    // but they're in a set so we can't test order
    String resultBrandName = certProds.get(0).getBrandName();
    String resultBrandType = certProds.get(0).getBrandType();
    assertTrue(possibleBrandNames.contains(resultBrandName));
    assertEquals("OS", resultBrandType);
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) Branding(org.candlepin.model.Branding) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with Pool

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

the class TestUtil method createPool.

public static Pool createPool(Owner owner, Product product, Collection<Product> providedProducts, Product derivedProduct, Collection<Product> subProvidedProducts, int quantity) {
    Pool pool = createPool(owner, product, providedProducts, quantity);
    Set<Product> subProvided = new HashSet<>();
    if (subProvidedProducts != null) {
        subProvided.addAll(subProvidedProducts);
    }
    pool.setDerivedProduct(derivedProduct);
    pool.setDerivedProvidedProducts(subProvided);
    return pool;
}
Also used : Product(org.candlepin.model.Product) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) HashSet(java.util.HashSet)

Example 48 with Pool

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

the class EntitlementCertificateGeneratorTest method testGenerateEntitlementCertificate.

@Test
public void testGenerateEntitlementCertificate() throws GeneralSecurityException, IOException {
    this.ecGenerator = new EntitlementCertificateGenerator(this.mockEntCertCurator, this.mockEntCertAdapter, this.mockEntitlementCurator, this.mockPoolCurator, this.mockEventSink, this.mockEventFactory, this.mockProductCurator);
    Consumer consumer = mock(Consumer.class);
    Pool pool = mock(Pool.class);
    Product product = mock(Product.class);
    when(pool.getId()).thenReturn("Swift");
    when(pool.getProduct()).thenReturn(product);
    Entitlement entitlement = mock(Entitlement.class);
    when(entitlement.getConsumer()).thenReturn(consumer);
    Map<String, Product> expectedProducts = new HashMap<>();
    expectedProducts.put("Swift", product);
    Map<String, Entitlement> expected = new HashMap<>();
    expected.put("Swift", entitlement);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put("Swift", new PoolQuantity(pool, 0));
    ecGenerator.generateEntitlementCertificate(pool, entitlement);
    verify(mockEntCertAdapter).generateEntitlementCerts(eq(consumer), eq(poolQuantityMap), eq(expected), eq(expectedProducts), eq(true));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 49 with Pool

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

the class EntitlementCertificateGeneratorTest method createPool.

/**
 * This method creates pool for testing without in-memory database. The provided
 * products are 'cached' in mocked product curator
 */
private Pool createPool(Owner owner, Product prod, Set<Product> providedProd, int q) {
    Pool p = TestUtil.createPool(owner, prod, providedProd, q);
    p.setId("" + lastPoolId++);
    System.out.println("Caching providedProducts for Pool:" + p.getId());
    when(mockProductCurator.getPoolProvidedProductsCached(p.getId())).thenReturn(providedProd);
    return p;
}
Also used : Pool(org.candlepin.model.Pool)

Example 50 with Pool

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

the class EntitlementCertificateGeneratorTest method testNonLazyRegenerationByEntitlementId.

@Test
public void testNonLazyRegenerationByEntitlementId() throws Exception {
    Owner owner = TestUtil.createOwner("test-owner", "Test Owner");
    Consumer consumer = TestUtil.createConsumer(owner);
    Product product = TestUtil.createProduct();
    Pool pool = TestUtil.createPool(owner, product);
    Entitlement entitlement = TestUtil.createEntitlement(owner, consumer, pool, null);
    entitlement.setId("test-ent-id");
    Collection<String> entitlements = Arrays.asList(entitlement.getId());
    pool.setEntitlements(new HashSet(Arrays.asList(entitlement)));
    HashMap<String, EntitlementCertificate> ecMap = new HashMap<>();
    ecMap.put(pool.getId(), new EntitlementCertificate());
    when(this.mockEntitlementCurator.find(eq(entitlement.getId()))).thenReturn(entitlement);
    when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), any(Map.class), any(Map.class), any(Map.class), eq(true))).thenReturn(ecMap);
    this.ecGenerator.regenerateCertificatesByEntitlementIds(entitlements, false);
    assertFalse(entitlement.isDirty());
    verify(this.mockEntCertAdapter, times(1)).generateEntitlementCerts(any(Consumer.class), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor.capture(), eq(true));
    verify(this.mockEventSink, times(1)).queueEvent(any(Event.class));
}
Also used : Owner(org.candlepin.model.Owner) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Consumer(org.candlepin.model.Consumer) Event(org.candlepin.audit.Event) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) 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