Search in sources :

Example 11 with PoolDTO

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

the class OwnerResourceTest method testOwnerAdminCanGetPools.

@Test
public void testOwnerAdminCanGetPools() {
    Principal principal = setupPrincipal(owner, Access.ALL);
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    Pool pool2 = TestUtil.createPool(owner, p);
    poolCurator.create(pool1);
    poolCurator.create(pool2);
    List<PoolDTO> pools = ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, new ArrayList<>(), false, false, null, null, principal, null);
    assertEquals(2, pools.size());
}
Also used : Product(org.candlepin.model.Product) 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 12 with PoolDTO

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

the class OwnerResourceTest method consumerListPoolsGetCalculatedAttributes.

@Test
public void consumerListPoolsGetCalculatedAttributes() {
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    poolCurator.create(pool1);
    Consumer c = this.createConsumer(owner);
    Principal principal = setupPrincipal(new ConsumerPrincipal(c, owner));
    securityInterceptor.enable();
    List<PoolDTO> pools = ownerResource.listPools(owner.getKey(), c.getUuid(), null, p.getId(), null, true, null, null, new ArrayList<>(), false, false, null, null, principal, null);
    assertEquals(1, pools.size());
    PoolDTO returnedPool = pools.get(0);
    assertNotNull(returnedPool.getCalculatedAttributes());
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 13 with PoolDTO

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

the class OwnerResourceTest method testUnmappedGuestConsumerCanListPoolsForFuture.

@Test
public void testUnmappedGuestConsumerCanListPoolsForFuture() {
    Consumer c = this.createConsumer(owner);
    c.setFact("virt.is_guest", "true");
    c.setFact("virt.uuid", "system_uuid");
    consumerCurator.merge(c);
    Principal principal = setupPrincipal(new ConsumerPrincipal(c, owner));
    securityInterceptor.enable();
    Date now = new Date();
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    pool1.setAttribute(Pool.Attributes.VIRT_ONLY, "true");
    pool1.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    pool1.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "false");
    pool1.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
    pool1.setStartDate(now);
    pool1.setEndDate(new Date(now.getTime() + 1000L * 60 * 60 * 24 * 365));
    Pool pool2 = TestUtil.createPool(owner, p);
    pool2.setAttribute(Pool.Attributes.VIRT_ONLY, "true");
    pool2.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    pool2.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "false");
    pool2.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
    pool2.setStartDate(new Date(now.getTime() + 2 * 1000L * 60 * 60 * 24 * 365));
    pool2.setEndDate(new Date(now.getTime() + 3 * 1000L * 60 * 60 * 24 * 365));
    poolCurator.create(pool1);
    poolCurator.create(pool2);
    List<PoolDTO> nowList = ownerResource.listPools(owner.getKey(), c.getUuid(), null, null, null, false, new Date(), null, new ArrayList<>(), false, false, null, null, principal, null);
    assertEquals(1, nowList.size());
    assert (nowList.get(0).getId().equals(pool1.getId()));
    Date activeOn = new Date(pool2.getStartDate().getTime() + 1000L * 60 * 60 * 24);
    List<PoolDTO> futureList = ownerResource.listPools(owner.getKey(), c.getUuid(), null, null, null, false, activeOn, null, new ArrayList<>(), false, false, null, null, principal, null);
    assertEquals(1, futureList.size());
    assert (futureList.get(0).getId().equals(pool2.getId()));
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Date(java.util.Date) Test(org.junit.Test)

Example 14 with PoolDTO

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

the class OwnerResourceTest method updatePool.

@Test
public void updatePool() {
    Product prod = this.createProduct(owner);
    Pool pool = TestUtil.createPool(owner, prod);
    pool.setSubscriptionSubKey("master");
    PoolDTO poolDto = this.modelTranslator.translate(pool, PoolDTO.class);
    poolDto = ownerResource.createPool(owner.getKey(), poolDto);
    List<Pool> createdPools = poolCurator.listByOwner(owner).list();
    assertEquals(1, createdPools.size());
    assertEquals(pool.getQuantity(), createdPools.get(0).getQuantity());
    poolDto.setQuantity(10L);
    ownerResource.updatePool(owner.getKey(), poolDto);
    List<Pool> updatedPools = poolCurator.listByOwner(owner).list();
    assertEquals(1, updatedPools.size());
    assertEquals(10L, updatedPools.get(0).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 15 with PoolDTO

use of org.candlepin.dto.manifest.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)

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