use of org.ehrbase.serialisation.flatencoding.FlatJasonProvider in project openEHR_SDK by ehrbase.
the class RoundTripTest method checkTestCase.
public void checkTestCase(TestCase testCase, SoftAssertions softly) throws IOException {
String value = IOUtils.toString(testCase.simSDTJson.getStream(), UTF_8);
RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, testCase.templateId);
Composition composition = flatJson.unmarshal(value);
Flattener flattener = new Flattener(new TestDataTemplateProvider());
Object flatten = flattener.flatten(composition, testCase.dtoClass);
Unflattener unflattener = new Unflattener(new TestDataTemplateProvider());
RMObject actual = unflattener.unflatten(flatten);
String actualFlat = flatJson.marshal(actual);
List<String> errors = compere(actualFlat, value);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.missing);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.extra);
}
use of org.ehrbase.serialisation.flatencoding.FlatJasonProvider in project openEHR_SDK by ehrbase.
the class DBEncodeRoundTripTest method testAlternativeEventsRoundTrip.
@Test
@Ignore
public void testAlternativeEventsRoundTrip() throws IOException {
String value = new String(Files.readAllBytes(Paths.get("src/test/resources/sample_data/alternative_events_reduced_flat.json")));
RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, "AlternativeEvents");
Composition composition = flatJson.unmarshal(value);
assertThat(composition).isNotNull();
CompositionSerializer compositionSerializerRawJson = new CompositionSerializer();
String db_encoded = compositionSerializerRawJson.dbEncode(composition);
assertNotNull(db_encoded);
String converted = new LightRawJsonEncoder(db_encoded).encodeCompositionAsString();
assertNotNull(converted);
Composition actual = new CanonicalJson().unmarshal(converted, Composition.class);
String actualFlat = flatJson.marshal(actual);
assertNotNull(actualFlat);
}
use of org.ehrbase.serialisation.flatencoding.FlatJasonProvider in project openEHR_SDK by ehrbase.
the class StructuredHelperTest method testStructuredToFlat.
private void testStructuredToFlat(CompositionTestDataStructuredJson structuredJson, CompositionTestDataSimSDTJson simSDTJson, String templateId) throws IOException {
String flat = IOUtils.toString(structuredJson.getStream(), StandardCharsets.UTF_8);
String actual = StructuredHelper.convertStructuredToFlat(flat);
String expected = IOUtils.toString(simSDTJson.getStream(), StandardCharsets.UTF_8);
RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, templateId);
List<String> errors = compere(flatJson.marshal(flatJson.unmarshal(actual)), expected);
SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder();
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder();
softAssertions.assertAll();
}
use of org.ehrbase.serialisation.flatencoding.FlatJasonProvider in project openEHR_SDK by ehrbase.
the class OldDtoModelTest method checkTestCase.
public void checkTestCase(TestCase testCase, SoftAssertions softly) throws IOException {
String value = IOUtils.toString(testCase.simSDTJson.getStream(), UTF_8);
RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, testCase.templateId);
Composition composition = flatJson.unmarshal(value);
Flattener flattener = new Flattener(new TestDataTemplateProvider());
Object flatten = flattener.flatten(composition, testCase.dtoClass);
Unflattener unflattener = new Unflattener(new TestDataTemplateProvider());
RMObject actual = unflattener.unflatten(flatten);
String actualFlat = flatJson.marshal(actual);
List<String> errors = compere(actualFlat, value);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.missing);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.extra);
}
use of org.ehrbase.serialisation.flatencoding.FlatJasonProvider in project openEHR_SDK by ehrbase.
the class FlatConformanceTest method testRoundTrip.
@ParameterizedTest
@MethodSource("testRoundTripArguments")
void testRoundTrip(CompositionTestDataConformanceSDTJson testData, String[] expectedMissing, String[] expectedExtra, String[] expectedValidationErrorPath) throws IOException {
String templateId = testData.getTemplate().getTemplateId();
RMDataFormat cut = new FlatJasonProvider(TEMPLATE_PROVIDER).buildFlatJson(FlatFormat.SIM_SDT, templateId);
String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
Composition unmarshal = cut.unmarshal(flat);
SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat(unmarshal).isNotNull();
CompositionValidator rmObjectValidator = new CompositionValidator();
softAssertions.assertThat(rmObjectValidator.validate(unmarshal, TEMPLATE_PROVIDER.buildIntrospect(templateId).orElseThrow())).filteredOn(d -> !ArrayUtils.contains(expectedValidationErrorPath, d.getAqlPath())).isEmpty();
String actual = cut.marshal(unmarshal);
String expected = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
List<String> errors = compere(actual, expected);
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder(expectedMissing);
softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder(expectedExtra);
softAssertions.assertAll();
}
Aggregations