EffectivityResource { @PUT @ApiOperation(value = "Update effectivity", response = EffectivityDTO.class) @Path("/{effectivityId}") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated effectivity"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response updateEffectivity( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Effectivity id") @PathParam("effectivityId") int effectivityId, @ApiParam(required = true, value = "Effectivity values to update") EffectivityDTO effectivityDTO) throws EntityNotFoundException, UpdateException, WorkspaceNotEnabledException, AccessRightException, CreationException { Effectivity effectivity; TypeEffectivity typeEffectivity = effectivityDTO.getTypeEffectivity(); if (TypeEffectivity.SERIALNUMBERBASEDEFFECTIVITY.equals(typeEffectivity)) { effectivity = effectivityManager.updateSerialNumberBasedEffectivity(workspaceId, effectivityId, effectivityDTO.getName(), effectivityDTO.getDescription(), effectivityDTO.getStartNumber(), effectivityDTO.getEndNumber()); } else if (TypeEffectivity.DATEBASEDEFFECTIVITY.equals(typeEffectivity)) { effectivity = effectivityManager.updateDateBasedEffectivity(workspaceId, effectivityId, effectivityDTO.getName(), effectivityDTO.getDescription(), effectivityDTO.getStartDate(), effectivityDTO.getEndDate()); } else if (TypeEffectivity.LOTBASEDEFFECTIVITY.equals(typeEffectivity)) { effectivity = effectivityManager.updateLotBasedEffectivity(workspaceId, effectivityId, effectivityDTO.getName(), effectivityDTO.getDescription(), effectivityDTO.getStartLotId(), effectivityDTO.getEndLotId()); } else { effectivity = effectivityManager.updateEffectivity(workspaceId, effectivityId, effectivityDTO.getName(), effectivityDTO.getDescription()); } EffectivityDTO returnedEffectivityDTO = mapper.map(effectivity, EffectivityDTO.class); returnedEffectivityDTO.setTypeEffectivity(typeEffectivity); ConfigurationItem configurationItem = effectivity.getConfigurationItem(); returnedEffectivityDTO.setConfigurationItemKey(configurationItem != null ? configurationItem.getKey() : null); return Response.ok(returnedEffectivityDTO).build(); } EffectivityResource(); @PostConstruct void init(); @GET @Path("/{effectivityId}") @ApiOperation(value = "Get an effectivity from its ID", response = EffectivityDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of effectivity"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) EffectivityDTO getEffectivity(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Effectivity id") @PathParam("effectivityId") int effectivityId); @PUT @ApiOperation(value = "Update effectivity", response = EffectivityDTO.class) @Path("/{effectivityId}") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated effectivity"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response updateEffectivity(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Effectivity id") @PathParam("effectivityId") int effectivityId,
            @ApiParam(required = true, value = "Effectivity values to update") EffectivityDTO effectivityDTO);  }
@Test public void updateEffectivityTest() throws ApplicationException { String workspaceId = "wks"; int effectivityId = 42; EffectivityDTO effectivityDTO = new EffectivityDTO(); effectivityDTO.setId(effectivityId); effectivityDTO.setDescription("Ola ola"); effectivityDTO.setTypeEffectivity(TypeEffectivity.SERIALNUMBERBASEDEFFECTIVITY); effectivityDTO.setStartNumber("ABCDEF"); effectivityDTO.setEndNumber("GHIJKL"); Mockito.when(effectivityManager.updateSerialNumberBasedEffectivity(workspaceId, effectivityId, effectivityDTO.getName(), effectivityDTO.getDescription(), effectivityDTO.getStartNumber(), effectivityDTO.getEndNumber())) .thenReturn(new SerialNumberBasedEffectivity()); Response res = effectivityResource.updateEffectivity(workspaceId, effectivityId, effectivityDTO); Object entity = res.getEntity(); Assert.assertTrue(entity.getClass().isAssignableFrom(EffectivityDTO.class)); EffectivityDTO result = (EffectivityDTO) entity; Assert.assertEquals(TypeEffectivity.SERIALNUMBERBASEDEFFECTIVITY, result.getTypeEffectivity()); effectivityDTO.setTypeEffectivity(TypeEffectivity.DATEBASEDEFFECTIVITY); effectivityDTO.setStartDate(new Date()); effectivityDTO.setEndDate(new Date()); Mockito.when( effectivityManager.updateDateBasedEffectivity(workspaceId, effectivityId, effectivityDTO.getName(), effectivityDTO.getDescription(), effectivityDTO.getStartDate(), effectivityDTO.getEndDate())) .thenReturn(new DateBasedEffectivity()); res = effectivityResource.updateEffectivity(workspaceId, effectivityId, effectivityDTO); entity = res.getEntity(); Assert.assertTrue(entity.getClass().isAssignableFrom(EffectivityDTO.class)); result = (EffectivityDTO) entity; Assert.assertEquals(TypeEffectivity.DATEBASEDEFFECTIVITY, result.getTypeEffectivity()); effectivityDTO.setTypeEffectivity(TypeEffectivity.LOTBASEDEFFECTIVITY); effectivityDTO.setStartLotId("ABC"); effectivityDTO.setEndLotId("DEF"); Mockito.when(effectivityManager.updateLotBasedEffectivity(workspaceId, effectivityId, effectivityDTO.getName(), effectivityDTO.getDescription(), effectivityDTO.getStartLotId(), effectivityDTO.getEndLotId())) .thenReturn(new LotBasedEffectivity()); res = effectivityResource.updateEffectivity(workspaceId, effectivityId, effectivityDTO); entity = res.getEntity(); Assert.assertTrue(entity.getClass().isAssignableFrom(EffectivityDTO.class)); result = (EffectivityDTO) entity; Assert.assertEquals(TypeEffectivity.LOTBASEDEFFECTIVITY, result.getTypeEffectivity()); effectivityDTO.setTypeEffectivity(null); Mockito.when( effectivityManager.updateEffectivity(workspaceId, effectivityId, effectivityDTO.getName(), effectivityDTO.getDescription())) .thenReturn(new LotBasedEffectivity()); res = effectivityResource.updateEffectivity(workspaceId, effectivityId, effectivityDTO); entity = res.getEntity(); Assert.assertTrue(entity.getClass().isAssignableFrom(EffectivityDTO.class)); result = (EffectivityDTO) entity; Assert.assertEquals(null, result.getTypeEffectivity()); }