Search in sources :

Example 1 with PoolDTO

use of org.candlepin.dto.manifest.v1.PoolDTO in project candlepin by candlepin.

the class OwnerResourceTest method removePoolsForExpiredUpdate.

@Test
public void removePoolsForExpiredUpdate() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "3");
    prod = productCurator.merge(prod);
    Pool pool = TestUtil.createPool(owner, prod);
    pool.setUpstreamPoolId("upstream-" + pool.getId());
    pool.setSubscriptionSubKey("master");
    PoolDTO poolDto = this.modelTranslator.translate(pool, PoolDTO.class);
    poolDto = ownerResource.createPool(owner.getKey(), poolDto);
    List<Pool> pools = poolCurator.listByOwner(owner).list();
    assertEquals(2, pools.size());
    poolDto.setStartDate(new Date(System.currentTimeMillis() - 5 * 24 * 60 * 60 * 1000));
    poolDto.setEndDate(new Date(System.currentTimeMillis() - 3 * 24 * 60 * 60 * 1000));
    ownerResource.updatePool(owner.getKey(), poolDto);
    pools = poolCurator.listByOwner(owner).list();
    assertEquals(0, pools.size());
}
Also used : Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) Date(java.util.Date) Test(org.junit.Test)

Example 2 with PoolDTO

use of org.candlepin.dto.manifest.v1.PoolDTO in project candlepin by candlepin.

the class OwnerResourceTest method createBonusPool.

@Test
public void createBonusPool() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "2");
    productCurator.merge(prod);
    Pool pool = TestUtil.createPool(owner, prod);
    pool.setUpstreamPoolId("upstream-" + pool.getId());
    assertEquals(0, poolCurator.listByOwner(owner).list().size());
    PoolDTO poolDto = this.modelTranslator.translate(pool, PoolDTO.class);
    ownerResource.createPool(owner.getKey(), poolDto);
    List<Pool> pools = poolCurator.listByOwner(owner).list();
    assertEquals(2, pools.size());
    assertTrue(pools.get(0).getSubscriptionSubKey().startsWith("master") || pools.get(1).getSubscriptionSubKey().startsWith("master"));
    assertTrue(pools.get(0).getSubscriptionSubKey().equals("derived") || pools.get(1).getSubscriptionSubKey().equals("derived"));
}
Also used : Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 3 with PoolDTO

use of org.candlepin.dto.manifest.v1.PoolDTO 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 4 with PoolDTO

use of org.candlepin.dto.manifest.v1.PoolDTO in project candlepin by candlepin.

the class PoolResourceTest method ownerAdminCannotListAnotherOwnersPools.

@Test(expected = NotFoundException.class)
public void ownerAdminCannotListAnotherOwnersPools() {
    List<PoolDTO> pools = poolResource.list(owner1.getId(), null, null, false, null, adminPrincipal, null);
    assertEquals(2, pools.size());
    Principal anotherPrincipal = setupPrincipal(owner2, Access.ALL);
    securityInterceptor.enable();
    poolResource.list(owner1.getId(), null, null, false, null, anotherPrincipal, null);
}
Also used : PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Principal(org.candlepin.auth.Principal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 5 with PoolDTO

use of org.candlepin.dto.manifest.v1.PoolDTO in project candlepin by candlepin.

the class OwnerResourceTest method enrichPool.

@Test
public void enrichPool() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    prod.setMultiplier(2L);
    productCurator.merge(prod);
    Pool pool = TestUtil.createPool(owner, prod);
    pool.setQuantity(100L);
    assertEquals(0, poolCurator.listByOwner(owner).list().size());
    PoolDTO poolDto = this.modelTranslator.translate(pool, PoolDTO.class);
    ownerResource.createPool(owner.getKey(), poolDto);
    List<Pool> pools = poolCurator.listByOwner(owner).list();
    assertEquals(1, pools.size());
    assertTrue(Boolean.parseBoolean(pools.get(0).getAttributeValue(Product.Attributes.VIRT_ONLY)));
    assertEquals(200L, pools.get(0).getQuantity().intValue());
}
Also used : Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Aggregations

PoolDTO (org.candlepin.dto.api.v1.PoolDTO)19 Pool (org.candlepin.model.Pool)18 Test (org.junit.Test)16 Product (org.candlepin.model.Product)14 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)8 Principal (org.candlepin.auth.Principal)8 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 UserPrincipal (org.candlepin.auth.UserPrincipal)5 HashSet (java.util.HashSet)3 Map (java.util.Map)3 ConsumerDTO (org.candlepin.dto.rules.v1.ConsumerDTO)3 PoolDTO (org.candlepin.dto.rules.v1.PoolDTO)3 Branding (org.candlepin.model.Branding)3 Consumer (org.candlepin.model.Consumer)3 Owner (org.candlepin.model.Owner)3 JsonJsContext (org.candlepin.policy.js.JsonJsContext)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2