Search in sources :

Example 1 with SourceStack

use of org.candlepin.model.SourceStack 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 2 with SourceStack

use of org.candlepin.model.SourceStack 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 3 with SourceStack

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

the class PoolManagerTest method testRefreshPoolsSortsStackDerivedPools.

@SuppressWarnings("rawtypes")
@Test
public void testRefreshPoolsSortsStackDerivedPools() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    // Pool has no subscription ID:
    Product product = TestUtil.createProduct();
    Pool p = TestUtil.createPool(product);
    p.setSourceStack(new SourceStack(new Consumer(), "a"));
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    Owner owner = getOwner();
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(pools);
    when(cqmock.iterator()).thenReturn(pools.iterator());
    when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    ArgumentCaptor<List> poolCaptor = ArgumentCaptor.forClass(List.class);
    verify(this.poolRulesMock).updatePools(poolCaptor.capture(), any(Map.class));
    assertEquals(1, poolCaptor.getValue().size());
    assertEquals(p, poolCaptor.getValue().get(0));
}
Also used : Owner(org.candlepin.model.Owner) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Consumer(org.candlepin.model.Consumer) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with SourceStack

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

the class PoolManagerTest method testIsManaged.

@Test
@Parameters(method = "getParametersForIsManagedTests")
public void testIsManaged(PoolType type, SourceSubscription srcSub, String upstreamPoolId, boolean hosted, boolean expected) {
    Pool pool = TestUtil.createPool(owner, product);
    when(mockConfig.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(!hosted);
    when(mockConfig.getBoolean(eq(ConfigProperties.STANDALONE), anyBoolean())).thenReturn(!hosted);
    pool.setSourceSubscription(srcSub);
    pool.setUpstreamPoolId(upstreamPoolId);
    switch(type) {
        case UNMAPPED_GUEST:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            pool.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
            break;
        case ENTITLEMENT_DERIVED:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            pool.setSourceEntitlement(new Entitlement());
            break;
        case STACK_DERIVED:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            pool.setSourceStack(new SourceStack());
            break;
        case BONUS:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            break;
        case DEVELOPMENT:
            pool.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
            break;
        case NORMAL:
        default:
    }
    boolean output = manager.isManaged(pool);
    assertEquals(expected, output);
}
Also used : SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 5 with SourceStack

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

the class EntitlementResourceTest method getUpstreamCertStackSubPool.

@Test
public void getUpstreamCertStackSubPool() {
    Entitlement parentEnt = TestUtil.createEntitlement();
    parentEnt.setId("parentEnt");
    SubscriptionsCertificate subcert = new SubscriptionsCertificate();
    subcert.setCert("HELLO");
    subcert.setKey("CERT");
    parentEnt.getPool().setCertificate(subcert);
    when(entitlementCurator.findUpstreamEntitlementForStack(consumer, "mystack")).thenReturn(parentEnt);
    String expected = "HELLOCERT";
    // Entitlement from stack sub-pool:
    Entitlement e = TestUtil.createEntitlement();
    e.setId("entitlementID");
    e.getPool().setSourceStack(new SourceStack(consumer, "mystack"));
    when(entitlementCurator.find(eq(e.getId()))).thenReturn(e);
    String result = entResource.getUpstreamCert(e.getId());
    assertEquals(expected, result);
}
Also used : SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) SourceStack(org.candlepin.model.SourceStack) Mockito.anyString(org.mockito.Mockito.anyString) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Aggregations

SourceStack (org.candlepin.model.SourceStack)9 Pool (org.candlepin.model.Pool)7 Entitlement (org.candlepin.model.Entitlement)5 Test (org.junit.Test)5 Consumer (org.candlepin.model.Consumer)4 SourceSubscription (org.candlepin.model.SourceSubscription)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Branding (org.candlepin.model.Branding)3 CertificateSerial (org.candlepin.model.CertificateSerial)3 Owner (org.candlepin.model.Owner)3 Product (org.candlepin.model.Product)3 ProvidedProduct (org.candlepin.model.ProvidedProduct)3 SubscriptionsCertificate (org.candlepin.model.SubscriptionsCertificate)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)2 PoolType (org.candlepin.model.Pool.PoolType)2 Subscription (org.candlepin.model.dto.Subscription)2 LinkedList (java.util.LinkedList)1