Skip to content

Commit

Permalink
refactor: multiple refacs in ConditionMapperTest (#142)
Browse files Browse the repository at this point in the history
* refactor: use BeforeAll instead of test class constructor

* refactor: use parameterized test

* feat: add default date format to XmlMapper

This ensures that only the date part is used from oBDS and FHIR
resource dates will be aligned to midnight at given time zone.
  • Loading branch information
pcvolkmer authored Oct 28, 2024
1 parent 14a1466 commit 84abcfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule;
import de.basisdatensatz.obds.v3.OBDS;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import org.approvaltests.Approvals;
import org.approvaltests.core.Options;
import org.hl7.fhir.r4.model.Reference;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.miracum.streams.ume.obdstofhir.FhirProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand All @@ -21,23 +24,25 @@
@SpringBootTest(classes = {FhirProperties.class})
@EnableConfigurationProperties
class ConditionMapperTest {
private final ConditionMapper sut;

@Autowired
ConditionMapperTest(FhirProperties fhirProps) {
private static ConditionMapper sut;

@BeforeAll
static void beforeEach(@Autowired FhirProperties fhirProps) {
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
sut = new ConditionMapper(fhirProps);
}

@Test
void map_withGivenObds_shouldCreateValidConditionResource() throws IOException {
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
// TODO: refactor to use a data provider for parameterized tests
final var resource = this.getClass().getClassLoader().getResource("obds3/test1.xml");
@ParameterizedTest
@CsvSource({"obds3/test1.xml"})
void map_withGivenObds_shouldCreateValidConditionResource(String sourceFile) throws IOException {
final var resource = this.getClass().getClassLoader().getResource(sourceFile);
assertThat(resource).isNotNull();

final var xmlMapper =
XmlMapper.builder()
.defaultUseWrapper(false)
.defaultDateFormat(new SimpleDateFormat("yyyy-MM-dd"))
.addModule(new JakartaXmlBindAnnotationModule())
.addModule(new Jdk8Module())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"subject": {
"reference": "Patient/1"
},
"recordedDate": "2024-06-10T02:00:00+02:00"
"recordedDate": "2024-06-10T00:00:00+02:00"
}

0 comments on commit 84abcfe

Please sign in to comment.