Search in sources :

Example 1 with TestDataTemplateProvider

use of org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider 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 2 with TestDataTemplateProvider

use of org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider 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 3 with TestDataTemplateProvider

use of org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider in project openEHR_SDK by ehrbase.

the class DBEncodeRoundTripTest method testCountRoundTrip.

@Test
@Ignore
public void testCountRoundTrip() throws IOException {
    String value = new String(Files.readAllBytes(Paths.get("src/test/resources/sample_data/test_all_type_count_flat.json")));
    RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, "test_all_types.en.v1");
    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 4 with TestDataTemplateProvider

use of org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider in project openEHR_SDK by ehrbase.

the class DBEncodeRoundTripTest method testMathFunctionRoundTrip.

@Test
@Ignore
public void testMathFunctionRoundTrip() throws IOException {
    String value = new String(Files.readAllBytes(Paths.get("src/test/resources/sample_data/corona_math_function_flat.json")));
    RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, "Corona_Anamnese");
    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 5 with TestDataTemplateProvider

use of org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider in project openEHR_SDK by ehrbase.

the class DBEncodeRoundTripTest 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);
    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);
    List<String> errors = compere(actualFlat, value);
    softly.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.missing);
    String[] extra = { "Extra path: test_all_types/test_all_types:0/identifier, value: 55175056", "Extra path: test_all_types/test_all_types:0/proportion_any|type, value: 1.0" };
    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) 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)

Aggregations

RMDataFormat (org.ehrbase.serialisation.RMDataFormat)7 FlatJasonProvider (org.ehrbase.serialisation.flatencoding.FlatJasonProvider)7 TestDataTemplateProvider (org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider)7 Composition (com.nedap.archie.rm.composition.Composition)6 LightRawJsonEncoder (org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder)6 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)6 Test (org.junit.Test)6 Ignore (org.junit.Ignore)5 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 List (java.util.List)1 IOUtils (org.apache.commons.io.IOUtils)1 SoftAssertions (org.assertj.core.api.SoftAssertions)1 FlatFormat (org.ehrbase.serialisation.flatencoding.FlatFormat)1 FlatJsonMarshallerTest.compere (org.ehrbase.serialisation.flatencoding.std.marshal.FlatJsonMarshallerTest.compere)1 CompositionTestDataSimSDTJson (org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson)1 CompositionTestDataStructuredJson (org.ehrbase.test_data.composition.CompositionTestDataStructuredJson)1 OperationalTemplateTestData (org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData)1 JSONAssert (org.skyscreamer.jsonassert.JSONAssert)1 JSONCompareMode (org.skyscreamer.jsonassert.JSONCompareMode)1