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());
}
Aggregations