@Test public void createTest() throws Exception { MvcResult andReturn = this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL + "/search") .content(mapper.writeValueAsString(DemandResponseEventFilter.builder() .addVenId(DemandResponseControllerTest.VEN1).build())) .header("Content-Type", "application/json").with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)).andReturn(); List<DemandResponseEventReadDto> readValue = convertMvcResultToDemandResponseDtoList(andReturn); assertNotNull(readValue); assertEquals(2, readValue.size()); for (DemandResponseEventReadDto dto : readValue) { assertEquals(DemandResponseControllerTest.MODIFICATION, dto.getDescriptor().getModificationNumber()); assertNotNull(dto.getCreatedTimestamp()); assertEquals(DemandResponseControllerTest.DURATION, dto.getActivePeriod().getDuration()); assertEquals(DemandResponseControllerTest.MARKETCONTEXT_NAME, dto.getDescriptor().getMarketContext()); assertEquals(DemandResponseControllerTest.START, dto.getActivePeriod().getStart()); assertEquals(DemandResponseEventSimpleValueEnum.SIMPLE_SIGNAL_PAYLOAD_HIGH.getValue(), dto.getSignals().get(0).getCurrentValue()); } DemandResponseEventCreateDto toCreate = createValidEvent(); byte[] content = mapper.writeValueAsBytes(toCreate); andReturn = this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(content) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.CREATED_201)).andReturn(); DemandResponseEventReadDto res = convertMvcResultToDemandResponseDto(andReturn); assertNotNull(res); assertNotNull(res.getId()); Long toDeleteId = res.getId(); assertEquals(DemandResponseControllerTest.MODIFICATION, res.getDescriptor().getModificationNumber()); assertNotNull(res.getCreatedTimestamp()); assertNotNull(res.getLastUpdateTimestamp()); assertEquals(DemandResponseControllerTest.DURATION, res.getActivePeriod().getDuration()); assertEquals(DemandResponseControllerTest.MARKETCONTEXT_NAME, res.getDescriptor().getMarketContext()); assertEquals(DemandResponseControllerTest.START, res.getActivePeriod().getStart()); assertEquals(DemandResponseEventSimpleValueEnum.SIMPLE_SIGNAL_PAYLOAD_HIGH.getValue(), res.getSignals().get(0).getCurrentValue()); assertTrue(DemandResponseEventStateEnum.ACTIVE.equals(res.getDescriptor().getState())); andReturn = this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL + "/search") .content(mapper.writeValueAsString(DemandResponseEventFilter.builder() .addVenId(DemandResponseControllerTest.VEN1).build())) .header("Content-Type", "application/json").with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)).andReturn(); readValue = convertMvcResultToDemandResponseDtoList(andReturn); assertNotNull(readValue); assertEquals(3, readValue.size()); for (DemandResponseEventReadDto dto : readValue) { assertEquals(DemandResponseControllerTest.MODIFICATION, dto.getDescriptor().getModificationNumber()); assertNotNull(dto.getCreatedTimestamp()); assertEquals(DemandResponseControllerTest.DURATION, dto.getActivePeriod().getDuration()); assertEquals(DemandResponseControllerTest.MARKETCONTEXT_NAME, dto.getDescriptor().getMarketContext()); assertEquals(DemandResponseControllerTest.START, dto.getActivePeriod().getStart()); assertEquals(DemandResponseEventSimpleValueEnum.SIMPLE_SIGNAL_PAYLOAD_HIGH.getValue(), dto.getSignals().get(0).getCurrentValue()); } toCreate = createValidEvent(); toCreate.getDescriptor().setMarketContext(null); String contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); toCreate = createValidEvent(); toCreate.getDescriptor().setOadrProfile(null); contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); toCreate = createValidEvent(); toCreate.getDescriptor().setResponseRequired(null); contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); toCreate = createValidEvent(); toCreate.getDescriptor().setMarketContext(UNKNOWN_MARKETCONTEXT_NAME); contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); toCreate = createValidEvent(); toCreate.getDescriptor().setMarketContext(UNKNOWN_MARKETCONTEXT_NAME); toCreate.getDescriptor().setModificationNumber(0L); contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); toCreate = createValidEvent(); toCreate.getDescriptor().setPriority(-1L); contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); toCreate = createValidEvent(); toCreate.getSignals().clear(); contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); toCreate = createValidEvent(); toCreate.getActivePeriod().setStart(null); contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); toCreate = createValidEvent(); toCreate.getActivePeriod().setDuration(null); contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); toCreate = createValidEvent(); toCreate.getActivePeriod().setDuration("1h"); contentStr = mapper.writeValueAsString(toCreate); this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(contentStr) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.BAD_REQUEST_400)); this.mockMvc.perform(MockMvcRequestBuilders.delete(DEMAND_RESPONSE_EVENT_URL + toDeleteId).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)); toCreate = createValidEvent(); toCreate.setPublished(true); content = mapper.writeValueAsBytes(toCreate); andReturn = this.mockMvc .perform(MockMvcRequestBuilders.post(DEMAND_RESPONSE_EVENT_URL).content(content) .header(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_HEADER_VALUE).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.CREATED_201)).andReturn(); res = convertMvcResultToDemandResponseDto(andReturn); assertNotNull(res); assertNotNull(res.getId()); toDeleteId = res.getId(); assertNotNull(res.getCreatedTimestamp()); assertNotNull(res.getLastUpdateTimestamp()); assertEquals(DemandResponseControllerTest.DURATION, res.getActivePeriod().getDuration()); assertEquals(DemandResponseControllerTest.MARKETCONTEXT_NAME, res.getDescriptor().getMarketContext()); assertEquals(DemandResponseControllerTest.START, res.getActivePeriod().getStart()); assertEquals(DemandResponseEventSimpleValueEnum.SIMPLE_SIGNAL_PAYLOAD_HIGH.getValue(), res.getSignals().get(0).getCurrentValue()); assertTrue(DemandResponseEventStateEnum.ACTIVE.equals(res.getDescriptor().getState())); assertTrue(res.getDescriptor().getModificationNumber().equals(0L)); this.mockMvc.perform(MockMvcRequestBuilders.delete(DEMAND_RESPONSE_EVENT_URL + toDeleteId).with(adminSession)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)); }
@RequestMapping(value = "/", method = RequestMethod.POST) @ResponseBody public DemandResponseEventReadDto create(@Valid @RequestBody DemandResponseEventCreateDto event, HttpServletResponse response, BindingResult result) { if (result.hasErrors()) { response.setStatus(HttpStatus.BAD_REQUEST_400); return null; } DemandResponseEvent save = demandResponseEventService.create(event); response.setStatus(HttpStatus.CREATED_201); LOGGER.info("create DR event: " + save.toString()); return dtoMapper.map(save, DemandResponseEventReadDto.class); }
DemandResponseController { @RequestMapping(value = "/", method = RequestMethod.POST) @ResponseBody public DemandResponseEventReadDto create(@Valid @RequestBody DemandResponseEventCreateDto event, HttpServletResponse response, BindingResult result) { if (result.hasErrors()) { response.setStatus(HttpStatus.BAD_REQUEST_400); return null; } DemandResponseEvent save = demandResponseEventService.create(event); response.setStatus(HttpStatus.CREATED_201); LOGGER.info("create DR event: " + save.toString()); return dtoMapper.map(save, DemandResponseEventReadDto.class); } }
DemandResponseController { @RequestMapping(value = "/", method = RequestMethod.POST) @ResponseBody public DemandResponseEventReadDto create(@Valid @RequestBody DemandResponseEventCreateDto event, HttpServletResponse response, BindingResult result) { if (result.hasErrors()) { response.setStatus(HttpStatus.BAD_REQUEST_400); return null; } DemandResponseEvent save = demandResponseEventService.create(event); response.setStatus(HttpStatus.CREATED_201); LOGGER.info("create DR event: " + save.toString()); return dtoMapper.map(save, DemandResponseEventReadDto.class); }  }
DemandResponseController { @RequestMapping(value = "/", method = RequestMethod.POST) @ResponseBody public DemandResponseEventReadDto create(@Valid @RequestBody DemandResponseEventCreateDto event, HttpServletResponse response, BindingResult result) { if (result.hasErrors()) { response.setStatus(HttpStatus.BAD_REQUEST_400); return null; } DemandResponseEvent save = demandResponseEventService.create(event); response.setStatus(HttpStatus.CREATED_201); LOGGER.info("create DR event: " + save.toString()); return dtoMapper.map(save, 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); }
DemandResponseController { @RequestMapping(value = "/", method = RequestMethod.POST) @ResponseBody public DemandResponseEventReadDto create(@Valid @RequestBody DemandResponseEventCreateDto event, HttpServletResponse response, BindingResult result) { if (result.hasErrors()) { response.setStatus(HttpStatus.BAD_REQUEST_400); return null; } DemandResponseEvent save = demandResponseEventService.create(event); response.setStatus(HttpStatus.CREATED_201); LOGGER.info("create DR event: " + save.toString()); return dtoMapper.map(save, 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);  }