-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature#25: Deposit endpoint and Transaction validator in progress
- Loading branch information
1 parent
3f23024
commit 783be73
Showing
17 changed files
with
641 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
client/src/test/java/com/cdx/bas/client/bank/account/BankAccountResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.cdx.bas.client.bank.account; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.h2.H2DatabaseTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(H2DatabaseTestResource.class) | ||
class BankAccountResourceTest { | ||
|
||
@Test | ||
public void deposite_shouldCreateDepositeTransaction_whenBankAccountFound_andDepositeTransactionIsValid() { | ||
|
||
} | ||
|
||
@Test | ||
public void deposite_shouldReturnHTTPError_whenBankAccountFound_butDepositeTransactionIsInvalid() { | ||
|
||
} | ||
|
||
@Test | ||
public void deposite_shouldReturnHTTPError_whenBankAccountFound_butDepositeAmountReach() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/domain/validator/CurrencyValidator.java → ...as/domain/currency/CurrencyValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...x/bas/domain/validator/ValidCurrency.java → ...dx/bas/domain/currency/ValidCurrency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
domain/src/main/java/com/cdx/bas/domain/transaction/TransactionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.cdx.bas.domain.transaction; | ||
|
||
public enum TransactionType { | ||
CREDIT, DEBIT | ||
CREDIT, DEBIT, DEPOSIT | ||
} |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/cdx/bas/domain/transaction/validation/AccountMovement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.cdx.bas.domain.transaction.validation; | ||
|
||
/** | ||
* transaction group that move money from an account to another | ||
*/ | ||
public interface AccountMovement { | ||
} |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/cdx/bas/domain/transaction/validation/CashMovement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.cdx.bas.domain.transaction.validation; | ||
|
||
/** | ||
* transaction group that use cash money to transfer to an account | ||
*/ | ||
public interface CashMovement { | ||
} |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/cdx/bas/domain/transaction/validation/ExistingTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.cdx.bas.domain.transaction.validation; | ||
|
||
/** | ||
* transaction group for existing transactions | ||
*/ | ||
public interface ExistingTransaction { | ||
} |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/cdx/bas/domain/transaction/validation/NewTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.cdx.bas.domain.transaction.validation; | ||
|
||
/** | ||
* transaction group for new transactions | ||
*/ | ||
public interface NewTransaction { | ||
} |
19 changes: 19 additions & 0 deletions
19
domain/src/main/java/com/cdx/bas/domain/transaction/validation/StatusValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.cdx.bas.domain.transaction.validation; | ||
|
||
import com.cdx.bas.domain.transaction.TransactionStatus; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
public class StatusValidator implements ConstraintValidator<ValidStatus, TransactionStatus> { | ||
|
||
private TransactionStatus expectedStatus; | ||
@Override | ||
public void initialize(ValidStatus constraintAnnotation) { | ||
this.expectedStatus = constraintAnnotation.expectedStatus(); | ||
} | ||
|
||
@Override | ||
public boolean isValid(TransactionStatus value, ConstraintValidatorContext context) { | ||
return value != null && value == expectedStatus; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
domain/src/main/java/com/cdx/bas/domain/transaction/validation/TransactionValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.cdx.bas.domain.transaction.validation; | ||
|
||
import com.cdx.bas.domain.transaction.Transaction; | ||
import com.cdx.bas.domain.transaction.TransactionException; | ||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.validation.ConstraintViolation; | ||
import jakarta.validation.Validator; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static com.cdx.bas.domain.transaction.TransactionType.DEPOSIT; | ||
|
||
|
||
@RequestScoped | ||
public class TransactionValidator { | ||
|
||
@Inject | ||
Validator validator; | ||
|
||
public void validateNewTransaction(Transaction transaction) throws TransactionException { | ||
validateTransaction(transaction, NewTransaction.class); | ||
} | ||
|
||
public void validateExistingTransaction(Transaction transaction) throws TransactionException { | ||
validateTransaction(transaction, ExistingTransaction.class); | ||
} | ||
|
||
private void validateTransaction(Transaction transaction, Class<?> group) throws TransactionException { | ||
Set<ConstraintViolation<Transaction>> violations = new HashSet<>(validator.validate(transaction)); | ||
if (DEPOSIT.equals(transaction.getType())) { | ||
violations.addAll(validator.validate(transaction, CashMovement.class, group)); | ||
} else { | ||
violations.addAll(validator.validate(transaction, AccountMovement.class, group)); | ||
} | ||
checkConstraintViolation(violations); | ||
} | ||
|
||
private static void checkConstraintViolation(Set<ConstraintViolation<Transaction>> violations) { | ||
if (!violations.isEmpty()) { | ||
throw new TransactionException(concatViolations(violations)); | ||
} | ||
} | ||
|
||
private static String concatViolations(Set<ConstraintViolation<Transaction>> violations) { | ||
StringBuilder violationBuilder = new StringBuilder(); | ||
for (ConstraintViolation<Transaction> violation : violations) { | ||
violationBuilder.append(violation.getMessage()); | ||
violationBuilder.append("\n"); | ||
} | ||
return violationBuilder.toString(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
domain/src/main/java/com/cdx/bas/domain/transaction/validation/ValidStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.cdx.bas.domain.transaction.validation; | ||
|
||
import com.cdx.bas.domain.transaction.TransactionStatus; | ||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Target({ElementType.FIELD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = StatusValidator.class) | ||
@Documented | ||
public @interface ValidStatus { | ||
|
||
TransactionStatus expectedStatus() default TransactionStatus.UNPROCESSED; | ||
String message() default "unexpected transaction status."; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
Oops, something went wrong.