@Test public void shouldUpdateWebPushVariantSuccessfully() { final WebPushVariant originalVariant = new WebPushVariant(); final WebPushVariant updatedVariant = new WebPushVariant(); final PushApplication pushApp = new PushApplication(); originalVariant.setPublicKey("test public Key"); updatedVariant.setPublicKey("update public Key"); when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp); when(variantService.findByVariantID("variant-id")).thenReturn(originalVariant); when(validator.validate(updatedVariant)).thenReturn(Collections.EMPTY_SET); final Response response = this.endpoint.updateWebPushVariant("push-app-id", "variant-id", updatedVariant); assertEquals(response.getStatus(), 200); assertTrue(response.getEntity() == originalVariant); assertEquals(originalVariant.getPublicKey(), "update public Key"); verify(variantService).updateVariant(originalVariant); }
@PUT @Path("/{webPushID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateWebPushVariant(@PathParam("pushAppID") String pushApplicationID, @PathParam("webPushID") String webPushID, WebPushVariant updatedVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } var variant = variantService.findByVariantID(webPushID); if (variant != null) { if (!(variant instanceof WebPushVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } WebPushVariant webPushVariant = (WebPushVariant) variant; try { updatedVariant.merge(webPushVariant); validateModelClass(webPushVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update WebPush Variant '{}'", webPushVariant.getVariantID()); logger.debug("Details: {}", cve); Response.ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating WebPush Variant '{}'", webPushID); variantService.updateVariant(webPushVariant); return Response.ok(webPushVariant).build(); } return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); }
WebPushVariantEndpoint extends AbstractVariantEndpoint<WebPushVariant> { @PUT @Path("/{webPushID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateWebPushVariant(@PathParam("pushAppID") String pushApplicationID, @PathParam("webPushID") String webPushID, WebPushVariant updatedVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } var variant = variantService.findByVariantID(webPushID); if (variant != null) { if (!(variant instanceof WebPushVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } WebPushVariant webPushVariant = (WebPushVariant) variant; try { updatedVariant.merge(webPushVariant); validateModelClass(webPushVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update WebPush Variant '{}'", webPushVariant.getVariantID()); logger.debug("Details: {}", cve); Response.ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating WebPush Variant '{}'", webPushID); variantService.updateVariant(webPushVariant); return Response.ok(webPushVariant).build(); } return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } }
WebPushVariantEndpoint extends AbstractVariantEndpoint<WebPushVariant> { @PUT @Path("/{webPushID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateWebPushVariant(@PathParam("pushAppID") String pushApplicationID, @PathParam("webPushID") String webPushID, WebPushVariant updatedVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } var variant = variantService.findByVariantID(webPushID); if (variant != null) { if (!(variant instanceof WebPushVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } WebPushVariant webPushVariant = (WebPushVariant) variant; try { updatedVariant.merge(webPushVariant); validateModelClass(webPushVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update WebPush Variant '{}'", webPushVariant.getVariantID()); logger.debug("Details: {}", cve); Response.ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating WebPush Variant '{}'", webPushID); variantService.updateVariant(webPushVariant); return Response.ok(webPushVariant).build(); } return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } WebPushVariantEndpoint();   WebPushVariantEndpoint(Validator validator, SearchManager searchManager); }
WebPushVariantEndpoint extends AbstractVariantEndpoint<WebPushVariant> { @PUT @Path("/{webPushID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateWebPushVariant(@PathParam("pushAppID") String pushApplicationID, @PathParam("webPushID") String webPushID, WebPushVariant updatedVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } var variant = variantService.findByVariantID(webPushID); if (variant != null) { if (!(variant instanceof WebPushVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } WebPushVariant webPushVariant = (WebPushVariant) variant; try { updatedVariant.merge(webPushVariant); validateModelClass(webPushVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update WebPush Variant '{}'", webPushVariant.getVariantID()); logger.debug("Details: {}", cve); Response.ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating WebPush Variant '{}'", webPushID); variantService.updateVariant(webPushVariant); return Response.ok(webPushVariant).build(); } return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } WebPushVariantEndpoint();   WebPushVariantEndpoint(Validator validator, SearchManager searchManager); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response registerWebPushVariant(
            WebPushVariant webPushVariant,
            @PathParam("pushAppID") String pushApplicationID,
            @Context UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) Response listAllWebPushVariationsForPushApp(@PathParam("pushAppID") String pushApplicationID); @PUT @Path("/{webPushID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateWebPushVariant(@PathParam("pushAppID") String pushApplicationID,
                                         @PathParam("webPushID") String webPushID, WebPushVariant updatedVariant); @PUT @Path("/{variantId}/renew") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response renewKeys(@PathParam("pushAppID") String pushApplicationID,
                                @PathParam("variantId") String variantId); }
WebPushVariantEndpoint extends AbstractVariantEndpoint<WebPushVariant> { @PUT @Path("/{webPushID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateWebPushVariant(@PathParam("pushAppID") String pushApplicationID, @PathParam("webPushID") String webPushID, WebPushVariant updatedVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } var variant = variantService.findByVariantID(webPushID); if (variant != null) { if (!(variant instanceof WebPushVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } WebPushVariant webPushVariant = (WebPushVariant) variant; try { updatedVariant.merge(webPushVariant); validateModelClass(webPushVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update WebPush Variant '{}'", webPushVariant.getVariantID()); logger.debug("Details: {}", cve); Response.ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating WebPush Variant '{}'", webPushID); variantService.updateVariant(webPushVariant); return Response.ok(webPushVariant).build(); } return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } WebPushVariantEndpoint();   WebPushVariantEndpoint(Validator validator, SearchManager searchManager); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response registerWebPushVariant(
            WebPushVariant webPushVariant,
            @PathParam("pushAppID") String pushApplicationID,
            @Context UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) Response listAllWebPushVariationsForPushApp(@PathParam("pushAppID") String pushApplicationID); @PUT @Path("/{webPushID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateWebPushVariant(@PathParam("pushAppID") String pushApplicationID,
                                         @PathParam("webPushID") String webPushID, WebPushVariant updatedVariant); @PUT @Path("/{variantId}/renew") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response renewKeys(@PathParam("pushAppID") String pushApplicationID,
                                @PathParam("variantId") String variantId);  }