Search in sources :

Example 11 with TestPatientBuilder

use of io.undertree.symptom.domain.TestPatientBuilder in project spring-boot-jpa by ssherwood.

the class PatientControllerWebTests method test_PatientController_addPatient_WithBirthDate_Expect_ValidAge.

@Test
public void test_PatientController_addPatient_WithBirthDate_Expect_ValidAge() throws Exception {
    ResponseEntity<Patient> entity = restTemplate.postForEntity("/patients", new TestPatientBuilder().withBirthDate(LocalDate.of(1980, 1, 1)).build(), Patient.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).isNotNull().hasFieldOrPropertyWithValue("age", LocalDate.now().getYear() - 1980);
}
Also used : TestPatientBuilder(io.undertree.symptom.domain.TestPatientBuilder) Patient(io.undertree.symptom.domain.Patient) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with TestPatientBuilder

use of io.undertree.symptom.domain.TestPatientBuilder in project spring-boot-jpa by ssherwood.

the class PatientControllerWebTests method test_PatientController_addPatient_WithInvalidEmail_Expect_BadRequest.

@Test
public void test_PatientController_addPatient_WithInvalidEmail_Expect_BadRequest() throws Exception {
    ResponseEntity<String> json = restTemplate.postForEntity("/patients", new TestPatientBuilder().withEmail("bad/email").build(), String.class);
    assertThat(json.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
    JSONAssert.assertEquals("{exception:\"org.springframework.web.bind.MethodArgumentNotValidException\"}", json.getBody(), false);
}
Also used : TestPatientBuilder(io.undertree.symptom.domain.TestPatientBuilder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TestPatientBuilder (io.undertree.symptom.domain.TestPatientBuilder)12 Test (org.junit.Test)12 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 GivenName (io.undertree.symptom.domain.GivenName)3 Patient (io.undertree.symptom.domain.Patient)3 NotFoundException (io.undertree.symptom.exceptions.NotFoundException)1