Search in sources :

Example 21 with EntitlementDTO

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

the class EntitlementResourceTest method getAllEntitlementsForConsumer.

@Test
public void getAllEntitlementsForConsumer() {
    PageRequest req = new PageRequest();
    req.setPage(1);
    req.setPerPage(10);
    Owner owner = TestUtil.createOwner();
    Consumer consumer = TestUtil.createConsumer(owner);
    Pool pool = TestUtil.createPool(owner, TestUtil.createProduct());
    Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, null);
    e.setId("getAllEntitlementsForConsumer");
    List<Entitlement> entitlements = new ArrayList<>();
    entitlements.add(e);
    Page<List<Entitlement>> page = new Page<>();
    page.setPageData(entitlements);
    EntitlementDTO entitlementDTO = new EntitlementDTO();
    entitlementDTO.setId("getAllEntitlementsForConsumer");
    when(consumerCurator.findByUuid(eq(consumer.getUuid()))).thenReturn(consumer);
    when(entitlementCurator.listByConsumer(isA(Consumer.class), anyString(), isA(EntitlementFilterBuilder.class), isA(PageRequest.class))).thenReturn(page);
    when(modelTranslator.translate(isA(Entitlement.class), eq(EntitlementDTO.class))).thenReturn(entitlementDTO);
    List<EntitlementDTO> result = entResource.listAllForConsumer(consumer.getUuid(), null, null, req);
    assertEquals(1, result.size());
    assertEquals("getAllEntitlementsForConsumer", result.get(0).getId());
}
Also used : Owner(org.candlepin.model.Owner) EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) ArrayList(java.util.ArrayList) Page(org.candlepin.common.paging.Page) PageRequest(org.candlepin.common.paging.PageRequest) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Aggregations

Entitlement (org.candlepin.model.Entitlement)15 EntitlementDTO (org.candlepin.dto.api.v1.EntitlementDTO)11 ArrayList (java.util.ArrayList)10 List (java.util.List)8 Pool (org.candlepin.model.Pool)8 ConsumerDTO (org.candlepin.dto.rules.v1.ConsumerDTO)7 EntitlementDTO (org.candlepin.dto.rules.v1.EntitlementDTO)7 JsonJsContext (org.candlepin.policy.js.JsonJsContext)7 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Produces (javax.ws.rs.Produces)6 Consumer (org.candlepin.model.Consumer)6 Test (org.junit.Test)6 Path (javax.ws.rs.Path)5 ConsumerType (org.candlepin.model.ConsumerType)5 EntitlementFilterBuilder (org.candlepin.model.EntitlementFilterBuilder)5 Owner (org.candlepin.model.Owner)5 LinkedList (java.util.LinkedList)4 GET (javax.ws.rs.GET)4 RuleExecutionException (org.candlepin.policy.js.RuleExecutionException)4