org.nakedobjects.example.expenses.fixtures.AbstractClaimFixture Maven / Gradle / Ivy
The newest version!
package org.nakedobjects.example.expenses.fixtures;
import org.nakedobjects.applib.fixtures.AbstractFixture;
import org.nakedobjects.applib.value.Date;
import org.nakedobjects.applib.value.Money;
import org.nakedobjects.example.expenses.claims.AbstractClaim;
import org.nakedobjects.example.expenses.claims.Claim;
import org.nakedobjects.example.expenses.claims.ClaimFactory;
import org.nakedobjects.example.expenses.claims.ClaimRepository;
import org.nakedobjects.example.expenses.claims.ExpenseItem;
import org.nakedobjects.example.expenses.claims.ExpenseType;
import org.nakedobjects.example.expenses.claims.ProjectCode;
import org.nakedobjects.example.expenses.claims.items.AbstractExpenseItem;
import org.nakedobjects.example.expenses.claims.items.Airfare;
import org.nakedobjects.example.expenses.claims.items.CarRental;
import org.nakedobjects.example.expenses.claims.items.GeneralExpense;
import org.nakedobjects.example.expenses.claims.items.Hotel;
import org.nakedobjects.example.expenses.claims.items.Journey;
import org.nakedobjects.example.expenses.claims.items.PrivateCarJourney;
import org.nakedobjects.example.expenses.claims.items.Taxi;
import org.nakedobjects.example.expenses.employee.Employee;
import org.nakedobjects.example.expenses.employee.EmployeeRepository;
public abstract class AbstractClaimFixture extends AbstractFixture {
// {{ Injected Services
// {{ Injected: ClaimRepository
private ClaimRepository claimRepository;
/**
* This field is not persisted, nor displayed to the user.
*/
protected ClaimRepository getClaimRepository() {
return this.claimRepository;
}
/**
* Injected by the application container.
*/
public void setClaimRepository(ClaimRepository claimRepository) {
this.claimRepository = claimRepository;
}
// }}
// {{ Injected: ClaimFactory
private ClaimFactory claimFactory;
/**
* This property is not persisted, nor displayed to the user.
*/
protected ClaimFactory getClaimFactory() {
return this.claimFactory;
}
/**
* Injected by the application container.
*/
public void setClaimFactory(final ClaimFactory claimFactory) {
this.claimFactory = claimFactory;
}
// }}
// {{ Injected: EmployeeRepository
private EmployeeRepository employeeRepository;
/**
* This field is not persisted, nor displayed to the user.
*/
protected EmployeeRepository getEmployeeRepository() {
return this.employeeRepository;
}
/**
* Injected by the application container.
*/
public void setEmployeeRepository(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository;
}
// }}
// }}
protected Claim createNewClaim(Employee employee, Employee approver, String description, ProjectCode projectCode, Date dateCreated) {
Claim claim = getClaimFactory().createNewClaim(employee, description);
claim.modifyApprover(approver);
claim.modifyProjectCode(projectCode);
if (dateCreated != null) {
claim.setDateCreated(dateCreated);
}
return claim;
}
private ExpenseItem createExpenseItem(
AbstractClaim claim,
ExpenseType type,
Date dateIncurred,
String description,
double amount) {
AbstractExpenseItem item = (AbstractExpenseItem) claim.createNewExpenseItem(type);
item.modifyDateIncurred(dateIncurred);
item.modifyDescription(description);
item.modifyAmount(money(amount, claim));
return item;
}
private void modifyStandardJourneyFields(Journey journey, String origin, String destination, boolean returnJourney) {
journey.modifyOrigin(origin);
journey.modifyDestination(destination);
journey.modifyReturnJourney(new Boolean(returnJourney));
}
protected GeneralExpense addGeneralExpense(AbstractClaim claim, Date dateIncurred, String description, double amount) {
GeneralExpense item = (GeneralExpense) createExpenseItem(claim, ExpenseTypeFixture.GENERAL, dateIncurred, description,
amount);
makePersistent(item);
return item;
}
protected Airfare addAirfare(
AbstractClaim claim,
Date dateIncurred,
String description,
double amount,
String airline,
String origin,
String destination,
boolean returnJourney) {
Airfare item = (Airfare) createExpenseItem(claim, ExpenseTypeFixture.AIRFARE, dateIncurred, description, amount);
item.modifyAirlineAndFlight(airline);
modifyStandardJourneyFields(item, origin, destination, returnJourney);
makePersistent(item);
return item;
}
protected Hotel addHotel(
AbstractClaim claim,
Date dateIncurred,
String description,
double amount,
String hotelURL,
int numberOfNights,
double accommodation,
double food,
double other) {
Hotel item = (Hotel) createExpenseItem(claim, ExpenseTypeFixture.HOTEL, dateIncurred, description, amount);
item.modifyHotelURL(hotelURL);
item.modifyNumberOfNights(numberOfNights);
item.modifyAccommodation(money(accommodation, claim));
item.modifyFood(money(food, claim));
item.modifyOther(money(other, claim));
makePersistent(item);
return item;
}
protected CarRental addCarRental(
AbstractClaim claim,
Date dateIncurred,
String description,
double amount,
String rentalCompany,
int noOfDays) {
CarRental item = (CarRental) createExpenseItem(claim, ExpenseTypeFixture.CAR_RENTAL, dateIncurred, description, amount);
item.modifyRentalCompany(rentalCompany);
item.modifyNumberOfDays(noOfDays);
makePersistent(item);
return item;
}
protected GeneralExpense addMobilePhone(AbstractClaim claim, Date dateIncurred, String phoneNumber, double amount) {
GeneralExpense item = (GeneralExpense) createExpenseItem(claim, ExpenseTypeFixture.MOBILE_PHONE, dateIncurred,
"Phone No. " + phoneNumber, amount);
makePersistent(item);
return item;
}
protected PrivateCarJourney addPrivateCarJourney(
AbstractClaim claim,
Date dateIncurred,
String description,
String origin,
String destination,
boolean returnJourney,
int totalMiles) {
PrivateCarJourney item = (PrivateCarJourney) createExpenseItem(claim, ExpenseTypeFixture.PRIVATE_CAR, dateIncurred,
description, 0.0);
modifyStandardJourneyFields(item, origin, destination, returnJourney);
item.modifyTotalMiles(totalMiles);
item.modifyMileageRate(0.40);
makePersistent(item);
return item;
}
protected Taxi addTaxi(
AbstractClaim claim,
Date dateIncurred,
String description,
double amount,
String origin,
String destination,
boolean returnJourney) {
Taxi item = (Taxi) createExpenseItem(claim, ExpenseTypeFixture.TAXI, dateIncurred, description, amount);
modifyStandardJourneyFields(item, origin, destination, returnJourney);
makePersistent(item);
return item;
}
protected GeneralExpense addMeal(AbstractClaim claim, Date dateIncurred, String description, double amount) {
GeneralExpense item = (GeneralExpense) createExpenseItem(claim, ExpenseTypeFixture.MEAL, dateIncurred, description,
amount);
makePersistent(item);
return item;
}
private Money money(double amount, AbstractClaim claim) {
return new Money(amount, claim.currencyCode());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy