Example #1
0
  private Cdn verifyAndLookupCdn(String label) {
    Cdn cdn = curator.lookupByLabel(label);

    if (cdn == null) {
      throw new NotFoundException(i18n.tr("No such content delivery network: {0}", label));
    }
    return cdn;
  }
Example #2
0
 /**
  * Removes a CDN
  *
  * @httpcode 400
  * @httpcode 404
  * @httpcode 200
  */
 @DELETE
 @Produces(MediaType.WILDCARD)
 @Path("/{label}")
 public void delete(@PathParam("label") String label, @Context Principal principal) {
   Cdn cdn = curator.lookupByLabel(label);
   if (cdn != null) {
     curator.delete(cdn);
   }
 }
  @Test
  public void testAsyncExport() {
    CdnCurator mockedCdnCurator = mock(CdnCurator.class);
    ManifestManager manifestManager = mock(ManifestManager.class);
    ConsumerResource cr =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            mockedOwnerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            mockedCdnCurator,
            null,
            null,
            productCurator,
            manifestManager);

    List<KeyValueParameter> extParams = new ArrayList<KeyValueParameter>();
    Owner owner = TestUtil.createOwner();
    Consumer consumer =
        TestUtil.createConsumer(new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN), owner);
    Cdn cdn = new Cdn("cdn-label", "test", "url");

    when(mockedConsumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid())))
        .thenReturn(consumer);
    when(mockedCdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);

    cr.exportDataAsync(null, consumer.getUuid(), cdn.getLabel(), "prefix", cdn.getUrl(), extParams);
    verify(manifestManager)
        .generateManifestAsync(
            eq(consumer.getUuid()),
            eq(cdn.getLabel()),
            eq("prefix"),
            eq(cdn.getUrl()),
            any(Map.class));
  }
Example #4
0
 /**
  * Creates a CDN
  *
  * @return a Cdn object
  * @httpcode 200
  */
 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public Cdn create(Cdn cdn, @Context Principal principal) {
   Cdn existing = curator.lookupByLabel(cdn.getLabel());
   if (existing != null) {
     throw new BadRequestException(
         i18n.tr("A CDN with the label {0}" + "already exists", cdn.getLabel()));
   }
   return curator.create(cdn);
 }