use of ch.aaap.harvestclient.domain.reference.Reference in project harvest-client by 3AP-AG.
the class ExpensesApiUpdateTest method changeAll.
@Test
void changeAll() {
String name = "test Expense";
boolean billableByDefault = false;
double defaultHourlyRate = 220.2;
boolean defaultAddToFutureProject = true;
boolean active = false;
ExpenseUpdateInfo changes = ImmutableExpenseUpdateInfo.builder().project(project).expenseCategory(expenseCategory).totalCost(55.).spentDate(LocalDate.of(2001, 1, 1)).build();
Expense updatedExpense = expensesApi.update(expense, changes);
assertThat(updatedExpense).usingComparatorForType(Comparator.comparing(Reference::getId), Reference.class).isEqualToComparingOnlyGivenFields(changes, "project", "expenseCategory", "totalCost", "spentDate");
}
use of ch.aaap.harvestclient.domain.reference.Reference in project harvest-client by 3AP-AG.
the class ExpensesApiCreateTest method create.
@Test
void create() {
Expense creationInfo = ImmutableExpense.builder().project(project).expenseCategory(expenseCategory).spentDate(LocalDate.now()).user(user).totalCost(22.).build();
expense = expensesApi.create(creationInfo);
assertThat(expense).usingComparatorForType(Comparator.comparing(Reference::getId), Reference.class).isEqualToIgnoringNullFields(creationInfo);
ExpenseCategoryReferenceDto expenseCategoryDto = (ExpenseCategoryReferenceDto) expense.getExpenseCategory();
ExpenseCategory expectedCategory = harvest.expenseCategories().get(expenseCategory);
assertThat(expenseCategoryDto).isEqualToComparingOnlyGivenFields(expectedCategory, "unitName", "unitPrice");
}
use of ch.aaap.harvestclient.domain.reference.Reference in project harvest-client by 3AP-AG.
the class ReferenceDtoAdapter method create.
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<? super T> rawType = type.getRawType();
log.trace("Called create with {}", type);
if (rawType != Reference.class) {
return null;
}
Class<?> elementClass = parseReferenceType(type);
String simpleName = elementClass.getSimpleName();
String expectedClassName = simpleName + DTO_SUFFIX;
try {
Class<?> dtoClass = Class.forName(BaseReferenceDto.class.getPackage().getName() + "." + expectedClassName);
log.trace("Got Dto class {}", dtoClass);
TypeAdapter<?> delegate = gson.getAdapter(dtoClass);
log.trace("Returning type adapter for {}", type);
return new TypeAdapter<T>() {
@Override
public void write(JsonWriter out, T value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
Reference reference = (Reference) value;
out.value(reference.getId());
}
@Override
@SuppressWarnings("unchecked")
public T read(JsonReader in) throws IOException {
return (T) delegate.read(in);
}
};
} catch (ClassNotFoundException e) {
throw new HarvestRuntimeException("Could not find ReferenceDto. Reference<" + simpleName + "> needs a class named " + expectedClassName + " to existing in the same package as ReferenceDto", e);
}
}
Aggregations