Search in sources :

Example 1 with CustomDocumentStorageServiceImpl

use of org.jbpm.document.service.impl.CustomDocumentStorageServiceImpl 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)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Document (org.jbpm.document.Document)1 CustomDocumentStorageServiceImpl (org.jbpm.document.service.impl.CustomDocumentStorageServiceImpl)1 Test (org.junit.Test)1