Search in sources :

Example 16 with PoolDTO

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

the class OwnerResourceTest method testCanFilterPoolsByAttribute.

@Test
public void testCanFilterPoolsByAttribute() throws Exception {
    Principal principal = setupPrincipal(owner, Access.ALL);
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    pool1.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    poolCurator.create(pool1);
    Product p2 = this.createProduct(owner);
    p2.setAttribute(Product.Attributes.CORES, "12");
    productCurator.merge(p2);
    Pool pool2 = TestUtil.createPool(owner, p2);
    poolCurator.create(pool2);
    List<KeyValueParameter> params = new ArrayList<>();
    params.add(createKeyValueParam("cores", "12"));
    List<PoolDTO> pools = ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, params, false, false, null, null, principal, null);
    assertEquals(1, pools.size());
    assertModelEqualsDTO(pool2, pools.get(0));
    params.clear();
    params.add(createKeyValueParam("virt_only", "true"));
    pools = ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, params, false, false, null, null, principal, null);
    assertEquals(1, pools.size());
    assertModelEqualsDTO(pool1, pools.get(0));
}
Also used : ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 17 with PoolDTO

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

the class OwnerResourceTest method cantUpdateBonusPool.

@Test(expected = BadRequestException.class)
public void cantUpdateBonusPool() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "3");
    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);
    ownerResource.createPool(owner.getKey(), poolDto);
    List<Pool> pools = poolCurator.listByOwner(owner).list();
    Pool bonusPool = null;
    for (Pool p : pools) {
        if (p.getSubscriptionSubKey().contentEquals("derived")) {
            bonusPool = p;
        }
    }
    assertNotNull(bonusPool);
    poolDto = this.modelTranslator.translate(bonusPool, PoolDTO.class);
    ownerResource.updatePool(owner.getKey(), poolDto);
}
Also used : Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 18 with PoolDTO

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

the class OwnerResourceTest method createPool.

@Test
public void createPool() {
    Product prod = this.createProduct(owner);
    Pool pool = TestUtil.createPool(owner, prod);
    PoolDTO poolDto = this.modelTranslator.translate(pool, PoolDTO.class);
    assertEquals(0, poolCurator.listByOwner(owner).list().size());
    PoolDTO createdPoolDto = ownerResource.createPool(owner.getKey(), poolDto);
    assertEquals(1, poolCurator.listByOwner(owner).list().size());
    assertNotNull(createdPoolDto.getId());
}
Also used : Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 19 with PoolDTO

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

the class OwnerResourceTest method createBonusPoolForUpdate.

@Test
public void createBonusPoolForUpdate() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "3");
    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);
    poolDto.setQuantity(100L);
    ownerResource.updatePool(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"));
    assertEquals(100L, pools.get(0).getQuantity().longValue());
    assertEquals(300L, pools.get(1).getQuantity().longValue());
}
Also used : Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 20 with PoolDTO

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

the class PoolResourceTest method testCalculatedAttributesEmpty.

@Test
public void testCalculatedAttributesEmpty() {
    PoolDTO p = poolResource.getPool(pool1.getId(), null, null, adminPrincipal);
    assertTrue(p.getCalculatedAttributes().isEmpty());
}
Also used : PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Test(org.junit.Test)

Aggregations

PoolDTO (org.candlepin.dto.api.v1.PoolDTO)19 Pool (org.candlepin.model.Pool)19 Test (org.junit.Test)16 Product (org.candlepin.model.Product)15 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