Search in sources :

Example 16 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.

the class ProjectInvoiceItemTransferManager_Test method getInvoiceItemsHavingNoOrder_works.

@Test
public void getInvoiceItemsHavingNoOrder_works() throws Exception {
    // given
    Project source = new Project();
    ProjectInvoiceItemTransferManager manager = new ProjectInvoiceItemTransferManager(null, source);
    manager.incomingInvoiceItemRepository = mockIncomingInvoiceItemRepository;
    manager.orderItemInvoiceItemLinkRepository = mockOrderItemInvoiceItemLinkRepository;
    IncomingInvoiceItem itemLinked = new IncomingInvoiceItem();
    IncomingInvoiceItem itemNotLinked = new IncomingInvoiceItem();
    OrderItemInvoiceItemLink link = new OrderItemInvoiceItemLink();
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceItemRepository).findByProject(source);
            will(returnValue(Arrays.asList(itemLinked, itemNotLinked)));
            oneOf(mockOrderItemInvoiceItemLinkRepository).findByInvoiceItem(itemLinked);
            will(returnValue(Optional.of(link)));
            oneOf(mockOrderItemInvoiceItemLinkRepository).findByInvoiceItem(itemNotLinked);
            will(returnValue(Optional.empty()));
        }
    });
    // when
    List<IncomingInvoiceItem> items = manager.getInvoiceItemsHavingNoOrder();
    // then
    Assertions.assertThat(items).contains(itemNotLinked);
    Assertions.assertThat(items).doesNotContain(itemLinked);
}
Also used : Expectations(org.jmock.Expectations) Project(org.estatio.module.capex.dom.project.Project) OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Test(org.junit.Test)

Example 17 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.

the class ProjectService_Test method moveIncomingInvoiceItemToProject_works_when_invoice_item_not_linked.

@Test
public void moveIncomingInvoiceItemToProject_works_when_invoice_item_not_linked() throws Exception {
    // given
    ProjectService projectService = new ProjectService();
    projectService.orderItemInvoiceItemLinkRepository = mockOrderItemInvoiceItemLinkRepository;
    IncomingInvoiceItem incomingInvoiceItem = new IncomingInvoiceItem();
    Project project = new Project();
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOrderItemInvoiceItemLinkRepository).findByInvoiceItem(incomingInvoiceItem);
            will(returnValue(Optional.empty()));
        }
    });
    // when
    projectService.moveIncomingInvoiceItemToProject(incomingInvoiceItem, project);
    // then
    Assertions.assertThat(incomingInvoiceItem.getProject()).isEqualTo(project);
}
Also used : Expectations(org.jmock.Expectations) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Test(org.junit.Test)

Example 18 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.

the class ProjectItem_InvoicedAmount_Test method invoicedAmount_works.

@Test
public void invoicedAmount_works() throws Exception {
    // given
    BigDecimal expectedTotalInvoicedNetAmountOnItems = new BigDecimal("100.00");
    BigDecimal netAmountOnItem1 = new BigDecimal("55.00");
    BigDecimal netAmountOnItem2 = new BigDecimal("45.00");
    BigDecimal netAmountOnItem3_discarded = new BigDecimal("12345.67");
    ProjectItem projectItem = new ProjectItem();
    ProjectItem_InvoicedAmount mixin = new ProjectItem_InvoicedAmount(projectItem);
    mixin.incomingInvoiceItemRepository = mockIncomingInvoiceItemRepository;
    IncomingInvoiceItem item1 = new IncomingInvoiceItem();
    item1.setInvoice(newIncomingInvoice());
    item1.setNetAmount(netAmountOnItem1);
    IncomingInvoiceItem item2 = new IncomingInvoiceItem();
    item2.setInvoice(newIncomingInvoice());
    item2.setNetAmount(netAmountOnItem2);
    IncomingInvoiceItem item3_discarded = new IncomingInvoiceItem() {

        @Override
        public boolean isDiscarded() {
            return true;
        }
    };
    item3_discarded.setInvoice(newIncomingInvoice());
    item3_discarded.setNetAmount(netAmountOnItem3_discarded);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceItemRepository).findByProjectAndCharge(null, null);
            will(returnValue(Arrays.asList(item1, item2, item3_discarded)));
        }
    });
    // when
    BigDecimal orderedAmount = mixin.invoicedAmount();
    // then
    Assertions.assertThat(orderedAmount).isEqualTo(expectedTotalInvoicedNetAmountOnItems);
}
Also used : Expectations(org.jmock.Expectations) ProjectItem_InvoicedAmount(org.estatio.module.capex.dom.invoice.contributions.ProjectItem_InvoicedAmount) ProjectItem(org.estatio.module.capex.dom.project.ProjectItem) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 19 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.

