SubscriptionResource { @ApiOperation(notes = "Activates a Subscription", value = "activateSubscription") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 503, message = ""), @ApiResponse(code = 202, message = "") }) @POST @Produces(MediaType.WILDCARD) @Consumes(MediaType.WILDCARD) public Response activateSubscription( @ApiParam(required = true) @QueryParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @ApiParam(required = true) @QueryParam("email") String email, @ApiParam(required = true) @QueryParam("email_locale") String emailLocale) { if (email == null) { throw new BadRequestException(i18n.tr("email is required for notification")); } if (emailLocale == null) { throw new BadRequestException(i18n.tr("email locale is required for notification")); } Consumer consumer = consumerCurator.findByUuid(consumerUuid); if (consumer == null) { throw new BadRequestException(i18n.tr("No such unit: {0}", consumerUuid)); } this.subService.activateSubscription(consumer, email, emailLocale); return Response.status(Status.ACCEPTED).build(); } @Inject  SubscriptionResource(SubscriptionServiceAdapter subService,
        ConsumerCurator consumerCurator, PoolManager poolManager, I18n i18n); @ApiOperation(notes = "Retrieves a list of Subscriptions", value = "getSubscriptions") @GET @Produces(MediaType.APPLICATION_JSON) List<Subscription> getSubscriptions(); @ApiOperation(notes = "Retrieves a single Subscription", value = "getSubscription") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @GET @Path("/{subscription_id}") @Produces(MediaType.APPLICATION_JSON) Subscription getSubscription(@PathParam("subscription_id") String subscriptionId); @ApiOperation(notes = "Retrieves a Subscription Certificate As a PEM", value = "getSubCertAsPem") @DoNotUseJAXBProvider @GET @Path("{subscription_id}/cert") // cpc passes up content-type on all calls, make sure we don't 415 it @Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON}) @Produces({ MediaType.TEXT_PLAIN }) String getSubCertAsPem(
        @PathParam("subscription_id") String subscriptionId); @ApiOperation(notes = "Retrieves a Subscription Certificate", value = "getSubCert") @GET @Path("{subscription_id}/cert") @Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON}) CertificateDTO getSubCert(
        @PathParam("subscription_id") String subscriptionId); @ApiOperation(notes = "Activates a Subscription", value = "activateSubscription") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 503, message = ""), @ApiResponse(code = 202, message = "") }) @POST @Produces(MediaType.WILDCARD) @Consumes(MediaType.WILDCARD) Response activateSubscription(
        @ApiParam(required = true) @QueryParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @ApiParam(required = true) @QueryParam("email") String email,
        @ApiParam(required = true) @QueryParam("email_locale") String emailLocale); @ApiOperation(notes = "Removes a Subscription", value = "deleteSubscription") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @DELETE @Path("/{subscription_id}") @Produces(MediaType.APPLICATION_JSON) void deleteSubscription(@PathParam("subscription_id") String subscriptionId);  }
@Test public void activateNoEmail() { assertThrows(BadRequestException.class, () -> subResource.activateSubscription("random", null, "en_us")); }
@Test public void activateNoEmailLocale() { assertThrows(BadRequestException.class, () -> subResource.activateSubscription("random", "random@somthing.com", null)); }
@Test public void activateBadConsumer() { assertThrows(BadRequestException.class, () -> subResource.activateSubscription("test_consumer", "email@whatever.net", "en_us")); }
@Test public void activateSubServiceCalled() { Consumer consumer = new Consumer("test_consumer", "alf", null, null); when(consumerCurator.findByUuid("ae843603bdc73")).thenReturn(consumer); subResource.activateSubscription("ae843603bdc73", "alf@alfnet.com", "en"); verify(subService).activateSubscription(consumer, "alf@alfnet.com", "en"); }
@Test public void activateCorrectResponseCode() { Consumer consumer = new Consumer("test_consumer", "alf", null, null); when(consumerCurator.findByUuid("ae843603bdc73")).thenReturn(consumer); Response result = subResource.activateSubscription("ae843603bdc73", "alf@alfnet.com", "en"); assertEquals(result.getStatus(), 202); }