@Test public void shouldUpdateiOSTokenVariantSuccessfully_withMultiPartData() { final iOSTokenVariant original = new iOSTokenVariant(); final iOSTokenVariant update = new iOSTokenVariant(); final PushApplication pushApp = new PushApplication(); update.setName("variant name"); update.setPrivateKey("privateKey"); update.setProduction(false); when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp); when(variantService.findByVariantID("variant-id")).thenReturn(original); when(validator.validate(update)).thenReturn(Collections.EMPTY_SET); when(validator.validate(original)).thenReturn(Collections.EMPTY_SET); final Response response = this.endpoint.updateiOSVariant(update, "push-app-id", "variant-id"); assertEquals(response.getStatus(), 200); assertEquals(original.getName(), "variant name"); verify(variantService).updateVariant(original); verify(producer).changeAPNClient(original); }
@PATCH @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateiOSVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("iOSID") String iOSID, iOSTokenVariant updatediOSVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationId); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } iOSTokenVariant iOSTokenVariant = (iOSTokenVariant) variantService.findByVariantID(iOSID); if (iOSTokenVariant != null) { try { updatediOSVariant.merge(iOSTokenVariant); validateModelClass(iOSTokenVariant); } catch (ConstraintViolationException cve) { ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating text details on iOS Variant '{}'", iOSID); variantService.updateVariant(iOSTokenVariant); return Response.noContent().build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); }
iOSTokenVariantEndpoint extends AbstractVariantEndpoint<iOSTokenVariant> { @PATCH @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateiOSVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("iOSID") String iOSID, iOSTokenVariant updatediOSVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationId); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } iOSTokenVariant iOSTokenVariant = (iOSTokenVariant) variantService.findByVariantID(iOSID); if (iOSTokenVariant != null) { try { updatediOSVariant.merge(iOSTokenVariant); validateModelClass(iOSTokenVariant); } catch (ConstraintViolationException cve) { ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating text details on iOS Variant '{}'", iOSID); variantService.updateVariant(iOSTokenVariant); return Response.noContent().build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } }
iOSTokenVariantEndpoint extends AbstractVariantEndpoint<iOSTokenVariant> { @PATCH @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateiOSVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("iOSID") String iOSID, iOSTokenVariant updatediOSVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationId); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } iOSTokenVariant iOSTokenVariant = (iOSTokenVariant) variantService.findByVariantID(iOSID); if (iOSTokenVariant != null) { try { updatediOSVariant.merge(iOSTokenVariant); validateModelClass(iOSTokenVariant); } catch (ConstraintViolationException cve) { ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating text details on iOS Variant '{}'", iOSID); variantService.updateVariant(iOSTokenVariant); return Response.noContent().build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } iOSTokenVariantEndpoint();   iOSTokenVariantEndpoint(Validator validator, SearchManager searchManager); }
iOSTokenVariantEndpoint extends AbstractVariantEndpoint<iOSTokenVariant> { @PATCH @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateiOSVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("iOSID") String iOSID, iOSTokenVariant updatediOSVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationId); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } iOSTokenVariant iOSTokenVariant = (iOSTokenVariant) variantService.findByVariantID(iOSID); if (iOSTokenVariant != null) { try { updatediOSVariant.merge(iOSTokenVariant); validateModelClass(iOSTokenVariant); } catch (ConstraintViolationException cve) { ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating text details on iOS Variant '{}'", iOSID); variantService.updateVariant(iOSTokenVariant); return Response.noContent().build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } iOSTokenVariantEndpoint();   iOSTokenVariantEndpoint(Validator validator, SearchManager searchManager); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response registeriOSVariant(
            iOSTokenVariant iOSVariant,
            @PathParam("pushAppID") String pushApplicationID,
            @Context UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) Response listAlliOSVariantsForPushApp(@PathParam("pushAppID") String pushApplicationID); @PATCH @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateiOSVariant(
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID,
            iOSTokenVariant updatediOSVariant); @PUT @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateiOSVariant(
            iOSTokenVariant updatediOSVariant,
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID); }
iOSTokenVariantEndpoint extends AbstractVariantEndpoint<iOSTokenVariant> { @PATCH @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateiOSVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("iOSID") String iOSID, iOSTokenVariant updatediOSVariant) { final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationId); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } iOSTokenVariant iOSTokenVariant = (iOSTokenVariant) variantService.findByVariantID(iOSID); if (iOSTokenVariant != null) { try { updatediOSVariant.merge(iOSTokenVariant); validateModelClass(iOSTokenVariant); } catch (ConstraintViolationException cve) { ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating text details on iOS Variant '{}'", iOSID); variantService.updateVariant(iOSTokenVariant); return Response.noContent().build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } iOSTokenVariantEndpoint();   iOSTokenVariantEndpoint(Validator validator, SearchManager searchManager); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response registeriOSVariant(
            iOSTokenVariant iOSVariant,
            @PathParam("pushAppID") String pushApplicationID,
            @Context UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) Response listAlliOSVariantsForPushApp(@PathParam("pushAppID") String pushApplicationID); @PATCH @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateiOSVariant(
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID,
            iOSTokenVariant updatediOSVariant); @PUT @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateiOSVariant(
            iOSTokenVariant updatediOSVariant,
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID);  }