the class OrderItem_Test method isInvoiced_works.

@Test
public void isInvoiced_works() throws Exception {
    // given
    OrderItem orderItem = new OrderItem();
    orderItem.setNetAmount(new BigDecimal("100.00"));
    IncomingInvoiceItem item1 = newIncomingInvoiceItem();
    IncomingInvoiceItem item2 = newIncomingInvoiceItem();
    // when
    item1.setNetAmount(new BigDecimal("50.00"));
    item2.setNetAmount(new BigDecimal("49.99"));
    orderItem.orderItemInvoiceItemLinkRepository = setupOrderItemInvoiceItemLinkRepository(item1, item2);
    // then
    assertThat(orderItem.isInvoiced()).isFalse();
    // and when
    item1.setNetAmount(new BigDecimal("50.00"));
    item2.setNetAmount(new BigDecimal("50.00"));
    orderItem.orderItemInvoiceItemLinkRepository = setupOrderItemInvoiceItemLinkRepository(item1, item2);
    // then
    assertThat(orderItem.isInvoiced()).isTrue();
    // and when
    item1.setNetAmount(new BigDecimal("50.00"));
    item2.setNetAmount(new BigDecimal("50.01"));
    orderItem.orderItemInvoiceItemLinkRepository = setupOrderItemInvoiceItemLinkRepository(item1, item2);
    // then
    assertThat(orderItem.isInvoiced()).isTrue();
}
Also used : IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 20 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.

the class OrderItem_Test method newIncomingInvoiceItem.

private IncomingInvoiceItem newIncomingInvoiceItem() {
    final IncomingInvoiceItem incomingInvoiceItem = new IncomingInvoiceItem();
    final IncomingInvoice incomingInvoice = new IncomingInvoice() {

        @Override
        protected EventBusService getEventBusService() {
            return mockEventBusService;
        }
    };
    context.ignoring(mockEventBusService);
    incomingInvoiceItem.setInvoice(incomingInvoice);
    return incomingInvoiceItem;
}
Also used : IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice)

Aggregations

IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)25 Test (org.junit.Test)14 BigDecimal (java.math.BigDecimal)8 OrderItem (org.estatio.module.capex.dom.order.OrderItem)7 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)6 OrderItemInvoiceItemLink (org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink)5 Expectations (org.jmock.Expectations)5 Action (org.apache.isis.applib.annotation.Action)3 ArrayList (java.util.ArrayList)2 Project (org.estatio.module.capex.dom.project.Project)2 Charge (org.estatio.module.charge.dom.Charge)2 ToString (lombok.ToString)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)1 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 IncomingInvoiceType (org.estatio.module.capex.dom.invoice.IncomingInvoiceType)1 ProjectItem_InvoicedAmount (org.estatio.module.capex.dom.invoice.contributions.ProjectItem_InvoicedAmount)1 Order (org.estatio.module.capex.dom.order.Order)1 IncomingInvoiceItem_createOrderItemLink (org.estatio.module.capex.dom.orderinvoice.IncomingInvoiceItem_createOrderItemLink)1 ProjectItem (org.estatio.module.capex.dom.project.ProjectItem)1 Party (org.estatio.module.party.dom.Party)1