@Test public void shouldUpdateAndroidVariantSuccessfully() { final AndroidVariant originalVariant = new AndroidVariant(); final AndroidVariant updatedVariant = new AndroidVariant(); final PushApplication pushApp = new PushApplication(); originalVariant.setGoogleKey("Original Google Key"); updatedVariant.setGoogleKey("Updated Google 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.updateAndroidVariant("push-app-id", "variant-id", updatedVariant); assertEquals(200,response.getStatus()); assertTrue(response.getEntity() == originalVariant); assertEquals(originalVariant.getGoogleKey(), "Updated Google Key"); verify(variantService).updateVariant(originalVariant); }
@PUT @Path("/{androidID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateAndroidVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("androidID") String androidID, AndroidVariant updatedAndroidApplication) { 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(androidID); if (variant != null) { if (!(variant instanceof AndroidVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } AndroidVariant androidVariant = (AndroidVariant) variant; try { updatedAndroidApplication.merge(androidVariant); validateModelClass(androidVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update Android Variant '{}'", androidVariant.getVariantID()); logger.debug("Details: {}", cve); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating Android Variant '{}'", androidID); variantService.updateVariant(androidVariant); return Response.ok(androidVariant).build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); }
AndroidVariantEndpoint extends AbstractVariantEndpoint<AndroidVariant> { @PUT @Path("/{androidID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateAndroidVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("androidID") String androidID, AndroidVariant updatedAndroidApplication) { 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(androidID); if (variant != null) { if (!(variant instanceof AndroidVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } AndroidVariant androidVariant = (AndroidVariant) variant; try { updatedAndroidApplication.merge(androidVariant); validateModelClass(androidVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update Android Variant '{}'", androidVariant.getVariantID()); logger.debug("Details: {}", cve); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating Android Variant '{}'", androidID); variantService.updateVariant(androidVariant); return Response.ok(androidVariant).build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } }
AndroidVariantEndpoint extends AbstractVariantEndpoint<AndroidVariant> { @PUT @Path("/{androidID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateAndroidVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("androidID") String androidID, AndroidVariant updatedAndroidApplication) { 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(androidID); if (variant != null) { if (!(variant instanceof AndroidVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } AndroidVariant androidVariant = (AndroidVariant) variant; try { updatedAndroidApplication.merge(androidVariant); validateModelClass(androidVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update Android Variant '{}'", androidVariant.getVariantID()); logger.debug("Details: {}", cve); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating Android Variant '{}'", androidID); variantService.updateVariant(androidVariant); return Response.ok(androidVariant).build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } AndroidVariantEndpoint();   AndroidVariantEndpoint(Validator validator, SearchManager searchManager); }
AndroidVariantEndpoint extends AbstractVariantEndpoint<AndroidVariant> { @PUT @Path("/{androidID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateAndroidVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("androidID") String androidID, AndroidVariant updatedAndroidApplication) { 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(androidID); if (variant != null) { if (!(variant instanceof AndroidVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } AndroidVariant androidVariant = (AndroidVariant) variant; try { updatedAndroidApplication.merge(androidVariant); validateModelClass(androidVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update Android Variant '{}'", androidVariant.getVariantID()); logger.debug("Details: {}", cve); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating Android Variant '{}'", androidID); variantService.updateVariant(androidVariant); return Response.ok(androidVariant).build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).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> { @PUT @Path("/{androidID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateAndroidVariant( @PathParam("pushAppID") String pushApplicationId, @PathParam("androidID") String androidID, AndroidVariant updatedAndroidApplication) { 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(androidID); if (variant != null) { if (!(variant instanceof AndroidVariant)) { return Response.status(Response.Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).build(); } AndroidVariant androidVariant = (AndroidVariant) variant; try { updatedAndroidApplication.merge(androidVariant); validateModelClass(androidVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update Android Variant '{}'", androidVariant.getVariantID()); logger.debug("Details: {}", cve); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Updating Android Variant '{}'", androidID); variantService.updateVariant(androidVariant); return Response.ok(androidVariant).build(); } return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forVariants().notFound().build()).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);  }