Search in sources :

Example 1 with UpstreamConsumerDTO

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

the class OwnerResourceTest method upstreamConsumers.

@Test
public void upstreamConsumers() {
    Principal p = mock(Principal.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    UpstreamConsumer upstream = mock(UpstreamConsumer.class);
    Owner owner = mock(Owner.class);
    OwnerResource ownerres = new OwnerResource(oc, pc, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
    when(oc.lookupByKey(eq("admin"))).thenReturn(owner);
    when(owner.getUpstreamConsumer()).thenReturn(upstream);
    List<UpstreamConsumerDTO> results = ownerres.getUpstreamConsumers(p, "admin");
    assertNotNull(results);
    assertEquals(1, results.size());
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) ProductCurator(org.candlepin.model.ProductCurator) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 2 with UpstreamConsumerDTO

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

the class OwnerResource method getUpstreamConsumers.

/**
 * Retrieves a list of Upstream Consumers for an Owner
 *
 * @return a list of UpstreamConsumer objects
 * @httpcode 404
 * @httpcode 200
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/upstream_consumers")
@ApiOperation(notes = " Retrieves a list of Upstream Consumers for an Owner", value = "Get Upstream Consumers")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public List<UpstreamConsumerDTO> getUpstreamConsumers(@Context Principal principal, @Verify(Owner.class) @PathParam("owner_key") String ownerKey) {
    Owner owner = this.findOwnerByKey(ownerKey);
    UpstreamConsumer consumer = owner.getUpstreamConsumer();
    UpstreamConsumerDTO dto = this.translator.translate(consumer, UpstreamConsumerDTO.class);
    // when multiples are supported.
    return Arrays.asList(dto);
}
Also used : Owner(org.candlepin.model.Owner) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

UpstreamConsumerDTO (org.candlepin.dto.api.v1.UpstreamConsumerDTO)2 Owner (org.candlepin.model.Owner)2 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)1 Principal (org.candlepin.auth.Principal)1 UserPrincipal (org.candlepin.auth.UserPrincipal)1 OwnerCurator (org.candlepin.model.OwnerCurator)1 ProductCurator (org.candlepin.model.ProductCurator)1 Test (org.junit.Test)1