Search in sources :

Example 11 with ItemStructure

use of com.nedap.archie.rm.datastructures.ItemStructure in project ehrbase by ehrbase.

the class FolderAccessTest method shouldInsertFolderWithNoSubfolders.

@Test
@Ignore
public void shouldInsertFolderWithNoSubfolders() throws Exception {
    // the creation and commit returning valid ids implies that the FolderMockDataProvider.java has provided the corresponding result for each SQL generated when inserting
    // create folder to insert
    Folder folder = new Folder();
    UIDBasedId uid = new ObjectVersionId("f8a2af65-fe89-45a4-9456-07c5e17b1634");
    ObjectVersionId uidim = new ObjectVersionId("f8a2af65-fe89-45a4-9456-07c5e17b1634");
    folder.setUid(uid);
    DvText name = new DvText();
    name.setValue("nameOfFolder");
    folder.setName(name);
    folder.setArchetypeNodeId("archetype_1");
    ItemStructure is = new ItemStructure() {

        @Override
        public List getItems() {
            Item item = new Item() {

                @Override
                public DvText getName() {
                    return new DvText("fol1");
                }
            };
            List<Item> items = new ArrayList<>();
            items.add(item);
            return items;
        }
    };
    folder.setDetails(is);
    // insert folder
    FolderAccess fa1 = new FolderAccess(testDomainAccess);
    FolderAccess fa2 = (FolderAccess) FolderAccess.getNewFolderAccessInstance(fa1, folder, DateTime.now(), UUID.fromString("f6a2af65-fe89-45a4-9456-07c5e17b1634"));
    assertEquals("f8a2af65-fe89-45a4-9456-07c5e17b1634", fa2.getFolderRecord().getId().toString());
    assertEquals("archetype_1", fa2.getFolderRecord().getArchetypeNodeId());
    assertEquals("nameOfFolder", fa2.getFolderRecord().getName());
    String expected = ("'{\n" + "  \"_type\" : \"\",\n" + "  \"items\" : [ {\n" + "    \"name\" : {\n" + "      \"_type\" : \"DV_TEXT\",\n" + "      \"value\" : \"fol1\"\n" + "    }\n" + "  } ]\n" + "}'::jsonb").replaceAll("\\n|\\r\\n", // avoids problems amond different platforms due to different representations of line change.
    System.getProperty("line.separator"));
    StringWriter expectedStringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(expectedStringWriter);
    // avoids problems amond different platforms due to different representations of line change.
    printWriter.print(expected);
    printWriter.close();
    assertEquals(expectedStringWriter.toString(), fa2.getFolderRecord().getDetails().toString());
    // commit and check returned UID is the valid one
    UUID storedFolderUid = fa2.commit(LocalDateTime.now(), UUID.randomUUID());
    assertEquals("f8a2af65-fe89-45a4-9456-07c5e17b1634", storedFolderUid.toString());
}
Also used : UIDBasedId(com.nedap.archie.rm.support.identification.UIDBasedId) ArrayList(java.util.ArrayList) ItemStructure(com.nedap.archie.rm.datastructures.ItemStructure) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) Folder(com.nedap.archie.rm.directory.Folder) DvText(com.nedap.archie.rm.datavalues.DvText) I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess) Item(com.nedap.archie.rm.datastructures.Item) StringWriter(java.io.StringWriter) UUID(java.util.UUID) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ItemStructure (com.nedap.archie.rm.datastructures.ItemStructure)11 Test (org.junit.Test)7 Item (com.nedap.archie.rm.datastructures.Item)4 DvText (com.nedap.archie.rm.datavalues.DvText)4 ArrayList (java.util.ArrayList)4 Timestamp (java.sql.Timestamp)3 I_FolderAccess (org.ehrbase.dao.access.interfaces.I_FolderAccess)3 Ignore (org.junit.Ignore)3 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)2 Folder (com.nedap.archie.rm.directory.Folder)2 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)2 UIDBasedId (com.nedap.archie.rm.support.identification.UIDBasedId)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 SQLException (java.sql.SQLException)2 OffsetDateTime (java.time.OffsetDateTime)2 UUID (java.util.UUID)2 DateTime (org.joda.time.DateTime)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2 MockResult (org.jooq.tools.jdbc.MockResult)2