Package org.apache.chemistry.opencmis.client.api

Examples of org.apache.chemistry.opencmis.client.api.Document


    @Test
    public void deleteAndCreateContent() throws IOException {
        // verify content

        String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME;
        Document document = (Document) this.session.getObjectByPath(path);
        assertNotNull("Document not found: " + path, document);

        // check default content
        ContentStream contentStream = document.getContentStream();
        assertNotNull(contentStream);
        String contentString = this.getContentAsString(contentStream);
        assertNotNull(contentString);

        // delete and set new content
        // ObjectId id = (return id not supported by AtomPub)
        document.deleteContentStream();
        // assertNotNull(id);

        String filename = UUID.randomUUID().toString();
        String mimetype = "text/html; charset=UTF-8";
        String content1 = "Im Walde rauscht ein Wasserfall. Wenn's nicht mehr rauscht ist's Wasser all.";

        byte[] buf1 = content1.getBytes("UTF-8");
        ByteArrayInputStream in1 = new ByteArrayInputStream(buf1);
        contentStream = this.session.getObjectFactory().createContentStream(filename, buf1.length, mimetype, in1);
        assertNotNull(contentStream);

        document.setContentStream(contentStream, true);

        // check default content
        ContentStream contentStream2 = document.getContentStream();
        assertNotNull(contentStream2);
        String contentString2 = this.getContentAsString(contentStream2);
        assertNotNull(contentString2);

        assertEquals(content1, contentString2);
View Full Code Here


    @Test
    public void updateProperties() {
        // verify content
        String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME;
        Document document = (Document) this.session.getObjectByPath(path);
        assertNotNull("Document not found: " + path, document);

        // TODO: adapt test to refactored interface
        // document.setProperty(PropertyIds.NAME, "Neuer Name");
        // document.updateProperties();
View Full Code Here

    @Test
    public void updateSinglePropertyAndCheckName() {
        // verify content
        String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME;
        Document document = (Document) this.session.getObjectByPath(path);
        assertNotNull("Document not found: " + path, document);

        String value = UUID.randomUUID().toString();
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.CHECKIN_COMMENT, value);

        String id = document.getId();
        assertNotNull(id);

        // update single property
        ObjectId newId = document.updateProperties(properties);
        assertNotNull(newId);
        assertEquals(id, newId.getId()); // should not be a new version

        session.clear();

        // verify
        String s1 = FixtureData.DOCUMENT1_NAME.toString();
        String s2 = document.getName();
        assertEquals(s1, s2);

        Property<String> p = document.getProperty(PropertyIds.NAME);
        String s3 = p.getFirstValue();
        assertEquals(s1, s3);

        Document document2 = (Document) this.session.getObjectByPath(path);
        assertNotNull("Document not found: " + path, document2);
    }
View Full Code Here

        ObjectId id = this.session.createDocument(properties, parentId, null, VersioningState.NONE);
        assertNotNull(id);

        // set and verify content
        Document doc = (Document) this.session.getObject(id);
        assertNotNull(doc);
        doc.setContentStream(contentStream, true);

        doc.refresh();
        assertEquals(buf1.length, doc.getContentStreamLength());
        assertEquals(mimetype, doc.getContentStreamMimeType());
        assertEquals(filename, doc.getContentStreamFileName());
        String content2 = this.getContentAsString(doc.getContentStream());
        assertEquals(content1, content2);
    }
View Full Code Here

        ObjectId id = this.session.createDocument(properties, parentId, null, VersioningState.NONE);
        assertNotNull(id);

        // set and verify content
        Document doc = (Document) this.session.getObject(id);
        assertNotNull(doc);
        doc.setContentStream(contentStream, false);

        doc.refresh();
        assertEquals(buf1.length, doc.getContentStreamLength());
        assertEquals(mimetype, doc.getContentStreamMimeType());
        assertEquals(filename, doc.getContentStreamFileName());
        String content2 = this.getContentAsString(doc.getContentStream());
        assertEquals(content1, content2);
    }
View Full Code Here

        ByteArrayInputStream in2 = new ByteArrayInputStream(buf2);
        ContentStream contentStream2 = this.session.getObjectFactory().createContentStream(filename2, buf2.length,
                mimetype, in2);
        assertNotNull(contentStream2);

        Document doc = (Document) this.session.getObject(id);
        assertNotNull(doc);
        doc.setContentStream(contentStream2, true);

        doc.refresh();
        assertEquals(buf2.length, doc.getContentStreamLength());
        assertEquals(mimetype, doc.getContentStreamMimeType());
        assertEquals(filename2, doc.getContentStreamFileName());
        String content3 = this.getContentAsString(doc.getContentStream());
        assertEquals(content2, content3);
    }
View Full Code Here

        ByteArrayInputStream in2 = new ByteArrayInputStream(buf2);
        ContentStream contentStream2 = this.session.getObjectFactory().createContentStream(filename2, buf2.length,
                mimetype, in2);
        assertNotNull(contentStream2);

        Document doc = (Document) this.session.getObject(id);
        assertNotNull(doc);
        doc.setContentStream(contentStream2, false);

        doc.refresh();
        assertEquals(buf2.length, doc.getContentStreamLength());
        assertEquals(mimetype, doc.getContentStreamMimeType());
        assertEquals(filename2, doc.getContentStreamFileName());
        String content3 = this.getContentAsString(doc.getContentStream());
        assertEquals(content2, content3);
    }
View Full Code Here

    @Before
    public void checkOutVersionableDocument() {
        /* check out one versionable document */
        String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME;
        Document document = (Document) this.session.getObjectByPath(path);
        assertNotNull("Document not found: " + path, document);
        DocumentType dt = (DocumentType) document.getType();
        assertNotNull(dt);
        if (dt.isVersionable() != null && dt.isVersionable().booleanValue()) {
            this.checkdOutId = document.checkOut();
        }
    }
View Full Code Here

        assertNotNull(folderId);

        // get the document
        String pathd = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
                + FixtureData.DOCUMENT1_NAME;
        Document document = (Document) session.getObjectByPath(pathd);

        // move document into new folder
        FileableCmisObject newdoc = document.move(testRoot, folderId);

        assertEquals(pathr + "/newfolder/" + FixtureData.DOCUMENT1_NAME,
                newdoc.getPaths().get(0));
    }
View Full Code Here

public abstract class AbstractReadOnlyContentStreamIT extends AbstractSessionTest {

    @Test
    public void readContentStream() throws IOException {
        String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME.toString();
        Document document = (Document) this.session.getObjectByPath(path);
        Assert.assertNotNull("document not found: " + path, document);

        ContentStream s = document.getContentStream();

        Assert.assertNotNull(s.getMimeType());
        s.getLength();
        s.getFileName();

        InputStream is = s.getStream();
        Assert.assertNotNull(is);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        baos.write(is.read());
        byte[] b = baos.toByteArray();

        Assert.assertNotNull(b);
        Assert.assertTrue(b.length > 0);

        // unknown content stream -> null
        s = document.getContentStream("nosuchstream");
        Assert.assertNull(s);
    }
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.client.api.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.