Search in sources :

Example 1 with SourceSubscription

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

the class TestUtil method clone.

/**
 * @param pool source pool
 * @return pool the clone pool
 */
public static Pool clone(Pool pool) {
    Pool p = new Pool(pool.getOwner(), pool.getProduct(), new HashSet<>(pool.getProvidedProducts()), pool.getQuantity(), pool.getStartDate(), pool.getEndDate(), pool.getContractNumber(), pool.getAccountNumber(), pool.getOrderNumber());
    p.setSourceSubscription(new SourceSubscription(pool.getSubscriptionId(), pool.getSubscriptionSubKey()));
    // Copy sub-product data if there is any:
    p.setDerivedProduct(pool.getDerivedProduct());
    for (Branding b : pool.getBranding()) {
        p.getBranding().add(new Branding(b.getProductId(), b.getType(), b.getName()));
    }
    return p;
}
Also used : SourceSubscription(org.candlepin.model.SourceSubscription) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) Branding(org.candlepin.model.Branding)

Example 2 with SourceSubscription

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

the class TestUtil method copyFromSub.

/**
 * Returns a pool which will look like it was created from the given subscription
 * during refresh pools.
 *
 * @param sub source subscription
 * @return pool for subscription
 */
public static Pool copyFromSub(Subscription sub) {
    Product product = createProduct((ProductData) sub.getProduct());
    Product derivedProduct = createProduct((ProductData) sub.getDerivedProduct());
    List<Product> providedProducts = new LinkedList<>();
    if (sub.getProvidedProducts() != null) {
        for (ProductData pdata : sub.getProvidedProducts()) {
            if (pdata != null) {
                providedProducts.add(TestUtil.createProduct(pdata));
            }
        }
    }
    List<Product> derivedProvidedProducts = new LinkedList<>();
    if (sub.getDerivedProvidedProducts() != null) {
        for (ProductData pdata : sub.getDerivedProvidedProducts()) {
            if (pdata != null) {
                derivedProvidedProducts.add(TestUtil.createProduct(pdata));
            }
        }
    }
    Pool pool = new Pool(sub.getOwner(), product, providedProducts, sub.getQuantity(), sub.getStartDate(), sub.getEndDate(), sub.getContractNumber(), sub.getAccountNumber(), sub.getOrderNumber());
    pool.setDerivedProduct(derivedProduct);
    pool.setDerivedProvidedProducts(derivedProvidedProducts);
    if (sub.getId() != null) {
        pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
    }
    pool.setUpstreamPoolId(sub.getUpstreamPoolId());
    pool.setUpstreamConsumerId(sub.getUpstreamConsumerId());
    pool.setUpstreamEntitlementId(sub.getUpstreamEntitlementId());
    for (Branding branding : sub.getBranding()) {
        pool.getBranding().add(new Branding(branding.getProductId(), branding.getType(), branding.getName()));
    }
    return pool;
}
Also used : ProductData(org.candlepin.model.dto.ProductData) SourceSubscription(org.candlepin.model.SourceSubscription) Product(org.candlepin.model.Product) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) Branding(org.candlepin.model.Branding) LinkedList(java.util.LinkedList)

Example 3 with SourceSubscription

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

the class PoolTranslatorTest method initSourceObject.

@Override
protected Pool initSourceObject() {
    Pool source = new Pool();
    source.setId("pool-id");
    source.setOwner(this.ownerTranslatorTest.initSourceObject());
    source.setProduct(this.productTranslatorTest.initSourceObject());
    source.setDerivedProduct(this.productTranslatorTest.initSourceObject());
    Set<Branding> brandingSet = new HashSet<>();
    brandingSet.add(this.brandingTranslatorTest.initSourceObject());
    source.setBranding(brandingSet);
    Entitlement entitlement = new Entitlement();
    entitlement.setId("ent-id");
    source.setSourceEntitlement(entitlement);
    SubscriptionsCertificate subCert = new SubscriptionsCertificate();
    subCert.setId("cert-id");
    subCert.setKey("cert-key");
    subCert.setCert("cert-cert");
    subCert.setSerial(new CertificateSerial());
    source.setCertificate(subCert);
    SourceSubscription sourceSubscription = new SourceSubscription();
    sourceSubscription.setId("source-sub-id-1");
    sourceSubscription.setSubscriptionId("source-sub-subscription-id-1");
    sourceSubscription.setSubscriptionSubKey("source-sub-subscription-sub-key-1");
    source.setSourceSubscription(sourceSubscription);
    source.setActiveSubscription(true);
    source.setCreatedByShare(false);
    source.setHasSharedAncestor(true);
    source.setQuantity(1L);
    source.setStartDate(new Date());
    source.setEndDate(new Date());
    Map<String, String> attributes = new HashMap<>();
    attributes.put(Pool.Attributes.SOURCE_POOL_ID, "true");
    source.setAttributes(attributes);
    source.setRestrictedToUsername("restricted-to-username-value");
    source.setContractNumber("333");
    source.setAccountNumber("444");
    source.setOrderNumber("555");
    source.setConsumed(6L);
    source.setExported(7L);
    source.setShared(8L);
    Map<String, String> calculatedAttributes = new HashMap<>();
    calculatedAttributes.put("calc-attribute-key-3", "calc-attribute-value-3");
    calculatedAttributes.put("calc-attribute-key-4", "calc-attribute-value-4");
    source.setCalculatedAttributes(calculatedAttributes);
    source.setUpstreamPoolId("upstream-pool-id-2");
    source.setUpstreamEntitlementId("upstream-entitlement-id-2");
    source.setUpstreamConsumerId("upstream-consumer-id-2");
    source.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    Product derivedProduct = new Product();
    derivedProduct.setId("derived-product-id-2");
    derivedProduct.setName("derived-product-name-2");
    derivedProduct.setAttributes(new HashMap<>());
    derivedProduct.setAttribute(Product.Attributes.ARCHITECTURE, "POWER");
    derivedProduct.setAttribute(Product.Attributes.STACKING_ID, "2221");
    source.setDerivedProduct(derivedProduct);
    ProvidedProduct providedProd = new ProvidedProduct();
    providedProd.setProductId("provided-product-id-1");
    providedProd.setProductName("provided-product-name-1");
    Set<ProvidedProduct> providedProducts = new HashSet<>();
    providedProducts.add(providedProd);
    source.setProvidedProductDtos(providedProducts);
    ProvidedProduct derivedProvidedProd = new ProvidedProduct();
    derivedProvidedProd.setProductId("derived-provided-product-id-1");
    derivedProvidedProd.setProductName("derived-provided-product-name-1");
    Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
    derivedProvidedProducts.add(derivedProvidedProd);
    source.setDerivedProvidedProductDtos(derivedProvidedProducts);
    Consumer sourceConsumer = new Consumer();
    sourceConsumer.setUuid("source-consumer-uuid");
    SourceStack sourceStack = new SourceStack();
    sourceStack.setSourceStackId("source-stack-source-stack-id-1");
    sourceStack.setId("source-stack-id-1");
    sourceStack.setSourceConsumer(sourceConsumer);
    source.setSourceStack(sourceStack);
    return source;
}
Also used : HashMap(java.util.HashMap) CertificateSerial(org.candlepin.model.CertificateSerial) ProvidedProduct(org.candlepin.model.ProvidedProduct) Product(org.candlepin.model.Product) Branding(org.candlepin.model.Branding) ProvidedProduct(org.candlepin.model.ProvidedProduct) Date(java.util.Date) SourceSubscription(org.candlepin.model.SourceSubscription) Consumer(org.candlepin.model.Consumer) SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Example 4 with SourceSubscription

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

the class PoolTranslatorTest method initSourceObject.

