@Test
public void publishTest() throws Exception {

	// check event exists
	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);
	// update but don't publish
	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());
	// publish unknown
	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));
	// publish
	// expect modificatioNumber to be incremented
	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());
	// publish already published event
	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());
}