Created
June 14, 2017 19:58
-
-
Save eduardoschmidtsantos/f1411d21a3e9bc534e8f3fcae0531eec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.jexperts.conformit.integration.oversight; | |
import br.com.jexperts.conformit.integration.IntegrationTestBase; | |
import br.com.jexperts.conformit.integration.util.WebTestConstants; | |
import br.com.jexperts.conformit.oversight.dto.DocumentFormDTO; | |
import br.com.jexperts.conformit.oversight.dto.DocumentTypeDTO; | |
import com.auth0.jwt.internal.com.fasterxml.jackson.databind.util.ISO8601DateFormat; | |
import com.github.springtestdbunit.annotation.DatabaseSetup; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import java.util.Date; | |
import java.util.HashMap; | |
import static br.com.jexperts.conformit.integration.util.WebTestUtil.convertObjectToJsonBytes; | |
import static org.hamcrest.Matchers.*; | |
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@DatabaseSetup("/db/datasets/oversight/document-entries.xml") | |
public class DocumentIntegrationTest extends IntegrationTestBase { | |
private final static Long OVERSIGHT_ID = 1L; | |
private final static Long OVERSIGHT_DOCUMENT_TYPE_ID = 1L; | |
private final static Long NOTIFICATION_TERM_DOCUMENT_TYPE_ID = 4L; | |
@Test | |
public void createEmptyDocument() throws Exception { | |
DocumentFormDTO emptyDocument = new DocumentFormDTO(); | |
mockMvc.perform(post("/v1/documents") | |
.contentType(WebTestConstants.APPLICATION_JSON_UTF8) | |
.content(convertObjectToJsonBytes(emptyDocument))) | |
.andExpect(status().isBadRequest()) | |
.andExpect(jsonPath("$.errors", hasSize(1))) | |
.andExpect(jsonPath("$.errors", containsInAnyOrder("type is required."))) | |
.andReturn(); | |
} | |
@Test | |
public void createValidOversightDocument() throws Exception { | |
final Long MAIN_DATE_DOCUMENT_VALUE_ID = 6L; | |
DocumentFormDTO emptyDocument = new DocumentFormDTO(); | |
DocumentTypeDTO type = new DocumentTypeDTO(); | |
type.setId(OVERSIGHT_DOCUMENT_TYPE_ID); | |
emptyDocument.setType(type); | |
HashMap<Long, Object> values = new HashMap<>(); | |
ISO8601DateFormat format = new ISO8601DateFormat(); | |
//TODO Create validation for main date(required for all documents) | |
values.put(MAIN_DATE_DOCUMENT_VALUE_ID, format.format(new Date())); | |
emptyDocument.setValues(values); | |
mockMvc.perform(post("/v1/documents") | |
.contentType(WebTestConstants.APPLICATION_JSON_UTF8) | |
.content(convertObjectToJsonBytes(emptyDocument))) | |
.andExpect(status().isCreated()) | |
.andExpect(jsonPath(String.format("$.type.id"), comparesEqualTo(OVERSIGHT_DOCUMENT_TYPE_ID.intValue()))) | |
.andExpect(jsonPath(String.format("$.values.%d",MAIN_DATE_DOCUMENT_VALUE_ID), notNullValue())) | |
.andReturn(); | |
} | |
@Test | |
public void createValidNotificationTermDocument() throws Exception { | |
final Long MAIN_DATE_DOCUMENT_VALUE_ID = 38L; | |
final Long OVERSIGHT_DOCUMENT_VALUE_ID = 37L; | |
DocumentFormDTO emptyDocument = new DocumentFormDTO(); | |
DocumentTypeDTO type = new DocumentTypeDTO(); | |
type.setId(NOTIFICATION_TERM_DOCUMENT_TYPE_ID); | |
emptyDocument.setType(type); | |
HashMap<Long, Object> values = new HashMap<>(); | |
ISO8601DateFormat format = new ISO8601DateFormat(); | |
values.put(MAIN_DATE_DOCUMENT_VALUE_ID, format.format(new Date())); | |
values.put(OVERSIGHT_DOCUMENT_VALUE_ID, OVERSIGHT_ID); | |
emptyDocument.setValues(values); | |
mockMvc.perform(post("/v1/documents") | |
.contentType(WebTestConstants.APPLICATION_JSON_UTF8) | |
.content(convertObjectToJsonBytes(emptyDocument))) | |
.andExpect(status().isCreated()) | |
.andExpect(jsonPath(String.format("$.type.id"), comparesEqualTo(NOTIFICATION_TERM_DOCUMENT_TYPE_ID.intValue()))) | |
.andExpect(jsonPath(String.format("$.values.%d",MAIN_DATE_DOCUMENT_VALUE_ID), notNullValue())) | |
.andReturn(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment