--- added test for BankAccountController with validation test for add method. For methods update and delete didn't do the check validation empty id because without id REST request for path "/securities/bank-accounts/" not work.
This commit is contained in:
parent
2ac22ddbdd
commit
11eb548d79
1 changed files with 148 additions and 14 deletions
|
|
@ -2,6 +2,7 @@ package ru.spcex.clearing.backendapi.controller.queue.account;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.NestedExceptionUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
|
@ -13,13 +14,18 @@ import ru.spcex.clearing.backendapi.config.WebConfig;
|
|||
import ru.spcex.clearing.backendapi.controller.queue.config.*;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.utils.MatcherFactory;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.BankAccountNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.BankAccountUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.QueueSuccessResponse;
|
||||
import ru.spcex.clearing.backendapi.domain.actions.IAction;
|
||||
import ru.spcex.clearing.backendapi.errors.ActionValidationException;
|
||||
import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountNewRequest;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
|
@ -37,6 +43,7 @@ class BankAccountControllerTest {
|
|||
public static final MatcherFactory.Matcher<CudResponse> CUD_RESPONSE_MATCHER = MatcherFactory.usingIgnoringFieldsComparator(CudResponse.class);
|
||||
private static final String REST_URL = "/securities/bank-accounts/";
|
||||
private static final CharacterEncodingFilter CHARACTER_ENCODING_FILTER = new CharacterEncodingFilter();
|
||||
private static final AtomicLong currentId = new AtomicLong();
|
||||
|
||||
static {
|
||||
CHARACTER_ENCODING_FILTER.setEncoding("UTF-8");
|
||||
|
|
@ -74,22 +81,21 @@ class BankAccountControllerTest {
|
|||
@Test
|
||||
void add() throws Exception {
|
||||
//ARRANGE
|
||||
BankAccountNewAction bankAccountNewAction = new BankAccountNewAction();
|
||||
bankAccountNewAction.setBankIdentificationCode("044525776");
|
||||
bankAccountNewAction.setBankName("Beta Money Bank");
|
||||
bankAccountNewAction.setCorrespondentAccount("30101111111111111776");
|
||||
bankAccountNewAction.setCorrespondentAccountName("correspondent");
|
||||
bankAccountNewAction.setCurrency("RUB");
|
||||
bankAccountNewAction.setDestination("destination");
|
||||
bankAccountNewAction.setTaxpayerIdentificationNumber("3664011397");
|
||||
bankAccountNewAction.setTaxRegistrationReasonCode("01");
|
||||
bankAccountNewAction.setAccount("11111222223333344444");
|
||||
BankAccountNewAction bankAccountNewAction = getBankAccountNewAction(
|
||||
"044525776",
|
||||
"Beta Money Bank",
|
||||
"30101111111111111776",
|
||||
"correspondent",
|
||||
"RUB",
|
||||
"destination",
|
||||
"3664011397",
|
||||
"01",
|
||||
"11111222223333344444");
|
||||
|
||||
CudResponse extended = new CudResponse();
|
||||
extended.setCode(0L);
|
||||
extended.setMessage("success");
|
||||
extended.setPayload(new QueueSuccessResponse(ActionType.NEW, 0L));
|
||||
|
||||
extended.setPayload(new QueueSuccessResponse(ActionType.NEW, currentId.getAndIncrement()));
|
||||
//ACT
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(REST_URL)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
|
|
@ -101,11 +107,139 @@ class BankAccountControllerTest {
|
|||
.andExpect(content().json(writeValue(extended)));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BankAccountController#add(BankAccountNewAction)}<br>
|
||||
* Тест проверяет работу валидации сущности {@link BankAccountNewAction} принятой по REST API для отправку в Apache Kafka.<br>
|
||||
* Входной запрос {@link BankAccountNewRequest}:<br>
|
||||
* {@link BankAccountNewRequest#bankIdentificationCode} - 044525776 или ""<br>
|
||||
* {@link BankAccountNewRequest#bankName} - Beta Money Bank или ""<br>
|
||||
* {@link BankAccountNewRequest#correspondentAccount} - 30101111111111111776 или ""<br>
|
||||
* {@link BankAccountNewRequest#correspondentAccountName} - correspondent или ""<br>
|
||||
* {@link BankAccountNewRequest#currency} - RUB или ""<br>
|
||||
* {@link BankAccountNewRequest#destination} - destinatio или ""n<br>
|
||||
* {@link BankAccountNewRequest#taxpayerIdentificationNumber} - 3664011397 или ""<br>
|
||||
* {@link BankAccountNewRequest#taxRegistrationReasonCode} - 01 или ""<br>
|
||||
* {@link BankAccountNewRequest#account} - 11111222223333344444 или ""<br>
|
||||
*/
|
||||
@Test
|
||||
void update() {
|
||||
void addWithException() {
|
||||
assertThrowsFor(getBankAccountNewAction("", "Beta Money Bank", "30101111111111111776", "correspondent", "RUB", "destination", "3664011397", "01", "11111222223333344444"));
|
||||
assertThrowsFor(getBankAccountNewAction("044525776", "", "30101111111111111776", "correspondent", "RUB", "destination", "3664011397", "01", "11111222223333344444"));
|
||||
assertThrowsFor(getBankAccountNewAction("044525776", "Beta Money Bank", "", "correspondent", "RUB", "destination", "3664011397", "01", "11111222223333344444"));
|
||||
assertThrowsFor(getBankAccountNewAction("044525776", "Beta Money Bank", "30101111111111111776", "", "RUB", "destination", "3664011397", "01", "11111222223333344444"));
|
||||
assertThrowsFor(getBankAccountNewAction("044525776", "Beta Money Bank", "30101111111111111776", "correspondent", "", "destination", "3664011397", "01", "11111222223333344444"));
|
||||
assertThrowsFor(getBankAccountNewAction("044525776", "Beta Money Bank", "30101111111111111776", "correspondent", "RUB", "", "3664011397", "01", "11111222223333344444"));
|
||||
assertThrowsFor(getBankAccountNewAction("044525776", "Beta Money Bank", "30101111111111111776", "correspondent", "RUB", "destination", "", "01", "11111222223333344444"));
|
||||
assertThrowsFor(getBankAccountNewAction("044525776", "Beta Money Bank", "30101111111111111776", "correspondent", "RUB", "destination", "3664011397", "", "11111222223333344444"));
|
||||
assertThrowsFor(getBankAccountNewAction("044525776", "Beta Money Bank", "30101111111111111776", "correspondent", "RUB", "destination", "3664011397", "01", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BankAccountController#update(Long, BankAccountUpdateAction)}<br>
|
||||
* Тест проверяет получение сущности {@link BankAccountUpdateAction} по REST API и отправку в Apache Kafka.<br>
|
||||
* Входной запрос {@link BankAccountUpdateAction}:<br>
|
||||
* {@link BankAccountUpdateAction#bankIdentificationCode} - 044525776<br>
|
||||
* {@link BankAccountUpdateAction#bankName} - Beta Money Bank<br>
|
||||
* {@link BankAccountUpdateAction#correspondentAccount} - 30101111111111111776<br>
|
||||
* {@link BankAccountUpdateAction#correspondentAccountName} - correspondent<br>
|
||||
* {@link BankAccountUpdateAction#currency} - RUB<br>
|
||||
* {@link BankAccountUpdateAction#destination} - destination<br>
|
||||
* {@link BankAccountUpdateAction#taxpayerIdentificationNumber} - 3664011397<br>
|
||||
* {@link BankAccountUpdateAction#taxRegistrationReasonCode} - 01<br>
|
||||
* {@link BankAccountUpdateAction#account} - 11111222223333344444<br>
|
||||
*/
|
||||
@Test
|
||||
void delete() {
|
||||
void update() throws Exception {
|
||||
//ARRANGE
|
||||
BankAccountUpdateAction bankAccountNewAction = getBankAccountUpdateAction(
|
||||
"044525776",
|
||||
"Beta Money Bank",
|
||||
"30101111111111111776",
|
||||
"correspondent",
|
||||
"RUB",
|
||||
"destination",
|
||||
"3664011397",
|
||||
"01",
|
||||
"11111222223333344444");
|
||||
|
||||
CudResponse extended = new CudResponse();
|
||||
extended.setCode(0L);
|
||||
extended.setMessage("success");
|
||||
extended.setPayload(new QueueSuccessResponse(ActionType.UPDATE, currentId.getAndIncrement()));
|
||||
//ACT
|
||||
mockMvc.perform(MockMvcRequestBuilders.put(REST_URL + "0")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(writeValue(bankAccountNewAction)))
|
||||
.andDo(print())//output to the log request and response
|
||||
// ASSERT
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(content().json(writeValue(extended)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link BankAccountController#delete(Long)} <br>
|
||||
* Тест проверяет получение id сущности {@link Long} по REST API и отправку в Apache Kafka.<br>
|
||||
* Входной запрос {@link Long}: - 0L<br>
|
||||
*/
|
||||
@Test
|
||||
void delete() throws Exception {
|
||||
//ARRANGE
|
||||
CudResponse extended = new CudResponse();
|
||||
extended.setCode(0L);
|
||||
extended.setMessage("success");
|
||||
extended.setPayload(new QueueSuccessResponse(ActionType.DELETE, currentId.getAndIncrement()));
|
||||
//ACT
|
||||
mockMvc.perform(MockMvcRequestBuilders.delete(REST_URL + "0")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())//output to the log request and response
|
||||
// ASSERT
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(content().json(writeValue(extended)));
|
||||
}
|
||||
|
||||
private void assertThrowsFor(IAction<?> iAction) {
|
||||
assertThrows(ActionValidationException.class, () -> {
|
||||
try {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(REST_URL).contentType(MediaType.APPLICATION_JSON).content(writeValue(iAction)));
|
||||
} catch (Exception e) {
|
||||
Throwable rootCause = NestedExceptionUtils.getRootCause(e);
|
||||
throw rootCause != null ? rootCause : e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private BankAccountNewAction getBankAccountNewAction(String BankIdentificationCode, String BankName, String CorrespondentAccount, String CorrespondentAccountName,
|
||||
String Currency, String Destination, String TaxpayerIdentificationNumber, String TaxRegistrationReasonCode,
|
||||
String Account) {
|
||||
BankAccountNewAction bankAccountNewAction = new BankAccountNewAction();
|
||||
bankAccountNewAction.setBankIdentificationCode(BankIdentificationCode);
|
||||
bankAccountNewAction.setBankName(BankName);
|
||||
bankAccountNewAction.setCorrespondentAccount(CorrespondentAccount);
|
||||
bankAccountNewAction.setCorrespondentAccountName(CorrespondentAccountName);
|
||||
bankAccountNewAction.setCurrency(Currency);
|
||||
bankAccountNewAction.setDestination(Destination);
|
||||
bankAccountNewAction.setTaxpayerIdentificationNumber(TaxpayerIdentificationNumber);
|
||||
bankAccountNewAction.setTaxRegistrationReasonCode(TaxRegistrationReasonCode);
|
||||
bankAccountNewAction.setAccount(Account);
|
||||
return bankAccountNewAction;
|
||||
}
|
||||
|
||||
private BankAccountUpdateAction getBankAccountUpdateAction(String BankIdentificationCode, String BankName, String CorrespondentAccount, String CorrespondentAccountName,
|
||||
String Currency, String Destination, String TaxpayerIdentificationNumber, String TaxRegistrationReasonCode,
|
||||
String Account) {
|
||||
BankAccountUpdateAction bankAccountUpdateAction = new BankAccountUpdateAction();
|
||||
bankAccountUpdateAction.setBankIdentificationCode(BankIdentificationCode);
|
||||
bankAccountUpdateAction.setBankName(BankName);
|
||||
bankAccountUpdateAction.setCorrespondentAccount(CorrespondentAccount);
|
||||
bankAccountUpdateAction.setCorrespondentAccountName(CorrespondentAccountName);
|
||||
bankAccountUpdateAction.setCurrency(Currency);
|
||||
bankAccountUpdateAction.setDestination(Destination);
|
||||
bankAccountUpdateAction.setTaxpayerIdentificationNumber(TaxpayerIdentificationNumber);
|
||||
bankAccountUpdateAction.setTaxRegistrationReasonCode(TaxRegistrationReasonCode);
|
||||
bankAccountUpdateAction.setAccount(Account);
|
||||
return bankAccountUpdateAction;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue