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