package com.nedap.archie.json;

import com.nedap.archie.aom.Archetype;
import com.nedap.archie.aom.CComplexObject;
import com.nedap.archie.rm.datastructures.Cluster;
import com.nedap.archie.serializer.adl.ADLArchetypeSerializer;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

/**
 * A test that tests JSON parsing of Archetypes using Jackson
 *
 * Created by pieter.bos on 06/07/16.
 */
public class AOMParseTest {



    @Test
    public void parseDeliriumObservationScreening() throws Exception {
        try(InputStream stream = getClass().getResourceAsStream("delirium_observation_screening.json")) {
            Archetype archetype = JacksonUtil.getObjectMapper().readValue(stream, Archetype.class);
            System.out.println(archetype);
            assertTrue(archetype.getGenerated());
            assertThat(archetype.getArchetypeId().getFullId(), is("openEHR-EHR-GENERIC_ENTRY.delirium_observation_screening.v1.0.0"));
            assertThat(archetype.getDefinition().getRmTypeName(), is("GENERIC_ENTRY"));
            CComplexObject cluster = archetype.getDefinition().itemAtPath("/data[id2]/items[id3]/items[id4]");
            assertThat(cluster.getRmTypeName(), is("CLUSTER"));
            assertThat(cluster.getNodeId(), is("id4"));
            assertThat(cluster.getParent(), is(equalTo(archetype.getDefinition().itemAtPath("/data[id2]/items[id3]/items"))));
            assertEquals("Groep1", cluster.getTerm().getText());
            System.out.println(ADLArchetypeSerializer.serialize(archetype));
        }
    }
}

@@ -1641,11 +1641,544 @@
  %7D%0A    %7D
+%0A%0A    @Test%0A    public void roundTripDeliriumObservationScreening() throws Exception %7B%0A        try(InputStream stream = getClass().getResourceAsStream(%22delirium_observation_screening.json%22)) %7B%0A            Archetype archetype = JacksonUtil.getObjectMapper().readValue(stream, Archetype.class);%0A            String reserialized = JacksonUtil.getObjectMapper().writeValueAsString(archetype);%0A            System.out.println(reserialized);%0A            JacksonUtil.getObjectMapper().readValue(reserialized, Archetype.class);%0A        %7D%0A    %7D
 %0A%7D%0A

Add roundtrip test 1