DemandResponseController { @RequestMapping(value = "/{id}/publish", method = RequestMethod.POST) @ResponseBody public DemandResponseEventReadDto publish(@PathVariable(value = "id") Long id, HttpServletResponse response) { Optional<DemandResponseEvent> op = demandResponseEventService.findById(id); if (!op.isPresent()) { response.setStatus(HttpStatus.NOT_FOUND_404); return null; } DemandResponseEvent event = op.get(); event = demandResponseEventService.publish(event); response.setStatus(HttpStatus.OK_200); LOGGER.info("active DR event: " + event.toString()); return dtoMapper.map(event, DemandResponseEventReadDto.class); }  @RequestMapping(value = "/search", method = RequestMethod.POST) @ResponseBody List<DemandResponseEventReadDto> search(@RequestBody List<DemandResponseEventFilter> filters,
			@RequestParam(value = "start", required = false) Long start,
			@RequestParam(value = "end", required = false) Long end,
			@RequestParam(value = "page", required = false) Integer page,
			@RequestParam(value = "size", required = false) Integer size, HttpServletResponse response); @RequestMapping(value = "/", method = RequestMethod.POST) @ResponseBody DemandResponseEventReadDto create(@Valid @RequestBody DemandResponseEventCreateDto event,
			HttpServletResponse response, BindingResult result); @RequestMapping(value = "/{id}", method = RequestMethod.PUT) @ResponseBody DemandResponseEventReadDto update(@PathVariable(value = "id") Long id,
			@Valid @RequestBody DemandResponseEventUpdateDto event, HttpServletResponse response,
			BindingResult result); @RequestMapping(value = "/{id}/publish", method = RequestMethod.POST) @ResponseBody DemandResponseEventReadDto publish(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}/active", method = RequestMethod.POST) @ResponseBody DemandResponseEventReadDto active(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}/cancel", method = RequestMethod.POST) @ResponseBody DemandResponseEventReadDto cancel(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody DemandResponseEventReadDto read(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseBody void delete(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}/venResponse", method = RequestMethod.GET) @ResponseBody List<VenDemandResponseEventDto> readVenDemandResponseEvent(@PathVariable(value = "id") Long id,
			HttpServletResponse response); @RequestMapping(value = "/{id}/venResponse/{username}", method = RequestMethod.GET) @ResponseBody VenDemandResponseEventDto readVenDemandResponseEvent(@PathVariable(value = "id") Long id,
			@PathVariable(value = "username") String username, HttpServletResponse response);  }
@Test public void publishTest() throws Exception { MvcResult andReturn = this.mockMvc .perform(MockMvcRequestBuilders.get(DEMAND_RESPONSE_EVENT_URL + event1.getId()).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)).andReturn(); DemandResponseEventReadDto dto = convertMvcResultToDemandResponseDto(andReturn); Long modificationNumber = dto.getDescriptor().getModificationNumber(); assertNotNull(dto); assertNotNull(dto.getSignals()); assertEquals(1, dto.getSignals().size()); assertEquals(dto.getSignals().get(0).getCurrentValue(), DemandResponseEventSimpleValueEnum.SIMPLE_SIGNAL_PAYLOAD_HIGH.getValue()); DemandResponseEventSignalDto signalModerate = new DemandResponseEventSignalDto(); signalModerate.setCurrentValue(DemandResponseEventSimpleValueEnum.SIMPLE_SIGNAL_PAYLOAD_MODERATE.getValue()); signalModerate.setSignalName(SIMPLE_SIGNAL_NAME); signalModerate.setSignalType(LEVEL_SIGNAL_TYPE); signalModerate.setUnitType(SIGNAL_UNIT_TYPE); DemandResponseEventUpdateDto updateDto = new DemandResponseEventUpdateDto(); updateDto.setPublished(false); updateDto.getSignals().add(signalModerate); updateDto.setTargets(dto.getTargets()); String contentStr = mapper.writeValueAsString(updateDto); this.mockMvc.perform(MockMvcRequestBuilders.put(DEMAND_RESPONSE_EVENT_URL + event1.getId()) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).content(contentStr).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)); andReturn = this.mockMvc .perform(MockMvcRequestBuilders.get(DEMAND_RESPONSE_EVENT_URL + event1.getId()).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)).andReturn(); dto = convertMvcResultToDemandResponseDto(andReturn); assertNotNull(dto); assertNotNull(dto.getSignals()); assertEquals(1, dto.getSignals().size()); assertEquals(DemandResponseEventSimpleValueEnum.SIMPLE_SIGNAL_PAYLOAD_MODERATE.getValue(), dto.getSignals().get(0).getCurrentValue()); assertEquals(SIMPLE_SIGNAL_NAME, dto.getSignals().get(0).getSignalName()); assertEquals(LEVEL_SIGNAL_TYPE, dto.getSignals().get(0).getSignalType()); assertEquals(SIGNAL_UNIT_TYPE, dto.getSignals().get(0).getUnitType()); assertEquals(modificationNumber, dto.getDescriptor().getModificationNumber()); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL + "12/publish") .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.NOT_FOUND_404)); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL + "mouaiccool/publish") .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); modificationNumber = modificationNumber + 1; this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL + event1.getId() + "/publish") .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)); andReturn = this.mockMvc .perform(MockMvcRequestBuilders.get(DEMAND_RESPONSE_EVENT_URL + event1.getId()).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)).andReturn(); dto = convertMvcResultToDemandResponseDto(andReturn); assertNotNull(dto); assertNotNull(dto.getSignals()); assertEquals(1, dto.getSignals().size()); assertEquals(dto.getSignals().get(0).getCurrentValue(), DemandResponseEventSimpleValueEnum.SIMPLE_SIGNAL_PAYLOAD_MODERATE.getValue()); assertEquals(modificationNumber, dto.getDescriptor().getModificationNumber()); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL + event1.getId() + "/publish") .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)); andReturn = this.mockMvc .perform(MockMvcRequestBuilders.get(DEMAND_RESPONSE_EVENT_URL + event1.getId()).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)).andReturn(); dto = convertMvcResultToDemandResponseDto(andReturn); assertNotNull(dto); assertNotNull(dto.getSignals()); assertEquals(1, dto.getSignals().size()); assertEquals(dto.getSignals().get(0).getCurrentValue(), DemandResponseEventSimpleValueEnum.SIMPLE_SIGNAL_PAYLOAD_MODERATE.getValue()); assertEquals(modificationNumber, dto.getDescriptor().getModificationNumber()); }