Search in sources :

Example 96 with Document

use of io.atlasmap.v2.Document in project mycore by MyCoRe-Org.

the class MCRMetadataStoreTest method exists.

@Test
public void exists() throws Exception {
    int id = getMetaDataStore().getNextFreeID();
    assertFalse(getMetaDataStore().exists(id));
    Document xml1 = new Document(new Element("root"));
    getMetaDataStore().create(new MCRJDOMContent(xml1), id);
    assertTrue(getMetaDataStore().exists(id));
    getMetaDataStore().delete(id);
    assertFalse(getMetaDataStore().exists(id));
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Test(org.junit.Test)

Example 97 with Document

use of io.atlasmap.v2.Document in project mycore by MyCoRe-Org.

the class MCRMetadataStoreTest method lastModified.

@Test
public void lastModified() throws Exception {
    Document xml1 = new Document(new Element("root"));
    Date date1 = new Date();
    synchronized (this) {
        wait(1000);
    }
    MCRStoredMetadata sm = getMetaDataStore().create(new MCRJDOMContent(xml1));
    Date date2 = sm.getLastModified();
    assertTrue(date2.after(date1));
    synchronized (this) {
        wait(1000);
    }
    Document xml2 = new Document(new Element("root"));
    sm.update(new MCRJDOMContent(xml2));
    assertTrue(sm.getLastModified().after(date2));
    @SuppressWarnings("deprecation") Date date = new Date(109, 1, 1);
    sm.setLastModified(date);
    sm = getMetaDataStore().retrieve(sm.getID());
    assertEquals(date, sm.getLastModified());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Date(java.util.Date) Test(org.junit.Test)

Example 98 with Document

use of io.atlasmap.v2.Document in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStoreTest method delete.

@Test
public void delete() throws Exception {
    System.out.println("TEST DELETE");
    Document xml1 = new Document(new Element("root"));
    int id = getVersStore().create(new MCRJDOMContent(xml1)).getID();
    assertTrue(getVersStore().exists(id));
    getVersStore().delete(id);
    assertFalse(getVersStore().exists(id));
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Test(org.junit.Test)

Example 99 with Document

use of io.atlasmap.v2.Document in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStoreTest method createUpdateDeleteCreate.

@Test
public void createUpdateDeleteCreate() throws Exception {
    Element root = new Element("bingo");
    Document xml1 = new Document(root);
    MCRVersionedMetadata vm = getVersStore().create(new MCRJDOMContent(xml1));
    root.setName("bango");
    vm.update(new MCRJDOMContent(xml1));
    vm.delete();
    root.setName("bongo");
    vm = getVersStore().create(new MCRJDOMContent(xml1), vm.getID());
    List<MCRMetadataVersion> versions = vm.listVersions();
    assertEquals(4, versions.size());
    assertEquals(MCRMetadataVersion.CREATED, versions.get(0).getType());
    assertEquals(MCRMetadataVersion.UPDATED, versions.get(1).getType());
    assertEquals(MCRMetadataVersion.DELETED, versions.get(2).getType());
    assertEquals(MCRMetadataVersion.CREATED, versions.get(3).getType());
    versions.get(1).restore();
    assertEquals("bango", vm.getMetadata().asXML().getRootElement().getName());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Test(org.junit.Test)

Example 100 with Document

use of io.atlasmap.v2.Document in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStoreTest method createDocument.

@Test
public void createDocument() throws Exception {
    Document testXmlDoc = new Document(new Element("root"));
    MCRContent testContent = new MCRJDOMContent(testXmlDoc);
    MCRVersionedMetadata versionedMetadata = getVersStore().create(testContent);
    MCRContent contentFromStore = getVersStore().retrieve(versionedMetadata.getID()).getMetadata();
    String contentStrFromStore = contentFromStore.asString();
    MCRContent mcrContent = new MCRJDOMContent(testXmlDoc);
    String expectedContentStr = mcrContent.asString();
    assertNotNull(versionedMetadata);
    assertEquals(expectedContentStr, contentStrFromStore);
    assertTrue(versionedMetadata.getID() > 0);
    assertTrue(versionedMetadata.getRevision() > 0);
    MCRVersionedMetadata vm3 = getVersStore().create(new MCRJDOMContent(testXmlDoc));
    assertTrue(vm3.getID() > versionedMetadata.getID());
    assertTrue(vm3.getRevision() > versionedMetadata.getRevision());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent) Test(org.junit.Test)

Aggregations

Document (org.jdom2.Document)403 Element (org.jdom2.Element)248 Test (org.junit.Test)111 SAXBuilder (org.jdom2.input.SAXBuilder)95 IOException (java.io.IOException)74 File (java.io.File)58 XMLOutputter (org.jdom2.output.XMLOutputter)55 JDOMException (org.jdom2.JDOMException)44 Field (io.atlasmap.v2.Field)40 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 ArrayList (java.util.ArrayList)30 Test (org.junit.jupiter.api.Test)27 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 InputStream (java.io.InputStream)23 JsonField (io.atlasmap.json.v2.JsonField)22 MCRContent (org.mycore.common.content.MCRContent)22 Document (com.google.cloud.language.v1.Document)21 HashMap (java.util.HashMap)21 MCRException (org.mycore.common.MCRException)21