public void test_should_convert_split_into_regular_transaction() { Transaction t = TransactionBuilder.withDb(db) .account(a1) .amount(2000) .withSplit(categories.get("A1"), 500) .withSplit(categories.get("A2"), 1500) .create(); List<Transaction> splits = db.getSplitsForTransaction(t.id); assertEquals(2, splits.size()); t.categoryId = categories.get("A").id; t.splits = null; db.insertOrUpdate(t); splits = db.getSplitsForTransaction(t.id); assertEquals(0, splits.size()); }
public void test_should_insert_and_update_attributes() { // given Category aa1 = categories.get("AA1"); Attribute attr1 = aa1.attributes.get(0); Attribute attr2 = aa1.attributes.get(1); // when inserted Transaction t1 = TransactionBuilder.withDb(db) .account(a1) .amount(1000) .category(aa1) .withAttributes(attributeValue(attr1, "value1"), attributeValue(attr2, "value2")) .create(); Transaction t2 = TransactionBuilder.withDb(db) .account(a2) .amount(2000) .withSplit(aa1, 600, "Note1", null, attributeValue(attr1, "value11")) .withSplit(aa1, 1400, "Note2", null, attributeValue(attr2, "value21")) .create(); // then assertAttributes(t1, attributeValue(attr1, "value1"), attributeValue(attr2, "value2")); List<Transaction> splits = db.getSplitsForTransaction(t2.id); assertAttributes(splits.get(0), attributeValue(attr1, "value11")); assertAttributes(splits.get(1), attributeValue(attr2, "value21")); // when modified db.insertOrUpdate(t1, Arrays.asList(attributeValue(attr2, "value3"))); splits.get(0).categoryAttributes = asMap(attributeValue(attr1, "value111"), attributeValue(attr2, "value222")); splits.get(1).categoryAttributes = asMap(attributeValue(attr1, "value333")); t2.splits = splits; db.insertOrUpdate(t2); // then assertAttributes(t1, attributeValue(attr2, "value3")); splits = db.getSplitsForTransaction(t2.id); assertAttributes( splits.get(0), attributeValue(attr1, "value111"), attributeValue(attr2, "value222")); assertAttributes(splits.get(1), attributeValue(attr1, "value333")); }
public void test_should_update_splits() { Transaction t = TransactionBuilder.withDb(db) .account(a1) .amount(-150) .category(Category.splitCategory(context)) .withSplit(categories.get("A1"), -60) .withSplit(categories.get("A2"), -40) .withTransferSplit(a2, -50, 40) .create(); List<Transaction> splits = db.getSplitsForTransaction(t.id); assertEquals(3, splits.size()); t.fromAmount = -250; splits.get(0).fromAmount = -70; splits.get(1).fromAmount = -50; splits.get(2).fromAmount = -130; splits.get(2).toAmount = 70; t.splits = splits; db.insertOrUpdate(t); splits = db.getSplitsForTransaction(t.id); assertEquals(3, splits.size()); }