Search in sources :

Example 6 with Document

use of org.jbpm.document.Document in project jbpm by kiegroup.

the class DocumentStorageServiceImplTest method testListDocumentsLessThanPageSize.

@Test
public void testListDocumentsLessThanPageSize() {
    byte[] content = "yet another document content".getBytes();
    Document document = documentStorageService.buildDocument("mydoc", content.length, new Date(), new HashMap<String, String>());
    assertNotNull(document.getIdentifier());
    documentStorageService.saveDocument(document, content);
    List<Document> docs = documentStorageService.listDocuments(0, 5);
    assertNotNull(docs);
    assertEquals(1, docs.size());
    assertEquals("mydoc", docs.get(0).getName());
}
Also used : Document(org.jbpm.document.Document) Date(java.util.Date) Test(org.junit.Test)

Example 7 with Document

use of org.jbpm.document.Document in project jbpm by kiegroup.

the class DocumentStorageServiceImplTest method testSaveAndDeleteDocument.

@Test
public void testSaveAndDeleteDocument() {
    byte[] content = "another document content".getBytes();
    Document document = documentStorageService.buildDocument("mydoc", content.length, new Date(), new HashMap<String, String>());
    assertNotNull(document.getIdentifier());
    documentStorageService.saveDocument(document, content);
    Document fromStorage = documentStorageService.getDocument(document.getIdentifier());
    assertNotNull(fromStorage);
    assertEquals(document.getIdentifier(), fromStorage.getIdentifier());
    assertEquals(document.getName(), fromStorage.getName());
    assertEquals(content.length, fromStorage.getContent().length);
    documentStorageService.deleteDocument(fromStorage);
    fromStorage = documentStorageService.getDocument(document.getIdentifier());
    assertNull(fromStorage);
}
Also used : Document(org.jbpm.document.Document) Date(java.util.Date) Test(org.junit.Test)

Example 8 with Document

use of org.jbpm.document.Document in project jbpm by kiegroup.

the class DocumentStorageServiceImplTest method testSaveAndListDocuments.

@Test
public void testSaveAndListDocuments() {
    long lastModified = System.currentTimeMillis() - 10000;
    for (int i = 0; i < 10; i++) {
        byte[] content = (i + " another document content").getBytes();
        Document document = documentStorageService.buildDocument("mydoc" + i, content.length, new Date(lastModified + i * 1000), new HashMap<String, String>());
        assertNotNull(document.getIdentifier());
        documentStorageService.saveDocument(document, content);
    }
    List<Document> docs = documentStorageService.listDocuments(0, 5);
    assertNotNull(docs);
    assertEquals(5, docs.size());
    assertEquals("mydoc" + 0, docs.get(0).getName());
    assertEquals("mydoc" + 1, docs.get(1).getName());
    assertEquals("mydoc" + 2, docs.get(2).getName());
    assertEquals("mydoc" + 3, docs.get(3).getName());
    assertEquals("mydoc" + 4, docs.get(4).getName());
    docs = documentStorageService.listDocuments(1, 5);
    assertNotNull(docs);
    assertEquals(5, docs.size());
    assertEquals("mydoc" + 5, docs.get(0).getName());
    assertEquals("mydoc" + 6, docs.get(1).getName());
    assertEquals("mydoc" + 7, docs.get(2).getName());
    assertEquals("mydoc" + 8, docs.get(3).getName());
    assertEquals("mydoc" + 9, docs.get(4).getName());
    docs = documentStorageService.listDocuments(1, 2);
    assertNotNull(docs);
    assertEquals(2, docs.size());
    assertEquals("mydoc" + 2, docs.get(0).getName());
    assertEquals("mydoc" + 3, docs.get(1).getName());
}
Also used : Document(org.jbpm.document.Document) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Document

use of org.jbpm.document.Document in project jbpm by kiegroup.

the class DocumentStorageServiceImplTest method testListDocumentsNonexistentDocsFolder.

@Test
public void testListDocumentsNonexistentDocsFolder() {
    // Delete document storage contents AND the dir itself
    File docsDir = new File(STORAGE_PATH_TEST);
    deleteFolder(docsDir);
    docsDir.delete();
    List<Document> docs = documentStorageService.listDocuments(0, 10);
    assertTrue("When documents directory doesn't exist, empty doc list should be returned", docs.isEmpty());
}
Also used : Document(org.jbpm.document.Document) File(java.io.File) Test(org.junit.Test)

Example 10 with Document

use of org.jbpm.document.Document in project jbpm by kiegroup.

the class DocumentImplTest method testConstructorWithoutIdentifier.

@Test
public void testConstructorWithoutIdentifier() {
    Document document = new DocumentImpl(NAME, SIZE, LAST_MODIFIED);
    Assertions.assertThat(document.getIdentifier()).isNotNull();
    Assertions.assertThat(document.getName()).isNotNull().isEqualTo(NAME);
    Assertions.assertThat(document.getSize()).isEqualTo(SIZE);
    Assertions.assertThat(document.getLastModified()).isEqualTo(LAST_MODIFIED);
}
Also used : Document(org.jbpm.document.Document) Test(org.junit.Test)

Aggregations

Document (org.jbpm.document.Document)38 Test (org.junit.Test)21 Date (java.util.Date)14 DocumentImpl (org.jbpm.document.service.impl.DocumentImpl)9 HashMap (java.util.HashMap)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DocumentData (org.kie.workbench.common.forms.dynamic.model.document.DocumentData)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Documents (org.jbpm.document.Documents)3 Drive (com.google.api.services.drive.Drive)2 VisualRecognition (com.ibm.watson.developer_cloud.visual_recognition.v3.VisualRecognition)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 DroolsObjectInputStream (org.drools.core.common.DroolsObjectInputStream)2 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)2 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)2 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)2