Search in sources :

Example 1 with CompositionTestDataCanonicalXML

use of org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML in project openEHR_SDK by ehrbase.

the class DBEncodeTest method testDBEncodeDecode.

/**
 * Encode an RM composition content part into its JSON DB equivalent (which is normally stored as a jsonb type)
 * then convert this JSON DB structure into a RAW (canonical) JSON that can be interpreted by ARCHIE.
 * Test the transformation render a valid RM composition.
 * NB. At this stage, the tests are fairly basic, what is needed is an actual comparison between the original
 * composition and the resulting one after the transformation cycle.
 *
 * @throws Exception
 */
@Test
public void testDBEncodeDecode() throws Exception {
    for (CompositionTestDataCanonicalXML compositionTestDataCanonicalXML : canonicals) {
        Composition composition = new CanonicalXML().unmarshal(IOUtils.toString(compositionTestDataCanonicalXML.getStream(), UTF_8), Composition.class);
        assertNotNull(composition);
        CompositionSerializer compositionSerializerRawJson = new CompositionSerializer();
        String db_encoded = compositionSerializerRawJson.dbEncode(composition);
        assertNotNull(db_encoded);
        String converted = new LightRawJsonEncoder(db_encoded).encodeCompositionAsString();
        // see if this can be interpreted by Archie
        Composition object = new CanonicalJson().unmarshal(converted, Composition.class);
        assertNotNull(object);
        // check if encoded/decode carry the same name
        assertThat(composition.getName().getValue()).isEqualTo(object.getName().getValue());
        String interpreted = new CanonicalXML().marshal(object);
        assertNotNull(interpreted);
    }
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) LightRawJsonEncoder(org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder) CompositionTestDataCanonicalXML(org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML) CanonicalXML(org.ehrbase.serialisation.xmlencoding.CanonicalXML) CompositionTestDataCanonicalXML(org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML) Test(org.junit.Test)

Aggregations

Composition (com.nedap.archie.rm.composition.Composition)1 LightRawJsonEncoder (org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder)1 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)1 CanonicalXML (org.ehrbase.serialisation.xmlencoding.CanonicalXML)1 CompositionTestDataCanonicalJson (org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson)1 CompositionTestDataCanonicalXML (org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML)1 Test (org.junit.Test)1