Skip to content

Instantly share code, notes, and snippets.

@tamboer
Created May 23, 2018 07:22
Show Gist options
  • Save tamboer/bf9f41f601a8fa41ed46823728c34c94 to your computer and use it in GitHub Desktop.
Save tamboer/bf9f41f601a8fa41ed46823728c34c94 to your computer and use it in GitHub Desktop.
Test with sql queries.
@Test
@Sql(scripts = {"/create_devices.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = {"/remove_devices.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void create_shouldFailWhenTheSameDeviceIsAddedASecondTime() throws Exception {
final ResultActions secondResultActions = mockMvc.perform(post("/devices")
.contentType(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(bulkDeviceUploadRequestWithDeviceThatWeAlreadyKnow())))
.andExpect(status().isOk());
expectSingleError(secondResultActions, DEVICE_INTERNAL_ID_DUPLICATE, new Error("DEVICE.UPLOAD.ERROR.DEVICE_EXISTS", "Device already known in the system."));
verifyZeroInteractions(eventPublisher);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment