boolean found2 = false;
System.out.println("addDonation");
ContactController instance = new ContactController();
Contact contact = instance.read(TEST_ID_ABC1);
Donation donation1 = new Donation();
donation1.setDueDate(new Date());
donation1.setProposalTitle(getName());
donation1.setReasonNotFunded(getName());
donation1.setStatus("Test1");
donation1.setAmount(new BigDecimal(1.11));
Donation donation2 = new Donation();
donation2.setDueDate(new Date());
donation2.setProposalTitle(getName());
donation2.setReasonNotFunded(getName());
donation2.setStatus("Test2");
donation2.setAmount(new BigDecimal(2.22));
donation1.setDonor(contact);
donation2.setDonor(contact);
donation1 = instance.addDonation(donation1);
donation2 = instance.addDonation(donation2);
assertEquals(contact, donation1.getDonor());
assertEquals(contact, donation2.getDonor());
for(Donation aDonation : donation2.getDonor().getDonations()) {
if (aDonation.getProposalTitle().equals(getName())
&& aDonation.getReasonNotFunded().equals(getName())
&& aDonation.getStatus().equals("Test1")
&& aDonation.getAmount().equals(new BigDecimal(1.11))) {
found1 = true;
}
if (aDonation.getProposalTitle().equals(getName())
&& aDonation.getReasonNotFunded().equals(getName())
&& aDonation.getStatus().equals("Test2")
&& aDonation.getAmount().equals(new BigDecimal(2.22))) {
found2 = true;
}
}
assertTrue("The added 1rst test donation is not found", found1);
assertTrue("The added 2nd test donation is not found", found2);
//check if donations can be read
DonationController donationCtrl = new DonationController();
assertNotNull(donationCtrl.read(donation1.getIdDonation()));
assertNotNull(donationCtrl.read(donation2.getIdDonation()));
//check update an existing donation
donation1.setStatus("Test3");
instance.addDonation(donation1);
assertEquals("Test3", donationCtrl.read(donation1.getIdDonation()).getStatus());