Skip to content
Permalink
Browse files
Merge pull request #4 from markusgeiss/develop
added better validation for amounts
  • Loading branch information
markusgeiss committed Aug 23, 2017
2 parents a2d1b65 + 6893908 commit 02db86b2880404514015a60bbd9fe226f9f95bf3
Showing 24 changed files with 139 additions and 77 deletions.
@@ -15,12 +15,16 @@
*/
package io.mifos.teller.api.v1.domain;

import javax.validation.constraints.DecimalMin;
import java.math.BigDecimal;

public class Charge {

private String code;
private String incomeAccountIdentifier;
private String name;
private Double amount;
@DecimalMin(value = "0.00")
private BigDecimal amount;

public Charge() {
super();
@@ -50,11 +54,11 @@ public void setName(final String name) {
this.name = name;
}

public Double getAmount() {
public BigDecimal getAmount() {
return this.amount;
}

public void setAmount(final Double amount) {
public void setAmount(final BigDecimal amount) {
this.amount = amount;
}
}
@@ -18,6 +18,9 @@
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.Valid;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

public class Cheque {
@Valid
@@ -28,8 +31,9 @@ public class Cheque {
private String drawer;
@NotEmpty
private String payee;
@NotEmpty
private String amount;
@NotNull
@DecimalMin(value = "0.00", inclusive = false)
private BigDecimal amount;
@NotEmpty
private String dateIssued;
private Boolean openCheque;
@@ -70,11 +74,11 @@ public void setPayee(final String payee) {
this.payee = payee;
}

public String getAmount() {
public BigDecimal getAmount() {
return this.amount;
}

public void setAmount(final String amount) {
public void setAmount(final BigDecimal amount) {
this.amount = amount;
}

@@ -18,8 +18,9 @@
import io.mifos.core.lang.validation.constraints.ValidIdentifier;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

public class Teller {

@@ -34,9 +35,9 @@ public enum State {
private String code;
@NotEmpty
private String password;
@NotNull
@DecimalMin("0.00")
private Double cashdrawLimit;
@DecimalMax("1000000000.00")
private BigDecimal cashdrawLimit;
@ValidIdentifier
private String tellerAccountIdentifier;
@ValidIdentifier
@@ -68,11 +69,11 @@ public void setPassword(final String password) {
this.password = password;
}

public Double getCashdrawLimit() {
public BigDecimal getCashdrawLimit() {
return this.cashdrawLimit;
}

public void setCashdrawLimit(final Double cashdrawLimit) {
public void setCashdrawLimit(final BigDecimal cashdrawLimit) {
this.cashdrawLimit = cashdrawLimit;
}

@@ -15,12 +15,15 @@
*/
package io.mifos.teller.api.v1.domain;

import javax.validation.constraints.DecimalMin;
import java.math.BigDecimal;
import java.util.List;

public class TellerBalanceSheet {

private String day;
private Double balance;
@DecimalMin("0.00")
private BigDecimal balance;
private List<TellerEntry> entries;

public TellerBalanceSheet() {
@@ -35,11 +38,11 @@ public void setDay(final String day) {
this.day = day;
}

public Double getBalance() {
public BigDecimal getBalance() {
return this.balance;
}

public void setBalance(final Double balance) {
public void setBalance(final BigDecimal balance) {
this.balance = balance;
}

@@ -15,6 +15,9 @@
*/
package io.mifos.teller.api.v1.domain;

import javax.validation.constraints.DecimalMin;
import java.math.BigDecimal;

public class TellerEntry {

public enum Type {
@@ -25,7 +28,8 @@ public enum Type {
private Type type;
private String transactionDate;
private String message;
private Double amount;
@DecimalMin("0.00")
private BigDecimal amount;

public TellerEntry() {
super();
@@ -55,11 +59,11 @@ public void setMessage(final String message) {
this.message = message;
}

public Double getAmount() {
public BigDecimal getAmount() {
return this.amount;
}

public void setAmount(final Double amount) {
public void setAmount(final BigDecimal amount) {
this.amount = amount;
}
}
@@ -17,7 +17,9 @@

import io.mifos.core.lang.validation.constraints.ValidIdentifier;

import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

public class TellerManagementCommand {

@@ -36,7 +38,8 @@ public enum Adjustment {
private Action action;
@NotNull
private Adjustment adjustment;
private Double amount;
@DecimalMin("0.00")
private BigDecimal amount;
@ValidIdentifier(optional = true)
private String assignedEmployeeIdentifier;

@@ -60,11 +63,11 @@ public void setAdjustment(final String adjustment) {
this.adjustment = Adjustment.valueOf(adjustment);
}

public Double getAmount() {
public BigDecimal getAmount() {
return this.amount;
}

public void setAmount(final Double amount) {
public void setAmount(final BigDecimal amount) {
this.amount = amount;
}

@@ -20,6 +20,7 @@
import javax.validation.Valid;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

public class TellerTransaction {

@@ -48,8 +49,8 @@ public enum State {
@ValidIdentifier
private String clerk;
@NotNull
@DecimalMin("0.00")
private Double amount;
@DecimalMin(value = "0.00", inclusive = false)
private BigDecimal amount;
private State state;
@Valid
private Cheque cheque;
@@ -130,11 +131,11 @@ public void setClerk(final String clerk) {
this.clerk = clerk;
}

public Double getAmount() {
public BigDecimal getAmount() {
return this.amount;
}

public void setAmount(final Double amount) {
public void setAmount(final BigDecimal amount) {
this.amount = amount;
}

@@ -15,12 +15,15 @@
*/
package io.mifos.teller.api.v1.domain;

import javax.validation.constraints.DecimalMin;
import java.math.BigDecimal;
import java.util.List;

public class TellerTransactionCosts {

private String tellerTransactionIdentifier;
private Double totalAmount;
@DecimalMin("0.00")
private BigDecimal totalAmount;
private List<Charge> charges;

public TellerTransactionCosts() {
@@ -35,11 +38,11 @@ public void setTellerTransactionIdentifier(final String tellerTransactionIdentif
this.tellerTransactionIdentifier = tellerTransactionIdentifier;
}

public Double getTotalAmount() {
public BigDecimal getTotalAmount() {
return this.totalAmount;
}

public void setTotalAmount(final Double totalAmount) {
public void setTotalAmount(final BigDecimal totalAmount) {
this.totalAmount = totalAmount;
}

@@ -29,6 +29,7 @@
import org.mockito.Matchers;
import org.mockito.Mockito;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
@@ -222,7 +223,7 @@ public void shouldUpdateTeller() throws Exception {

super.eventRecorder.wait(EventConstants.POST_TELLER, teller.getCode());

teller.setCashdrawLimit(15000.00D);
teller.setCashdrawLimit(BigDecimal.valueOf(15000.00D));

super.testSubject.change(officeIdentifier, teller.getCode(), teller);

@@ -478,10 +479,28 @@ public void shouldNotOpenTellerAlreadyOpen() throws Exception {
super.testSubject.post(officeIdentifier, teller.getCode(), command);
}

@Test(expected = TellerValidationException.class)
public void shouldNotCreateTellerMinimumCashWithdrawalLimitViolation() throws Exception {
final String officeIdentifier = RandomStringUtils.randomAlphabetic(32);
final Teller teller = TellerGenerator.createRandomTeller();
teller.setCashdrawLimit(BigDecimal.valueOf(0.00001D));

super.testSubject.create(officeIdentifier, teller);
}

@Test(expected = TellerValidationException.class)
public void shouldNotCreateTellerMaximumCashWithdrawalLimitViolation() throws Exception {
final String officeIdentifier = RandomStringUtils.randomAlphabetic(32);
final Teller teller = TellerGenerator.createRandomTeller();
teller.setCashdrawLimit(BigDecimal.valueOf(2000000000));

super.testSubject.create(officeIdentifier, teller);
}

private void compareTeller(final Teller expected, final Teller actual) {
Assert.assertEquals(expected.getCode(), actual.getCode());
Assert.assertEquals(expected.getTellerAccountIdentifier(), actual.getTellerAccountIdentifier());
Assert.assertEquals(expected.getVaultAccountIdentifier(), actual.getVaultAccountIdentifier());
Assert.assertEquals(expected.getCashdrawLimit(), actual.getCashdrawLimit());
Assert.assertTrue(expected.getCashdrawLimit().compareTo(actual.getCashdrawLimit()) == 0);
}
}

0 comments on commit 02db86b

Please sign in to comment.