@Override
protected Pool initSourceObject() {
    Pool source = new Pool();
    source.setId("pool-id");
    source.setOwner(this.ownerTranslatorTest.initSourceObject());
    source.setProduct(this.productTranslatorTest.initSourceObject());
    source.setDerivedProduct(this.productTranslatorTest.initSourceObject());
    Set<Branding> brandingSet = new HashSet<>();
    brandingSet.add(this.brandingTranslatorTest.initSourceObject());
    source.setBranding(brandingSet);
    Entitlement entitlement = new Entitlement();
    entitlement.setId("ent-id");
    source.setSourceEntitlement(entitlement);
    SubscriptionsCertificate subCert = new SubscriptionsCertificate();
    subCert.setId("cert-id");
    subCert.setKey("cert-key");
    subCert.setCert("cert-cert");
    subCert.setSerial(new CertificateSerial());
    source.setCertificate(subCert);
    SourceSubscription sourceSubscription = new SourceSubscription();
    sourceSubscription.setId("source-sub-id-1");
    sourceSubscription.setSubscriptionId("source-sub-subscription-id-1");
    sourceSubscription.setSubscriptionSubKey("source-sub-subscription-sub-key-1");
    source.setSourceSubscription(sourceSubscription);
    source.setActiveSubscription(true);
    source.setCreatedByShare(false);
    source.setHasSharedAncestor(true);
    source.setQuantity(1L);
    source.setStartDate(new Date());
    source.setEndDate(new Date());
    Map<String, String> attributes = new HashMap<>();
    attributes.put(Pool.Attributes.SOURCE_POOL_ID, "true");
    source.setAttributes(attributes);
    source.setRestrictedToUsername("restricted-to-username-value");
    source.setContractNumber("333");
    source.setAccountNumber("444");
    source.setOrderNumber("555");
    source.setConsumed(6L);
    source.setExported(7L);
    source.setShared(8L);
    Map<String, String> calculatedAttributes = new HashMap<>();
    calculatedAttributes.put("calc-attribute-key-3", "calc-attribute-value-3");
    calculatedAttributes.put("calc-attribute-key-4", "calc-attribute-value-4");
    source.setCalculatedAttributes(calculatedAttributes);
    source.setUpstreamPoolId("upstream-pool-id-2");
    source.setUpstreamEntitlementId("upstream-entitlement-id-2");
    source.setUpstreamConsumerId("upstream-consumer-id-2");
    source.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    ProvidedProduct providedProd = new ProvidedProduct();
    providedProd.setProductId("provided-product-id-1");
    providedProd.setProductName("provided-product-name-1");
    Set<ProvidedProduct> providedProducts = new HashSet<>();
    providedProducts.add(providedProd);
    source.setProvidedProductDtos(providedProducts);
    ProvidedProduct derivedProvidedProd = new ProvidedProduct();
    derivedProvidedProd.setProductId("derived-provided-product-id-1");
    derivedProvidedProd.setProductName("derived-provided-product-name-1");
    Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
    derivedProvidedProducts.add(derivedProvidedProd);
    source.setDerivedProvidedProductDtos(derivedProvidedProducts);
    Consumer sourceConsumer = new Consumer();
    sourceConsumer.setUuid("source-consumer-uuid");
    SourceStack sourceStack = new SourceStack();
    sourceStack.setSourceStackId("source-stack-source-stack-id-1");
    sourceStack.setId("source-stack-id-1");
    sourceStack.setSourceConsumer(sourceConsumer);
    source.setSourceStack(sourceStack);
    return source;
}
Also used : HashMap(java.util.HashMap) CertificateSerial(org.candlepin.model.CertificateSerial) Branding(org.candlepin.model.Branding) ProvidedProduct(org.candlepin.model.ProvidedProduct) Date(java.util.Date) SourceSubscription(org.candlepin.model.SourceSubscription) Consumer(org.candlepin.model.Consumer) SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Example 5 with SourceSubscription

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

the class EntitlementCertificateGeneratorTest method testNonLazyRegenerate.

@Test
public void testNonLazyRegenerate() throws Exception {
    Owner owner = TestUtil.createOwner("test-owner", "Test Owner");
    Product product = TestUtil.createProduct();
    Pool pool = TestUtil.createPool(owner, product);
    pool.setSourceSubscription(new SourceSubscription("source-sub-id", "master"));
    Map<String, EntitlementCertificate> entCerts = new HashMap<>();
    entCerts.put(pool.getId(), new EntitlementCertificate());
    when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), anyMapOf(String.class, PoolQuantity.class), anyMapOf(String.class, Entitlement.class), anyMapOf(String.class, Product.class), eq(true))).thenReturn(entCerts);
    Consumer consumer = TestUtil.createConsumer(owner);
    Entitlement entitlement = new Entitlement(pool, consumer, owner, 1);
    entitlement.setDirty(true);
    this.ecGenerator.regenerateCertificatesOf(entitlement, false);
    assertFalse(entitlement.isDirty());
    verify(this.mockEntCertAdapter).generateEntitlementCerts(eq(consumer), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor.capture(), eq(true));
    assertEquals(entitlement, this.entMapCaptor.getValue().get(pool.getId()));
    assertEquals(product, this.productMapCaptor.getValue().get(pool.getId()));
    verify(this.mockEventSink, times(1)).queueEvent(any(Event.class));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Event(org.candlepin.audit.Event) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Aggregations

Pool (org.candlepin.model.Pool)31 SourceSubscription (org.candlepin.model.SourceSubscription)31 Product (org.candlepin.model.Product)23 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)19 Owner (org.candlepin.model.Owner)19 Subscription (org.candlepin.model.dto.Subscription)18 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)15 LinkedList (java.util.LinkedList)14 PoolType (org.candlepin.model.Pool.PoolType)10 Entitlement (org.candlepin.model.Entitlement)9 HashSet (java.util.HashSet)8 List (java.util.List)7 Branding (org.candlepin.model.Branding)7 HashMap (java.util.HashMap)6 Consumer (org.candlepin.model.Consumer)6 Matchers.anyList (org.mockito.Matchers.anyList)6 Map (java.util.Map)5 Date (java.util.Date)4 CandlepinQuery (org.candlepin.model.CandlepinQuery)4