<NME> InvoiceTest_newItem.java
<BEF> ADDFILE
<MSG> EST-33: add invoice items repository

<DFF> @@ -0,0 +1,94 @@
+/*
+ *
+ *  Copyright 2012-2013 Eurocommercial Properties NV
+ *
+ *
+ *  Licensed under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.estatio.integration.tests.invoice;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.math.BigDecimal;
+
+import org.joda.time.LocalDate;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.estatio.dom.charge.Charge;
+import org.estatio.dom.charge.Charges;
+import org.estatio.dom.currency.Currencies;
+import org.estatio.dom.currency.Currency;
+import org.estatio.dom.invoice.Invoice;
+import org.estatio.dom.invoice.InvoiceStatus;
+import org.estatio.dom.invoice.Invoices;
+import org.estatio.dom.invoice.PaymentMethod;
+import org.estatio.dom.lease.Lease;
+import org.estatio.dom.lease.Leases;
+import org.estatio.dom.party.Parties;
+import org.estatio.dom.party.Party;
+import org.estatio.fixture.EstatioTransactionalObjectsFixture;
+import org.estatio.fixture.invoice.InvoiceAndInvoiceItemFixture;
+import org.estatio.integration.tests.EstatioIntegrationTest;
+
+public class InvoiceTest_newItem extends EstatioIntegrationTest {
+
+    private Invoices invoices;
+    private Parties parties;
+    private Leases leases;
+    private Currencies currencies;
+    private Charges charges;
+
+    private Party seller;
+    private Party buyer;
+    private Lease lease;
+    private Currency currency;
+    private Charge charge;
+
+    @BeforeClass
+    public static void setupTransactionalData() {
+        scenarioExecution().install(new EstatioTransactionalObjectsFixture());
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        invoices = service(Invoices.class);
+        parties = service(Parties.class);
+        leases = service(Leases.class);
+        currencies = service(Currencies.class);
+        charges = service(Charges.class);
+
+        seller = parties.findPartyByReference(InvoiceAndInvoiceItemFixture.SELLER_PARTY);
+        buyer = parties.findPartyByReference(InvoiceAndInvoiceItemFixture.BUYER_PARTY);
+        lease = leases.findLeaseByReference(InvoiceAndInvoiceItemFixture.LEASE);
+
+        charge = charges.allCharges().get(0);
+        currency = currencies.allCurrencies().get(0);
+
+    }
+
+    @Test
+    public void happyCase() throws Exception {
+        Invoice invoice = invoices.newInvoice(buyer, seller, PaymentMethod.BANK_TRANSFER, currency, new LocalDate(2013, 1, 1), lease);
+        invoice.newItem(charge, new BigDecimal(1), new BigDecimal("10000.123"), "Test");
+        Invoice foundInvoice = invoices.findMatchingInvoice(seller, buyer, PaymentMethod.BANK_TRANSFER, lease, InvoiceStatus.NEW, new LocalDate(2013, 1, 1));
+        assertThat(foundInvoice.getNetAmount(), is(new BigDecimal("10000.123")));
+        assertThat(foundInvoice.getItems().first().getNetAmount(), is(new BigDecimal("10000.123")));
+        // TODO: EST-290: netAmount has scale set to two but the example above
+        // proves that it's possible to store with a higher precision
+    }
+
+}

{'addition_count': 94, 'commit_subject': 'EST-33: add invoice items repository', 'deletion_count': 0, 'file_extension': '.java', 'lang': 'java', 'license': 'apache-2.0', 'repo_name': 'estatio/estatio'}