Search in sources :

Example 1 with TestPatientBuilder

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

the class PatientControllerWebTests method test_PatientController_addPatient_WithEmptyGivenName_Expect_BadRequest.

@Test
public void test_PatientController_addPatient_WithEmptyGivenName_Expect_BadRequest() throws Exception {
    Patient build = new TestPatientBuilder().withGivenName(new GivenName("")).build();
    ResponseEntity<String> json = restTemplate.postForEntity("/patients", 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) Patient(io.undertree.symptom.domain.Patient) GivenName(io.undertree.symptom.domain.GivenName) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with TestPatientBuilder

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

the class PatientRepositoryTests method test_PatientRepository_SaveWithShortGivenName_ExpectException.

@Test
public void test_PatientRepository_SaveWithShortGivenName_ExpectException() throws Exception {
    thrown.expect(ConstraintViolationException.class);
    thrown.expectMessage(allOf(containsString("givenName"), containsString("'size must be between 2 and")));
    patientRepository.saveAndFlush(new TestPatientBuilder().withGivenName(new GivenName("A")).build());
}
Also used : TestPatientBuilder(io.undertree.symptom.domain.TestPatientBuilder) GivenName(io.undertree.symptom.domain.GivenName) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 3 with TestPatientBuilder

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

the class PatientRepositoryTests method test_PatientRepository_findByPatientId_ExpectExists.

@Test
public void test_PatientRepository_findByPatientId_ExpectExists() throws Exception {
    Patient patient = entityManager.persistFlushFind(new TestPatientBuilder().build());
    Patient aPatient = patientRepository.findByPatientId(patient.getPatientId()).orElseThrow(NotFoundException::new);
    assertThat(aPatient).isEqualTo(patient);
}
Also used : TestPatientBuilder(io.undertree.symptom.domain.TestPatientBuilder) Patient(io.undertree.symptom.domain.Patient) NotFoundException(io.undertree.symptom.exceptions.NotFoundException) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 4 with TestPatientBuilder

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

the class PatientRepositoryTests method test_PatientRepository_SaveWithShortFamilyName_ExpectException.

@Test
public void test_PatientRepository_SaveWithShortFamilyName_ExpectException() throws Exception {
    thrown.expect(ConstraintViolationException.class);
    thrown.expectMessage(allOf(containsString("familyName"), containsString("'size must be between 2 and")));
    patientRepository.saveAndFlush(new TestPatientBuilder().withFamilyName("Z").build());
}
Also used : TestPatientBuilder(io.undertree.symptom.domain.TestPatientBuilder) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 5 with TestPatientBuilder

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

the class PatientRepositoryTests method test_PatientRepository_SaveWithLessThanMinWeight_ExpectException.

@Test
public void test_PatientRepository_SaveWithLessThanMinWeight_ExpectException() throws Exception {
    thrown.expect(ConstraintViolationException.class);
    thrown.expectMessage(allOf(containsString("weight"), containsString("'must be greater than or equal to 0'")));
    patientRepository.saveAndFlush(new TestPatientBuilder().withWeight((short) -1).build());
}
Also used : TestPatientBuilder(io.undertree.symptom.domain.TestPatientBuilder) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

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