Search in sources :

Example 31 with Document

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

the class DocumentsMarshallingStrategyTest method testSingleDocMarshallUnmarshallTracking.

@Test
public void testSingleDocMarshallUnmarshallTracking() throws IOException, ClassNotFoundException {
    final AtomicInteger counter = new AtomicInteger(0);
    DocumentMarshallingStrategy docMarshallingStrategy = new DocumentMarshallingStrategy(new CustomDocumentStorageServiceImpl() {

        @Override
        public Document saveDocument(Document document, byte[] content) {
            counter.incrementAndGet();
            return super.saveDocument(document, content);
        }
    });
    Document document = getDocument("docOne");
    byte[] marshalledDocument = docMarshallingStrategy.marshal(null, null, document);
    assertEquals(1, counter.get());
    Document unmarshalledDocument = (Document) docMarshallingStrategy.unmarshal(null, null, marshalledDocument, this.getClass().getClassLoader());
    assertEquals(document.getName(), unmarshalledDocument.getName());
    assertEquals(document.getLink(), unmarshalledDocument.getLink());
    // marhsall it again, it should not call the save on document service since document didn't change
    marshalledDocument = docMarshallingStrategy.marshal(null, null, unmarshalledDocument);
    assertEquals(1, counter.get());
    unmarshalledDocument.setContent("updated content".getBytes());
    marshalledDocument = docMarshallingStrategy.marshal(null, null, unmarshalledDocument);
    assertEquals(2, counter.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CustomDocumentStorageServiceImpl(org.jbpm.document.service.impl.CustomDocumentStorageServiceImpl) Document(org.jbpm.document.Document) Test(org.junit.Test)

Example 32 with Document

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

the class DocumentsMarshallingStrategyTest method testMarshallUnmarshall.

@Test
public void testMarshallUnmarshall() throws IOException, ClassNotFoundException {
    List<Document> documents = getDocuments();
    Documents docs = new Documents(documents);
    byte[] marshalledDocs = docsMarshallingStrategy.marshal(null, null, docs);
    Documents unmarshalledDocs = (Documents) docsMarshallingStrategy.unmarshal(null, null, marshalledDocs, this.getClass().getClassLoader());
    assertEquals(docs.getDocuments().size(), unmarshalledDocs.getDocuments().size());
    List<Document> unmarshalledDocumentsList = unmarshalledDocs.getDocuments();
    assertEquals(documents.size(), unmarshalledDocumentsList.size());
    assertEquals(unmarshalledDocumentsList.get(0).getName(), docs.getDocuments().get(0).getName());
    assertEquals(unmarshalledDocumentsList.get(0).getLink(), docs.getDocuments().get(0).getLink());
    assertEquals(unmarshalledDocumentsList.get(1).getName(), docs.getDocuments().get(1).getName());
    assertEquals(unmarshalledDocumentsList.get(1).getLink(), docs.getDocuments().get(1).getLink());
}
Also used : Documents(org.jbpm.document.Documents) Document(org.jbpm.document.Document) Test(org.junit.Test)

Example 33 with Document

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

the class DocumentStorageServiceImplTest method testSaveAndDeleteByIdDocument.

@Test
public void testSaveAndDeleteByIdDocument() {
    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);
    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.getIdentifier());
    fromStorage = documentStorageService.getDocument(document.getIdentifier());
    assertNull(fromStorage);
}
Also used : Document(org.jbpm.document.Document) Date(java.util.Date) Test(org.junit.Test)

Example 34 with Document

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

the class DocumentStorageServiceImplTest method testSaveAndGetDocument.

@Test
public void testSaveAndGetDocument() {
    byte[] content = "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);
}
Also used : Document(org.jbpm.document.Document) Date(java.util.Date) Test(org.junit.Test)

Example 35 with Document

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

the class DocumentImplTest method testConstructorWithIdentifier.

@Test
public void testConstructorWithIdentifier() {
    Document document = new DocumentImpl(ID, NAME, SIZE, LAST_MODIFIED);
    Assertions.assertThat(document.getIdentifier()).isNotNull().isEqualTo(ID);
    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