Search in sources :

Example 1 with BuyerFinder

use of org.estatio.module.capex.dom.documents.BuyerFinder in project estatio by estatio.

the class IncomingDocAsInvoiceViewModel_Test method notification_BuyerBarcodeMatchValidation_works.

@Test
public void notification_BuyerBarcodeMatchValidation_works() {
    String notification;
    // given
    IncomingDocAsInvoiceViewModel viewModel = new IncomingDocAsInvoiceViewModel();
    Party buyerDerived = new Organisation();
    BuyerFinder buyerFinder = new BuyerFinder() {

        @Override
        public Party buyerDerivedFromDocumentName(final IncomingInvoice incomingInvoice) {
            return buyerDerived;
        }
    };
    IncomingInvoice invoice = new IncomingInvoice();
    Party buyerOnViewmodel = new Organisation();
    viewModel.setDomainObject(invoice);
    viewModel.buyerFinder = buyerFinder;
    viewModel.setBuyer(buyerOnViewmodel);
    // when
    notification = viewModel.getNotification();
    // then
    Assertions.assertThat(notification).isEqualTo("Buyer does not match barcode (document name); ");
    // and given (buyers matching)
    viewModel.setBuyer(buyerDerived);
    // when
    notification = viewModel.getNotification();
    // then
    Assertions.assertThat(notification).isNull();
    // and given (no buyer derived)
    BuyerFinder buyerFinderReturningNull = new BuyerFinder() {

        @Override
        public Party buyerDerivedFromDocumentName(final IncomingInvoice incomingInvoice) {
            return null;
        }
    };
    viewModel.buyerFinder = buyerFinderReturningNull;
    // when
    notification = viewModel.getNotification();
    // then
    Assertions.assertThat(notification).isNull();
}
Also used : Party(org.estatio.module.party.dom.Party) BuyerFinder(org.estatio.module.capex.dom.documents.BuyerFinder) Organisation(org.estatio.module.party.dom.Organisation) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Test(org.junit.Test)

Example 2 with BuyerFinder

use of org.estatio.module.capex.dom.documents.BuyerFinder in project estatio by estatio.

the class BuyerFinder_Test method testWhenParamIsDocument.

private void testWhenParamIsDocument(final String documentName, final String derivedPartyReference) {
    // given
    Document document = new Document(null, null, documentName, null, null);
    BuyerFinder finder = new BuyerFinder();
    finder.partyRepository = mockPartyRepository;
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockPartyRepository).findPartyByReference(derivedPartyReference);
        }
    });
    // when
    finder.buyerDerivedFromDocumentName(document);
}
Also used : Expectations(org.jmock.Expectations) BuyerFinder(org.estatio.module.capex.dom.documents.BuyerFinder) Document(org.incode.module.document.dom.impl.docs.Document)

Example 3 with BuyerFinder

use of org.estatio.module.capex.dom.documents.BuyerFinder in project estatio by estatio.

the class BuyerFinder_Test method testerWhenNullOrTooShort.

private void testerWhenNullOrTooShort(final String documentName) {
    // given
    IncomingInvoice invoice = new IncomingInvoice();
    BuyerFinder finder = new BuyerFinder();
    finder.partyRepository = mockPartyRepository;
    finder.lookupAttachedPdfService = mockLookupAttachedPdfService;
    Optional<Document> optional = Optional.of(new Document(null, null, documentName, null, null));
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockLookupAttachedPdfService).lookupIncomingInvoicePdfFrom(invoice);
            will(returnValue(optional));
        }
    });
    // when
    finder.buyerDerivedFromDocumentName(invoice);
}
Also used : Expectations(org.jmock.Expectations) BuyerFinder(org.estatio.module.capex.dom.documents.BuyerFinder) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Document(org.incode.module.document.dom.impl.docs.Document)

Example 4 with BuyerFinder

use of org.estatio.module.capex.dom.documents.BuyerFinder in project estatio by estatio.

the class BuyerFinder_Test method testWhenParamIsInvoice.

private void testWhenParamIsInvoice(final String documentName, final String derivedPartyReference) {
    // given
    IncomingInvoice invoice = new IncomingInvoice();
    BuyerFinder finder = new BuyerFinder();
    finder.partyRepository = mockPartyRepository;
    finder.lookupAttachedPdfService = mockLookupAttachedPdfService;
    Optional<Document> optional = Optional.of(new Document(null, null, documentName, null, null));
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockLookupAttachedPdfService).lookupIncomingInvoicePdfFrom(invoice);
            will(returnValue(optional));
            oneOf(mockPartyRepository).findPartyByReference(derivedPartyReference);
        }
    });
    // when
    finder.buyerDerivedFromDocumentName(invoice);
}
Also used : Expectations(org.jmock.Expectations) BuyerFinder(org.estatio.module.capex.dom.documents.BuyerFinder) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Document(org.incode.module.document.dom.impl.docs.Document)

Aggregations

BuyerFinder (org.estatio.module.capex.dom.documents.BuyerFinder)4 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)3 Document (org.incode.module.document.dom.impl.docs.Document)3 Expectations (org.jmock.Expectations)3 Organisation (org.estatio.module.party.dom.Organisation)1 Party (org.estatio.module.party.dom.Party)1 Test (org.junit.Test)1