Search in sources :

Example 1 with Patient

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

the class PatientController method updatePatientIncludingNulls.

/**
 * Update an existing resource with a new representation.  The entire state of the entity is
 * replaced with that provided with the RequestBody (this means that null or excluded fields are
 * updated to null on the entity itself).
 *
 * @param patientId unique patient UUID to find
 * @param patient the Patient to update with
 * @return the Patient as modified by the update
 */
@PutMapping("/{id}")
public Patient updatePatientIncludingNulls(@PathVariable("id") final UUID patientId, @Valid @RequestBody final Patient patient) {
    Patient originalPatient = this.getPatient(patientId);
    updateProperties(patientId, originalPatient, patient);
    return this.patientRepository.save(originalPatient);
}
Also used : Patient(io.undertree.symptom.domain.Patient) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 2 with Patient

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

the class PatientControllerWebTests method test_PatientController_addPatient_WithEmpty_Expect_BadRequest.

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

Example 3 with Patient

use of io.undertree.symptom.domain.Patient 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 4 with Patient

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

the class PatientRepositoryTests method test_PatientRepository_SaveWithEmpty_ExpectException.

@Test
public void test_PatientRepository_SaveWithEmpty_ExpectException() throws Exception {
    thrown.expect(ConstraintViolationException.class);
    thrown.expectMessage(containsString("'may not be empty'"));
    patientRepository.saveAndFlush(new Patient());
}
Also used : Patient(io.undertree.symptom.domain.Patient) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 5 with Patient

use of io.undertree.symptom.domain.Patient 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)

Aggregations

Patient (io.undertree.symptom.domain.Patient)9 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 TestPatientBuilder (io.undertree.symptom.domain.TestPatientBuilder)3 NotFoundException (io.undertree.symptom.exceptions.NotFoundException)2 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)2 GivenName (io.undertree.symptom.domain.GivenName)1 HashMap (java.util.HashMap)1 HttpEntity (org.springframework.http.HttpEntity)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1