Skip to content
Permalink
Browse files
added verification for balance and cash draw limit
  • Loading branch information
mgeiss committed Jun 25, 2017
1 parent 8af6853 commit 71839a17fb6e181e6a3af0f44e5dce6418433b25
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 112 deletions.
@@ -19,11 +19,11 @@
import io.mifos.core.api.annotation.ThrowsExceptions;
import io.mifos.core.api.util.CustomFeignClientsConfiguration;
import io.mifos.teller.api.v1.domain.Teller;
import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
import io.mifos.teller.api.v1.domain.TellerBalanceSheet;
import io.mifos.teller.api.v1.domain.TellerManagementCommand;
import io.mifos.teller.api.v1.domain.TellerTransaction;
import io.mifos.teller.api.v1.domain.TellerTransactionCosts;
import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -152,7 +152,8 @@ void post(@PathVariable("tellerCode") final String tellerCode,
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = TellerNotFoundException.class),
@ThrowsException(status = HttpStatus.BAD_REQUEST, exception = TellerTransactionValidationException.class)
@ThrowsException(status = HttpStatus.BAD_REQUEST, exception = TellerTransactionValidationException.class),
@ThrowsException(status = HttpStatus.CONFLICT, exception = TransactionProcessingException.class)
})
TellerTransactionCosts post(@PathVariable("tellerCode") final String tellerCode,
@RequestBody @Valid final TellerTransaction tellerTransaction);
@@ -0,0 +1,19 @@
/*
* Copyright 2017 The Mifos Initiative.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.mifos.teller.api.v1.client;

public class TransactionProcessingException extends RuntimeException {
}
@@ -15,6 +15,7 @@
*/
package io.mifos.teller;

import io.mifos.accounting.api.v1.domain.Account;
import io.mifos.teller.api.v1.EventConstants;
import io.mifos.teller.api.v1.client.TellerAlreadyExistsException;
import io.mifos.teller.api.v1.client.TellerNotFoundException;
@@ -30,6 +31,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class TestTellerManagement extends AbstractTellerTest {

@@ -45,11 +47,11 @@ public void shouldCreateTeller() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -72,8 +74,8 @@ public void shouldNotCreateTellerUnknownTellerAccount() throws Exception {
final String officeIdentifier = RandomStringUtils.randomAlphabetic(32);
final Teller teller = TellerGenerator.createRandomTeller();

Mockito.doAnswer(invocation -> false)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.empty())
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);
}
@@ -83,8 +85,8 @@ public void shouldNotCreateTellerUnknownVaultAccount() throws Exception {
final String officeIdentifier = RandomStringUtils.randomAlphabetic(32);
final Teller teller = TellerGenerator.createRandomTeller();

Mockito.doAnswer(invocation -> false)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.empty())
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);
}
@@ -98,11 +100,11 @@ public void shouldCreateTellerAlreadyExists() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -119,11 +121,11 @@ public void shouldFindTeller() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -172,11 +174,11 @@ public void shouldFetchTeller() throws Exception {
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

tellerToCreate.forEach(teller -> {
Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -210,11 +212,11 @@ public void shouldUpdateTeller() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -240,11 +242,11 @@ public void shouldNotUpdateTellerUnknownOffice() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -264,20 +266,20 @@ public void shouldNotUpdateTellerUnknownTellerAccount() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

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

teller.setTellerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));

Mockito.doAnswer(invocation -> false)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.empty())
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

super.testSubject.change(officeIdentifier, teller.getCode(), teller);
}
@@ -290,20 +292,20 @@ public void shouldNotUpdateTellerUnknownVaultAccount() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

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

teller.setVaultAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));

Mockito.doAnswer(invocation -> false)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.empty())
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.change(officeIdentifier, teller.getCode(), teller);
}
@@ -318,11 +320,11 @@ public void shouldNotUpdateTellerMismatch() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -349,11 +351,11 @@ public void shouldOpenTeller() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -384,11 +386,11 @@ public void shouldCloseTeller() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -425,11 +427,11 @@ public void shouldNotCloseTellerAlreadyClosed() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

@@ -450,11 +452,11 @@ public void shouldNotOpenTellerAlreadyOpen() throws Exception {
Mockito.doAnswer(invocation -> true)
.when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));

Mockito.doAnswer(invocation -> true)
.when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
Mockito.doAnswer(invocation -> Optional.of(new Account()))
.when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));

super.testSubject.create(officeIdentifier, teller);

0 comments on commit 71839a1

Please sign in to comment.