Search in sources :

Example 1 with FlatJasonProvider

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);
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) EhrbaseMultiOccurrenceDeV1Composition(org.ehrbase.client.classgenerator.examples.ehrbasemultioccurrencedev1composition.EhrbaseMultiOccurrenceDeV1Composition) AlternativeEventsComposition(org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition) TestAllTypesEnV1Composition(org.ehrbase.client.classgenerator.examples.testalltypesenv1composition.TestAllTypesEnV1Composition) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) RMObject(com.nedap.archie.rm.RMObject) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) RMObject(com.nedap.archie.rm.RMObject)

Example 2 with FlatJasonProvider

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);
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) LightRawJsonEncoder(org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) TestDataTemplateProvider(org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with FlatJasonProvider

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();
}
Also used : CompositionTestDataStructuredJson(org.ehrbase.test_data.composition.CompositionTestDataStructuredJson) SoftAssertions(org.assertj.core.api.SoftAssertions) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test) IOException(java.io.IOException) JSONAssert(org.skyscreamer.jsonassert.JSONAssert) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) TestDataTemplateProvider(org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider) List(java.util.List) FlatJsonMarshallerTest.compere(org.ehrbase.serialisation.flatencoding.std.marshal.FlatJsonMarshallerTest.compere) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) JSONCompareMode(org.skyscreamer.jsonassert.JSONCompareMode) FlatFormat(org.ehrbase.serialisation.flatencoding.FlatFormat) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) TestDataTemplateProvider(org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider)

Example 4 with FlatJasonProvider

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);
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) TestAllTypesEnV1Composition(org.ehrbase.client.classgenerator.olddtoexamples.testalltypesenv1composition.TestAllTypesEnV1Composition) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.olddtoexamples.coronaanamnesecomposition.CoronaAnamneseComposition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) Flattener(org.ehrbase.client.flattener.Flattener) Unflattener(org.ehrbase.client.flattener.Unflattener) RMObject(com.nedap.archie.rm.RMObject) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) RMObject(com.nedap.archie.rm.RMObject)

Example 5 with FlatJasonProvider

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();
}
Also used : Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) Composition(com.nedap.archie.rm.composition.Composition) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayUtils(org.apache.commons.lang3.ArrayUtils) IOException(java.io.IOException) Arguments(org.junit.jupiter.params.provider.Arguments) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) CompositionValidator(org.ehrbase.validation.CompositionValidator) StandardCharsets(java.nio.charset.StandardCharsets) ArrayList(java.util.ArrayList) IOUtils(org.apache.commons.io.IOUtils) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) CompositionTestDataConformanceSDTJson(org.ehrbase.test_data.composition.CompositionTestDataConformanceSDTJson) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) TestDataTemplateProvider(org.ehrbase.conformance_test.templateprovider.TestDataTemplateProvider) Map(java.util.Map) FlatFormat(org.ehrbase.serialisation.flatencoding.FlatFormat) MethodSource(org.junit.jupiter.params.provider.MethodSource) Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) CompositionValidator(org.ehrbase.validation.CompositionValidator) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

RMDataFormat (org.ehrbase.serialisation.RMDataFormat)13 FlatJasonProvider (org.ehrbase.serialisation.flatencoding.FlatJasonProvider)13 Composition (com.nedap.archie.rm.composition.Composition)11 LightRawJsonEncoder (org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder)7 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)7 TestDataTemplateProvider (org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider)7 Test (org.junit.Test)6 Ignore (org.junit.Ignore)5 IOException (java.io.IOException)4 StandardCharsets (java.nio.charset.StandardCharsets)4 IOUtils (org.apache.commons.io.IOUtils)4 FlatFormat (org.ehrbase.serialisation.flatencoding.FlatFormat)4 SoftAssertions (org.assertj.core.api.SoftAssertions)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 RMObject (com.nedap.archie.rm.RMObject)2 List (java.util.List)2 ArrayUtils (org.apache.commons.lang3.ArrayUtils)2 TestDataTemplateProvider (org.ehrbase.client.templateprovider.TestDataTemplateProvider)2 TestDataTemplateProvider (org.ehrbase.conformance_test.templateprovider.TestDataTemplateProvider)2