use of org.incode.module.document.dom.impl.docs.Document in project estatio by estatio.
the class Order_2_IntegTest method orderFixtureLoadedProperly.
@Test
public void orderFixtureLoadedProperly() throws Exception {
assertThat(orderRepository.listAll().size()).isEqualTo(1);
List<Document> unclassifiedIncomingOrders = incomingDocumentRepository.findUnclassifiedIncomingOrders();
assertThat(unclassifiedIncomingOrders.size()).isEqualTo(0);
final String documentName = Order_enum.fakeOrder2Pdf.getDocument_d().findUsing(serviceRegistry).getName();
Document document = incomingDocumentRepository.findAllIncomingDocumentsByName(documentName).get(0);
List<IncomingDocumentCategorisationStateTransition> transitions = mixin(Document_categorisationTransitions.class, document).coll();
assertThat(transitions.size()).isEqualTo(2);
}
use of org.incode.module.document.dom.impl.docs.Document in project estatio by estatio.
the class DocumentMenu_Upload_IntegTest method happy_case.
@Test
public void happy_case() throws Exception {
// given
List<Document> incomingDocumentsBefore = repository.findIncomingDocuments();
assertThat(incomingDocumentsBefore).isEmpty();
// when
final String fileName = "1020100123.pdf";
final byte[] pdfBytes = Resources.toByteArray(Resources.getResource(DocumentMenu_Upload_IntegTest.class, fileName));
final Blob blob = new Blob(fileName, "application/pdf", pdfBytes);
wrap(documentMenu).upload(blob);
transactionService.nextTransaction();
// then
List<Document> incomingDocumentsAfter = repository.findAllIncomingDocuments();
assertThat(incomingDocumentsAfter).hasSize(1);
final Document document = incomingDocumentsAfter.get(0);
final Blob documentBlob = document.getBlob();
assertThat(documentBlob.getName()).isEqualTo(blob.getName());
assertThat(documentBlob.getMimeType().getBaseType()).isEqualTo(blob.getMimeType().getBaseType());
assertThat(documentBlob.getBytes()).isEqualTo(blob.getBytes());
assertThat(JDOHelper.getVersion(document)).isEqualTo(1L);
assertThat(paperclipRepository.findByDocument(document).size()).isEqualTo(0);
// and then also
final List<IncomingDocumentCategorisationStateTransition> transitions = stateTransitionRepository.findByDomainObject(document);
assertThat(transitions).hasSize(2);
assertTransition(transitions.get(0), NEW, CATEGORISE, null);
assertTransition(transitions.get(1), null, INSTANTIATE, NEW);
// and when
final String fileName2 = "1020100123-altered.pdf";
final byte[] pdfBytes2 = Resources.toByteArray(Resources.getResource(DocumentMenu_Upload_IntegTest.class, fileName2));
final Blob similarNamedBlob = new Blob(fileName, "application/pdf", pdfBytes2);
wrap(documentMenu).upload(similarNamedBlob);
transactionService.nextTransaction();
// then
incomingDocumentsAfter = repository.findAllIncomingDocuments();
assertThat(incomingDocumentsAfter).hasSize(2);
assertThat(incomingDocumentsAfter.get(0).getName()).isEqualTo(fileName);
assertThat(incomingDocumentsAfter.get(0).getBlobBytes()).isEqualTo(similarNamedBlob.getBytes());
assertThat(JDOHelper.getVersion(incomingDocumentsAfter.get(0))).isEqualTo(2L);
assertThat(paperclipRepository.findByDocument(incomingDocumentsAfter.get(0)).size()).isEqualTo(1);
// has prefix arch-[date time indication]-
assertThat(incomingDocumentsAfter.get(1).getName()).contains(fileName);
assertThat(incomingDocumentsAfter.get(1).getBlobBytes()).isEqualTo(documentBlob.getBytes());
assertThat(JDOHelper.getVersion(incomingDocumentsAfter.get(1))).isEqualTo(1L);
assertThat(paperclipRepository.findByDocument(incomingDocumentsAfter.get(1)).size()).isEqualTo(0);
}
Aggregations