Search in sources :

Example 1 with RMObjectValidator

use of com.nedap.archie.rmobjectvalidator.RMObjectValidator in project openEHR_SDK by ehrbase.

the class StructuredJsonTest method test.

private void test(CompositionTestDataStructuredJson testData, String templateId) throws IOException {
    RMDataFormat cut = new FlatJasonProvider(templateProvider).buildFlatJson(FlatFormat.STRUCTURED, templateId);
    String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
    Composition unmarshal = cut.unmarshal(flat);
    SoftAssertions softAssertions = new SoftAssertions();
    softAssertions.assertThat(unmarshal).isNotNull();
    RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
    softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
    String actual = cut.marshal(unmarshal);
    String expected = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
    JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
}
Also used : CompositionTestDataStructuredJson(org.ehrbase.test_data.composition.CompositionTestDataStructuredJson) SoftAssertions(org.assertj.core.api.SoftAssertions) Composition(com.nedap.archie.rm.composition.Composition) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) JSONAssert(org.skyscreamer.jsonassert.JSONAssert) Test(org.junit.jupiter.api.Test) IOUtils(org.apache.commons.io.IOUtils) TestDataTemplateProvider(org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) JSONCompareMode(org.skyscreamer.jsonassert.JSONCompareMode) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator) Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator)

Example 2 with RMObjectValidator

use of com.nedap.archie.rmobjectvalidator.RMObjectValidator in project openEHR_SDK by ehrbase.

the class FlatJsonTest method check.

private void check(String templateId, CompositionTestDataSimSDTJson testData, String[] expectedMissing, String[] expectedExtra) throws IOException {
    RMDataFormat cut = new FlatJasonProvider(templateProvider).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();
    RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
    softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
    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 : SoftAssertions(org.assertj.core.api.SoftAssertions) Composition(com.nedap.archie.rm.composition.Composition) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test) IOException(java.io.IOException) 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) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator) Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator)

Example 3 with RMObjectValidator

use of com.nedap.archie.rmobjectvalidator.RMObjectValidator in project openEHR_SDK by ehrbase.

the class FlatJsonTest method roundTripRaw.

@Test
public void roundTripRaw() throws IOException {
    CompositionTestDataSimSDTJson testData = CompositionTestDataSimSDTJson.CORONA_WITH_RAW;
    String templateId = "Corona_Anamnese";
    RMDataFormat cut = new FlatJasonProvider(templateProvider).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();
    RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
    softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
    String actual = cut.marshal(unmarshal);
    String expected = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA.getStream(), StandardCharsets.UTF_8);
    List<String> errors = compere(actual, expected);
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder();
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder();
    softAssertions.assertAll();
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Composition(com.nedap.archie.rm.composition.Composition) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test) IOException(java.io.IOException) 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) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator) Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test)

Example 4 with RMObjectValidator

use of com.nedap.archie.rmobjectvalidator.RMObjectValidator in project openEHR_SDK by ehrbase.

the class FlatJsonTest method roundTripFeederAuditRaw.

@Test
public void roundTripFeederAuditRaw() throws IOException {
    CompositionTestDataSimSDTJson testData = CompositionTestDataSimSDTJson.CORONA_WITH_FEEDER_AUDIT_RAW;
    String templateId = "Corona_Anamnese";
    RMDataFormat cut = new FlatJasonProvider(templateProvider).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();
    RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
    softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
    String actual = cut.marshal(unmarshal);
    String expected = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA_WITH_FEEDER_AUDIT.getStream(), StandardCharsets.UTF_8);
    List<String> errors = compere(actual, expected);
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder();
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder();
    softAssertions.assertAll();
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Composition(com.nedap.archie.rm.composition.Composition) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test) IOException(java.io.IOException) 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) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator) Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test)

Aggregations

Composition (com.nedap.archie.rm.composition.Composition)4 ArchieRMInfoLookup (com.nedap.archie.rminfo.ArchieRMInfoLookup)4 RMObjectValidator (com.nedap.archie.rmobjectvalidator.RMObjectValidator)4 IOException (java.io.IOException)4 StandardCharsets (java.nio.charset.StandardCharsets)4 IOUtils (org.apache.commons.io.IOUtils)4 SoftAssertions (org.assertj.core.api.SoftAssertions)4 RMDataFormat (org.ehrbase.serialisation.RMDataFormat)4 TestDataTemplateProvider (org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider)4 OperationalTemplateTestData (org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData)4 List (java.util.List)3 FlatJsonMarshallerTest.compere (org.ehrbase.serialisation.flatencoding.std.marshal.FlatJsonMarshallerTest.compere)3 CompositionTestDataSimSDTJson (org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson)3 Test (org.junit.Test)3 CompositionTestDataStructuredJson (org.ehrbase.test_data.composition.CompositionTestDataStructuredJson)1 Test (org.junit.jupiter.api.Test)1 JSONAssert (org.skyscreamer.jsonassert.JSONAssert)1 JSONCompareMode (org.skyscreamer.jsonassert.JSONCompareMode)1