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);
}
}
Aggregations