@Test public void registerAndroidVariantShouldReturn400WhenVariantModelIsNotValid() { final AndroidVariant variant = new AndroidVariant(); final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http: final PushApplication pushApp = new PushApplication(); when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp); when(validator.validate(variant)).thenReturn(Sets.newHashSet(sampleViolation)); final Response response = this.endpoint.registerAndroidVariant(variant, "push-app-id", uriInfo); assertEquals(response.getStatus(), 400); verify(variantService, never()).addVariant(variant); verify(pushAppService, never()).addVariant(pushApp, variant); }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registerAndroidVariant( AndroidVariant androidVariant, @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(androidVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create Android variant"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register Android variant with Push Application '{}'", pushApplicationID); variantService.addVariant(androidVariant); pushAppService.addVariant(pushApp, androidVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(androidVariant.getVariantID())).build()).entity(androidVariant).build(); }
AndroidVariantEndpoint extends AbstractVariantEndpoint<AndroidVariant> { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registerAndroidVariant( AndroidVariant androidVariant, @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(androidVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create Android variant"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register Android variant with Push Application '{}'", pushApplicationID); variantService.addVariant(androidVariant); pushAppService.addVariant(pushApp, androidVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(androidVariant.getVariantID())).build()).entity(androidVariant).build(); } }
AndroidVariantEndpoint extends AbstractVariantEndpoint<AndroidVariant> { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registerAndroidVariant( AndroidVariant androidVariant, @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(androidVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create Android variant"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register Android variant with Push Application '{}'", pushApplicationID); variantService.addVariant(androidVariant); pushAppService.addVariant(pushApp, androidVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(androidVariant.getVariantID())).build()).entity(androidVariant).build(); } AndroidVariantEndpoint();   AndroidVariantEndpoint(Validator validator, SearchManager searchManager); }
AndroidVariantEndpoint extends AbstractVariantEndpoint<AndroidVariant> { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registerAndroidVariant( AndroidVariant androidVariant, @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(androidVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create Android variant"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register Android variant with Push Application '{}'", pushApplicationID); variantService.addVariant(androidVariant); pushAppService.addVariant(pushApp, androidVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(androidVariant.getVariantID())).build()).entity(androidVariant).build(); } AndroidVariantEndpoint();   AndroidVariantEndpoint(Validator validator, SearchManager searchManager); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response registerAndroidVariant(
            AndroidVariant androidVariant,
            @PathParam("pushAppID") String pushApplicationID,
            @Context UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) Response listAllAndroidVariationsForPushApp(@PathParam("pushAppID") String pushApplicationID); @PUT @Path("/{androidID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateAndroidVariant(
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("androidID") String androidID,
            AndroidVariant updatedAndroidApplication); }
AndroidVariantEndpoint extends AbstractVariantEndpoint<AndroidVariant> { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registerAndroidVariant( AndroidVariant androidVariant, @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(androidVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create Android variant"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register Android variant with Push Application '{}'", pushApplicationID); variantService.addVariant(androidVariant); pushAppService.addVariant(pushApp, androidVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(androidVariant.getVariantID())).build()).entity(androidVariant).build(); } AndroidVariantEndpoint();   AndroidVariantEndpoint(Validator validator, SearchManager searchManager); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response registerAndroidVariant(
            AndroidVariant androidVariant,
            @PathParam("pushAppID") String pushApplicationID,
            @Context UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) Response listAllAndroidVariationsForPushApp(@PathParam("pushAppID") String pushApplicationID); @PUT @Path("/{androidID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateAndroidVariant(
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("androidID") String androidID,
            AndroidVariant updatedAndroidApplication);  }