@Test public void shouldRegisteriOSVariantSuccessfully() { final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http: final PushApplication pushApp = new PushApplication(); final iOSApplicationUploadForm form = new iOSApplicationUploadForm(); form.setName("variant name"); form.setCertificate("certificate".getBytes()); form.setProduction(false); when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp); when(validator.validate(form)).thenReturn(Collections.EMPTY_SET); final Response response = this.endpoint.registeriOSVariant(form, "push-app-id", uriInfo); assertEquals(response.getStatus(), 201); final iOSVariant createdVariant = (iOSVariant) response.getEntity(); assertEquals(createdVariant.getName(), "variant name"); assertEquals(response.getMetadata().get("location").get(0).toString(), "http: verify(variantService).addVariant(createdVariant); verify(pushAppService).addVariant(pushApp, createdVariant); }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registeriOSVariant( iOSApplicationUploadForm form, @PathParam("pushAppID") String pushApplicationID, @Context UriInfo uriInfo) { PushApplication pushApp = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (pushApp == null) { return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } try { validateModelClass(form); } catch (ConstraintViolationException cve) { logger.trace("Unable to validate given form upload"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } iOSVariant iOSVariant = new iOSVariant(); iOSVariant.setName(form.getName()); iOSVariant.setDescription(form.getDescription()); iOSVariant.setPassphrase(form.getPassphrase()); iOSVariant.setCertificate(form.getCertificate()); iOSVariant.setProduction(form.getProduction()); iOSVariant.setVariantID(form.getVariantID()); iOSVariant.setSecret(form.getSecret()); try { validateModelClass(iOSVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create iOS variant entity"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register iOS variant with Push Application '{}'", pushApplicationID); variantService.addVariant(iOSVariant); pushAppService.addVariant(pushApp, iOSVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(iOSVariant.getVariantID())).build()).entity(iOSVariant).build(); }
iOSVariantEndpoint extends AbstractVariantEndpoint<iOSVariant> { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registeriOSVariant( iOSApplicationUploadForm form, @PathParam("pushAppID") String pushApplicationID, @Context UriInfo uriInfo) { PushApplication pushApp = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (pushApp == null) { return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } try { validateModelClass(form); } catch (ConstraintViolationException cve) { logger.trace("Unable to validate given form upload"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } iOSVariant iOSVariant = new iOSVariant(); iOSVariant.setName(form.getName()); iOSVariant.setDescription(form.getDescription()); iOSVariant.setPassphrase(form.getPassphrase()); iOSVariant.setCertificate(form.getCertificate()); iOSVariant.setProduction(form.getProduction()); iOSVariant.setVariantID(form.getVariantID()); iOSVariant.setSecret(form.getSecret()); try { validateModelClass(iOSVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create iOS variant entity"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register iOS variant with Push Application '{}'", pushApplicationID); variantService.addVariant(iOSVariant); pushAppService.addVariant(pushApp, iOSVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(iOSVariant.getVariantID())).build()).entity(iOSVariant).build(); } }
iOSVariantEndpoint extends AbstractVariantEndpoint<iOSVariant> { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registeriOSVariant( iOSApplicationUploadForm form, @PathParam("pushAppID") String pushApplicationID, @Context UriInfo uriInfo) { PushApplication pushApp = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (pushApp == null) { return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } try { validateModelClass(form); } catch (ConstraintViolationException cve) { logger.trace("Unable to validate given form upload"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } iOSVariant iOSVariant = new iOSVariant(); iOSVariant.setName(form.getName()); iOSVariant.setDescription(form.getDescription()); iOSVariant.setPassphrase(form.getPassphrase()); iOSVariant.setCertificate(form.getCertificate()); iOSVariant.setProduction(form.getProduction()); iOSVariant.setVariantID(form.getVariantID()); iOSVariant.setSecret(form.getSecret()); try { validateModelClass(iOSVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create iOS variant entity"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register iOS variant with Push Application '{}'", pushApplicationID); variantService.addVariant(iOSVariant); pushAppService.addVariant(pushApp, iOSVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(iOSVariant.getVariantID())).build()).entity(iOSVariant).build(); } iOSVariantEndpoint();   iOSVariantEndpoint(Validator validator, SearchManager searchManager); }
iOSVariantEndpoint extends AbstractVariantEndpoint<iOSVariant> { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registeriOSVariant( iOSApplicationUploadForm form, @PathParam("pushAppID") String pushApplicationID, @Context UriInfo uriInfo) { PushApplication pushApp = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (pushApp == null) { return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } try { validateModelClass(form); } catch (ConstraintViolationException cve) { logger.trace("Unable to validate given form upload"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } iOSVariant iOSVariant = new iOSVariant(); iOSVariant.setName(form.getName()); iOSVariant.setDescription(form.getDescription()); iOSVariant.setPassphrase(form.getPassphrase()); iOSVariant.setCertificate(form.getCertificate()); iOSVariant.setProduction(form.getProduction()); iOSVariant.setVariantID(form.getVariantID()); iOSVariant.setSecret(form.getSecret()); try { validateModelClass(iOSVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create iOS variant entity"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register iOS variant with Push Application '{}'", pushApplicationID); variantService.addVariant(iOSVariant); pushAppService.addVariant(pushApp, iOSVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(iOSVariant.getVariantID())).build()).entity(iOSVariant).build(); } iOSVariantEndpoint();   iOSVariantEndpoint(Validator validator, SearchManager searchManager); @POST @Deprecated @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) Response registeriOSVariantMultipart(
            @MultipartForm iOSApplicationUploadForm form,
            @PathParam("pushAppID") String pushApplicationID,
            @Context UriInfo uriInfo); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response registeriOSVariant(
            iOSApplicationUploadForm form,
            @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,
            iOSVariant updatediOSVariant); @PUT @Path("/{iOSID}") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) @Deprecated Response updateiOSVariantMultipart(
            @MultipartForm iOSApplicationUploadForm updatedForm,
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID); @PUT @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateiOSVariant(
            iOSApplicationUploadForm updatedForm,
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID); }
iOSVariantEndpoint extends AbstractVariantEndpoint<iOSVariant> { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registeriOSVariant( iOSApplicationUploadForm form, @PathParam("pushAppID") String pushApplicationID, @Context UriInfo uriInfo) { PushApplication pushApp = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (pushApp == null) { return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } try { validateModelClass(form); } catch (ConstraintViolationException cve) { logger.trace("Unable to validate given form upload"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } iOSVariant iOSVariant = new iOSVariant(); iOSVariant.setName(form.getName()); iOSVariant.setDescription(form.getDescription()); iOSVariant.setPassphrase(form.getPassphrase()); iOSVariant.setCertificate(form.getCertificate()); iOSVariant.setProduction(form.getProduction()); iOSVariant.setVariantID(form.getVariantID()); iOSVariant.setSecret(form.getSecret()); try { validateModelClass(iOSVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create iOS variant entity"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register iOS variant with Push Application '{}'", pushApplicationID); variantService.addVariant(iOSVariant); pushAppService.addVariant(pushApp, iOSVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(iOSVariant.getVariantID())).build()).entity(iOSVariant).build(); } iOSVariantEndpoint();   iOSVariantEndpoint(Validator validator, SearchManager searchManager); @POST @Deprecated @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) Response registeriOSVariantMultipart(
            @MultipartForm iOSApplicationUploadForm form,
            @PathParam("pushAppID") String pushApplicationID,
            @Context UriInfo uriInfo); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response registeriOSVariant(
            iOSApplicationUploadForm form,
            @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,
            iOSVariant updatediOSVariant); @PUT @Path("/{iOSID}") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) @Deprecated Response updateiOSVariantMultipart(
            @MultipartForm iOSApplicationUploadForm updatedForm,
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID); @PUT @Path("/{iOSID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateiOSVariant(
            iOSApplicationUploadForm updatedForm,
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("iOSID") String iOSID);  }