Search in sources :

Example 86 with Consumer

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

the class EntitlerTest method testDevPoolCreationAtBindFailStandalone.

@Test(expected = ForbiddenException.class)
public void testDevPoolCreationAtBindFailStandalone() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    devProdDTOs.add(p.toDTO());
    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<>();
    activeList.add(activePool);
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(true);
    when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
    when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
    when(ownerProductCurator.getProductById(eq(owner), eq(p.getId()))).thenReturn(p);
    AutobindData ad = new AutobindData(devSystem, owner);
    entitler.bindByProducts(ad);
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) AutobindData(org.candlepin.resource.dto.AutobindData) Date(java.util.Date) Test(org.junit.Test)

Example 87 with Consumer

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

the class EntitlerTest method nullPool.

@Test(expected = BadRequestException.class)
public void nullPool() throws EntitlementRefusedException {
    String poolid = "foo";
    // keeps me from casting null
    Consumer c = TestUtil.createConsumer();
    Map<String, Integer> pQs = new HashMap<>();
    pQs.put(poolid, 1);
    when(cc.findByUuid(eq(c.getUuid()))).thenReturn(c);
    when(pm.entitleByPools(eq(c), eq(pQs))).thenThrow(new IllegalArgumentException());
    entitler.bindByPoolQuantities(c.getUuid(), pQs);
}
Also used : Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 88 with Consumer

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

the class EntitlerTest method testDevPoolCreationAtBind.

@Test
public void testDevPoolCreationAtBind() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    p.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
    devProdDTOs.add(p.toDTO());
    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<>();
    activeList.add(activePool);
    Pool devPool = mock(Pool.class);
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
    when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
    when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);
    this.mockProducts(owner, p);
    this.mockProductImport(owner, p);
    this.mockContentImport(owner, Collections.<String, Content>emptyMap());
    when(pm.createPool(any(Pool.class))).thenReturn(devPool);
    when(devPool.getId()).thenReturn("test_pool_id");
    AutobindData ad = new AutobindData(devSystem, owner);
    entitler.bindByProducts(ad);
    verify(pm).createPool(any(Pool.class));
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) AutobindData(org.candlepin.resource.dto.AutobindData) Date(java.util.Date) Test(org.junit.Test)

Example 89 with Consumer

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

the class EntitlerTest method testDevPoolCreationAtBindFailNotActive.

@Test(expected = ForbiddenException.class)
public void testDevPoolCreationAtBindFailNotActive() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    devProdDTOs.add(p.toDTO());
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
    when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(false);
    when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
    when(ownerProductCurator.getProductById(eq(owner), eq(p.getId()))).thenReturn(p);
    AutobindData ad = new AutobindData(devSystem, owner);
    entitler.bindByProducts(ad);
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) List(java.util.List) ArrayList(java.util.ArrayList) AutobindData(org.candlepin.resource.dto.AutobindData) Date(java.util.Date) Test(org.junit.Test)

Example 90 with Consumer

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

the class EntitlerTest method testRevokesLapsedUnmappedGuestEntitlementsOnAutoHeal.

@Test
public void testRevokesLapsedUnmappedGuestEntitlementsOnAutoHeal() throws Exception {
    Owner owner1 = new Owner("o1");
    owner1.setId(TestUtil.randomString());
    when(ownerCurator.findOwnerById(eq(owner1.getId()))).thenReturn(owner1);
    Product product = TestUtil.createProduct();
    Pool p1 = TestUtil.createPool(owner1, product);
    p1.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
    Date thirtySixHoursAgo = new Date(new Date().getTime() - 36L * 60L * 60L * 1000L);
    Date twelveHoursAgo = new Date(new Date().getTime() - 12L * 60L * 60L * 1000L);
    Consumer c;
    c = TestUtil.createConsumer(owner1);
    c.setCreated(thirtySixHoursAgo);
    c.setFact("virt.uuid", "1");
    Entitlement e1 = TestUtil.createEntitlement(owner1, c, p1, null);
    e1.setEndDateOverride(twelveHoursAgo);
    Set<Entitlement> entitlementSet1 = new HashSet<>();
    entitlementSet1.add(e1);
    p1.setEntitlements(entitlementSet1);
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.iterator()).thenReturn(Arrays.asList(e1).iterator());
    when(entitlementCurator.findByPoolAttribute(eq(c), eq("unmapped_guests_only"), eq("true"))).thenReturn(cqmock);
    String[] pids = { product.getId(), "prod2" };
    when(cc.findByUuid(eq("abcd1234"))).thenReturn(c);
    entitler.bindByProducts(pids, "abcd1234", null, null);
    AutobindData data = AutobindData.create(c, owner1).forProducts(pids);
    verify(pm).entitleByProducts(eq(data));
    verify(pm).revokeEntitlements(Arrays.asList(e1));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) CandlepinQuery(org.candlepin.model.CandlepinQuery) AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Consumer (org.candlepin.model.Consumer)470 Test (org.junit.Test)345 Entitlement (org.candlepin.model.Entitlement)162 Owner (org.candlepin.model.Owner)126 Pool (org.candlepin.model.Pool)114 Product (org.candlepin.model.Product)112 Date (java.util.Date)102 ConsumerType (org.candlepin.model.ConsumerType)94 LinkedList (java.util.LinkedList)73 ArrayList (java.util.ArrayList)71 HashSet (java.util.HashSet)69 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)69 HashMap (java.util.HashMap)48 ApiOperation (io.swagger.annotations.ApiOperation)43 Produces (javax.ws.rs.Produces)43 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)40 ApiResponses (io.swagger.annotations.ApiResponses)38 GuestId (org.candlepin.model.GuestId)37 Path (javax.ws.rs.Path)36 List (java.util.List)35