added new test

This commit is contained in:
psemenkov 2022-12-02 18:55:30 +03:00
parent 40c716d159
commit d661fa166f
20 changed files with 764 additions and 69 deletions

View file

@ -1,4 +1,4 @@
package ru.spcex.clearing.backendapi.controller.queue.config;
package ru.spcex.clearing.backendapi.controller.config;
import com.hazelcast.config.*;
import com.hazelcast.core.Hazelcast;

View file

@ -1,4 +1,4 @@
package ru.spcex.clearing.backendapi.controller.queue.config;
package ru.spcex.clearing.backendapi.controller.config;
import org.apache.kafka.clients.producer.Producer;
import org.springframework.beans.factory.annotation.Autowired;
@ -10,7 +10,7 @@ import ru.spcex.clearing.backendapi.service.validation.ActionValidationProvider;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@Configuration
public class IOperator {
public class IOperatorTest {
@Autowired
@Qualifier("hazelcastServiceTest")

View file

@ -1,4 +1,4 @@
package ru.spcex.clearing.backendapi.controller.queue.config;
package ru.spcex.clearing.backendapi.controller.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;

View file

@ -1,4 +1,4 @@
package ru.spcex.clearing.backendapi.controller.queue.config;
package ru.spcex.clearing.backendapi.controller.config;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;

View file

@ -1,4 +1,4 @@
package ru.spcex.clearing.backendapi.controller.queue.config;
package ru.spcex.clearing.backendapi.controller.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

View file

@ -1,4 +1,4 @@
package ru.spcex.clearing.backendapi.controller.queue.config;
package ru.spcex.clearing.backendapi.controller.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;

View file

@ -13,8 +13,11 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import ru.spcex.clearing.backendapi.controller.queue.company.DeleteCompanyController;
import ru.spcex.clearing.backendapi.controller.queue.config.*;
import ru.spcex.clearing.backendapi.controller.config.*;
import ru.spcex.clearing.backendapi.controller.queue.account.AccountController;
import ru.spcex.clearing.backendapi.controller.queue.account.BankAccountController;
import ru.spcex.clearing.backendapi.controller.queue.company.*;
import ru.spcex.clearing.backendapi.controller.queue.misc.NotificationController;
import ru.spcex.clearing.backendapi.meta.GetResponseFactory;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@ -23,10 +26,21 @@ import java.util.concurrent.atomic.AtomicLong;
@ContextConfiguration(classes = {
BankAccountControllerConfig.class,
//account
AccountController.class,
BankAccountController.class,
//company
DeleteCompanyController.class,
EditClearingMemberCategoryController.class,
EditCompanyInfoController.class,
EditCompanySymbolController.class,
EditContactController.class,
ProfileDocumentController.class,
//misc
NotificationController.class,
//*****************************
WebTestConfig.class,
IOperator.class,
IOperatorTest.class,
KafkaTestConfig.class,
HazelcastServiceTestConfiguration.class,
StateLoaderImplConfig.class,

View file

@ -0,0 +1,53 @@
package ru.spcex.clearing.backendapi.controller.queue.account;
import com.hazelcast.core.IMap;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import ru.clearing.classes.statics.data.account.Account;
import ru.spcex.clearing.backendapi.controller.queue.AbstractControllerTest;
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import java.util.Collection;
import java.util.Map;
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;
import static ru.spcex.clearing.backendapi.controller.utils.JsonUtil.writeValue;
class AccountControllerTest extends AbstractControllerTest {
private static final String REST_URL = "/accounting/accounts/";
/**
* {@link AccountController#getAll()} <br>
* Тест проверяет получение запроса по REST API и отправку всех записей из таблицы hazelcast Map_BankAccount.<br>
* Входной запрос /securities/bank-accounts/ <br>
* Ответ CommonGetAllResponse <br>
*/
@Test
void getAll() throws Exception {
//ARRANGE
Account existBankAccount = new Account();
existBankAccount.setAccountType("99");
existBankAccount.setAccount("123456789123");
existBankAccount.setId(currentId.get());
IMap<Long, Account> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Account);
iMap.put(existBankAccount.getId(), existBankAccount);
Collection<Account> values = iMap.values();
Collection<Map<String, Object>> all = responseFactory.responseFromObjectCollection(values);
CommonGetAllResponse expected = new CommonGetAllResponse();
expected.fromEntity(all);
//ACT
perform(MockMvcRequestBuilders.get(REST_URL)
.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(expected)));
}
}

View file

@ -27,7 +27,7 @@ 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;
import static ru.spcex.clearing.backendapi.controller.queue.utils.JsonUtil.writeValue;
import static ru.spcex.clearing.backendapi.controller.utils.JsonUtil.writeValue;
class BankAccountControllerTest extends AbstractControllerTest {
private static final String REST_URL = "/securities/bank-accounts/";

View file

@ -18,7 +18,7 @@ import java.util.Map;
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;
import static ru.spcex.clearing.backendapi.controller.queue.utils.JsonUtil.writeValue;
import static ru.spcex.clearing.backendapi.controller.utils.JsonUtil.writeValue;
class DeleteCompanyControllerTest extends AbstractControllerTest {
private static final String REST_URL = "/companies/";

View file

@ -0,0 +1,173 @@
package ru.spcex.clearing.backendapi.controller.queue.company;
import com.hazelcast.core.IMap;
import org.junit.jupiter.api.Test;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import ru.clearing.classes.statics.data.generated.ClearingMemberCategory;
import ru.spcex.clearing.backendapi.controller.queue.AbstractControllerTest;
import ru.spcex.clearing.backendapi.controller.request.cud.company.ClearingMemberCategoryNewAction;
import ru.spcex.clearing.backendapi.controller.request.cud.company.ClearingMemberCategoryUpdateAction;
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
import ru.spcex.clearing.backendapi.controller.response.cud.QueueSuccessResponse;
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
import ru.spcex.clearing.backendapi.domain.actions.IAction;
import ru.spcex.clearing.backendapi.errors.ActionValidationException;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.ActionType;
import java.util.Collection;
import java.util.Map;
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;
import static ru.spcex.clearing.backendapi.controller.utils.JsonUtil.writeValue;
class EditClearingMemberCategoryControllerTest extends AbstractControllerTest {
private static final String REST_URL = "/clearing-member-categories/";
/**
* {@link EditClearingMemberCategoryController#add(ClearingMemberCategoryNewAction)}<br>
* Тест проверяет получение сущности {@link ClearingMemberCategoryNewAction} по REST API и отправку в Apache Kafka.<br>
* Входной запрос {@link ClearingMemberCategoryNewAction}:<br>
* {@link ClearingMemberCategoryNewAction#clearingMemberCategory} - "Category"<br>
* {@link ClearingMemberCategoryNewAction#companyId} - currentId<br>
*/
@Test
void add() throws Exception {
//ARRANGE
ClearingMemberCategoryNewAction clearingMemberCategoryNewAction = new ClearingMemberCategoryNewAction();
clearingMemberCategoryNewAction.setClearingMemberCategory("Category");
clearingMemberCategoryNewAction.setCompanyId(0L);
CudResponse expected = new CudResponse();
expected.setCode(0L);
expected.setMessage("success");
expected.setPayload(new QueueSuccessResponse(ActionType.NEW, currentId.getAndIncrement()));
//ACT
perform(MockMvcRequestBuilders.post(REST_URL)
.contentType(MediaType.APPLICATION_JSON)
.content(writeValue(clearingMemberCategoryNewAction)))
.andDo(print())//output to the log request and response
//ASSERT
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(expected)));
}
/**
* {@link EditClearingMemberCategoryController#add(ClearingMemberCategoryNewAction)}<br>
* Тест проверяет получение сущности {@link ClearingMemberCategoryNewAction} по REST API и отправку в Apache Kafka.<br>
* Входной запрос {@link ClearingMemberCategoryNewAction}:<br>
* {@link ClearingMemberCategoryNewAction#clearingMemberCategory} - "Category"<br>
* {@link ClearingMemberCategoryNewAction#companyId} - currentId<br>
*/
// @Test валидации пока нет
void addWithException() {
assertThrowsFor(getClearingMemberCategoryNewAction("Category", null));
assertThrowsFor(getClearingMemberCategoryNewAction("", 0L));
}
/**
* {@link EditClearingMemberCategoryController#update(Long, ClearingMemberCategoryUpdateAction)}<br>
* Тест проверяет получение сущности {@link ClearingMemberCategoryUpdateAction} по REST API и отправку в Apache Kafka.<br>
* Входной запрос {@link ClearingMemberCategoryUpdateAction}:<br>
* {@link ClearingMemberCategoryUpdateAction#clearingMemberCategory} - Category<br>
* {@link ClearingMemberCategoryUpdateAction#id} - currentId<br>
*/
@Test
void update() throws Exception {
//ARRANGE
ClearingMemberCategoryUpdateAction clearingMemberCategoryUpdateAction = new ClearingMemberCategoryUpdateAction();
clearingMemberCategoryUpdateAction.setClearingMemberCategory("Category");
clearingMemberCategoryUpdateAction.setId(currentId.get());
CudResponse expected = new CudResponse();
expected.setCode(0L);
expected.setMessage("success");
expected.setPayload(new QueueSuccessResponse(ActionType.UPDATE, currentId.getAndIncrement()));
//ACT
perform(MockMvcRequestBuilders.put(REST_URL + clearingMemberCategoryUpdateAction.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(writeValue(clearingMemberCategoryUpdateAction)))
.andDo(print())//output to the log request and response
//ASSERT
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(expected)));
}
/**
* {@link EditClearingMemberCategoryController#delete(Long)} <br>
* Тест проверяет получение id сущности {@link Long} по REST API и отправку в Apache Kafka.<br>
* Входной запрос /clearing-member-categories/{@link Long}: - currentId<br>
*/
@Test
void delete() throws Exception {
//ARRANGE
CudResponse expected = new CudResponse();
expected.setCode(0L);
expected.setMessage("success");
expected.setPayload(new QueueSuccessResponse(ActionType.DELETE, currentId.getAndIncrement()));
//ACT
perform(MockMvcRequestBuilders.delete(REST_URL + expected.getPayload().getId())
.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(expected)));
}
/**
* {@link EditClearingMemberCategoryController#getAll()} <br>
* Тест проверяет получение запроса по REST API и отправку всех записей из таблицы hazelcast Map_BankAccount.<br>
* Входной запрос /clearing-member-categories/ <br>
* Ответ CommonGetAllResponse <br>
*/
@Test
void getAll() throws Exception {
//ARRANGE
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
clearingMemberCategory.setClearingMemberCategory("Category");
clearingMemberCategory.setCompanyId(1000000L);
clearingMemberCategory.setId(currentId.get());
IMap<Long, ClearingMemberCategory> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ClearingMemberCategory);
iMap.put(clearingMemberCategory.getId(), clearingMemberCategory);
Collection<ClearingMemberCategory> values = iMap.values();
Collection<Map<String, Object>> all = responseFactory.responseFromObjectCollection(values);
CommonGetAllResponse expected = new CommonGetAllResponse();
expected.fromEntity(all);
//ACT
perform(MockMvcRequestBuilders.get(REST_URL)
.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(expected)));
}
private void assertThrowsFor(IAction<?> iAction) {
assertThrows(ActionValidationException.class, () -> {
try {
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 ClearingMemberCategoryNewAction getClearingMemberCategoryNewAction(String category, Long companyId) {
ClearingMemberCategoryNewAction clearingMemberCategoryNewAction = new ClearingMemberCategoryNewAction();
clearingMemberCategoryNewAction.setClearingMemberCategory(category);
clearingMemberCategoryNewAction.setCompanyId(companyId);
return clearingMemberCategoryNewAction;
}
}

View file

@ -0,0 +1,126 @@
package ru.spcex.clearing.backendapi.controller.queue.company;
import org.junit.jupiter.api.Test;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import ru.spcex.clearing.backendapi.controller.queue.AbstractControllerTest;
import ru.spcex.clearing.backendapi.controller.request.cud.company.ClearingMemberCategoryNewAction;
import ru.spcex.clearing.backendapi.controller.request.cud.company.CompanyInfoUpdateAction;
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 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;
import static ru.spcex.clearing.backendapi.controller.utils.JsonUtil.writeValue;
class EditCompanyInfoControllerTest extends AbstractControllerTest {
private static final String REST_URL = "/company-infos/";
/**
* {@link EditCompanyInfoController#update(Long, CompanyInfoUpdateAction)}<br>
* Тест проверяет получение сущности {@link CompanyInfoUpdateAction} по REST API и отправку в Apache Kafka.<br>
* Входной запрос {@link CompanyInfoUpdateAction}:<br>
* {@link CompanyInfoUpdateAction#clearingCode} - 11<br>
* {@link CompanyInfoUpdateAction#tradingCode} - 11<br>
* {@link CompanyInfoUpdateAction#corporationSoleType} - 0000<br>
* {@link CompanyInfoUpdateAction#countryCode} - 0000<br>
* {@link CompanyInfoUpdateAction#description} - exists description<br>
* {@link CompanyInfoUpdateAction#professionalSign} - 0000<br>
* {@link CompanyInfoUpdateAction#legalKind} - 0000<br>
* {@link CompanyInfoUpdateAction#organizationType} - 0000<br>
* {@link CompanyInfoUpdateAction#residence} - 0000<br>
* {@link CompanyInfoUpdateAction#shortNameEng} - exists shortNameEng<br>
* {@link CompanyInfoUpdateAction#fullNameEng} - exists fullNameEng<br>
* {@link CompanyInfoUpdateAction#shortName} - exists shortName<br>
* {@link CompanyInfoUpdateAction#fullName} - exists fullName<br>
* {@link CompanyInfoUpdateAction- Category<br>
* {@link CompanyInfoUpdateAction- Category<br>
* {@link CompanyInfoUpdateAction- Category<br>
* {@link CompanyInfoUpdateAction#id} - currentId<br>
*/
// @Test валидации пока нет
void addWithException() {
assertThrowsFor(getClearingMemberCategoryNewAction("Category", null));
assertThrowsFor(getClearingMemberCategoryNewAction("", 0L));
}
/**
* {@link EditCompanyInfoController#update(Long, CompanyInfoUpdateAction)}<br>
* Тест проверяет получение сущности {@link CompanyInfoUpdateAction} по REST API и отправку в Apache Kafka.<br>
* Входной запрос {@link CompanyInfoUpdateAction}:<br>
* {@link CompanyInfoUpdateAction#clearingCode} - 11<br>
* {@link CompanyInfoUpdateAction#tradingCode} - 11<br>
* {@link CompanyInfoUpdateAction#corporationSoleType} - 0000<br>
* {@link CompanyInfoUpdateAction#countryCode} - 0000<br>
* {@link CompanyInfoUpdateAction#description} - exists description<br>
* {@link CompanyInfoUpdateAction#professionalSign} - 0000<br>
* {@link CompanyInfoUpdateAction#legalKind} - 0000<br>
* {@link CompanyInfoUpdateAction#organizationType} - 0000<br>
* {@link CompanyInfoUpdateAction#residence} - 0000<br>
* {@link CompanyInfoUpdateAction#shortNameEng} - exists shortNameEng<br>
* {@link CompanyInfoUpdateAction#fullNameEng} - exists fullNameEng<br>
* {@link CompanyInfoUpdateAction#shortName} - exists shortName<br>
* {@link CompanyInfoUpdateAction#fullName} - exists fullName<br>
* {@link CompanyInfoUpdateAction- Category<br>
* {@link CompanyInfoUpdateAction- Category<br>
* {@link CompanyInfoUpdateAction- Category<br>
* {@link CompanyInfoUpdateAction#id} - currentId<br>
*/
@Test
void update() throws Exception {
//ARRANGE
CompanyInfoUpdateAction companyInfoUpdateAction = new CompanyInfoUpdateAction();
companyInfoUpdateAction.setClearingCode("11");
companyInfoUpdateAction.setTradingCode("11");
companyInfoUpdateAction.setCorporationSoleType("0000");
companyInfoUpdateAction.setCountryCode("0000");
companyInfoUpdateAction.setDescription("exists description");
companyInfoUpdateAction.setProfessionalSign("0000");
companyInfoUpdateAction.setLegalKind("0000");
companyInfoUpdateAction.setOrganizationType("0000");
companyInfoUpdateAction.setResidence("0000");
companyInfoUpdateAction.setShortNameEng("exists shortNameEng");
companyInfoUpdateAction.setFullNameEng("exists fullNameEng");
companyInfoUpdateAction.setShortName("exists shortName");
companyInfoUpdateAction.setFullName("exists fullName");
companyInfoUpdateAction.setId(currentId.get());
CudResponse expected = new CudResponse();
expected.setCode(0L);
expected.setMessage("success");
expected.setPayload(new QueueSuccessResponse(ActionType.UPDATE, currentId.getAndIncrement()));
//ACT
perform(MockMvcRequestBuilders.put(REST_URL + companyInfoUpdateAction.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(writeValue(companyInfoUpdateAction)))
.andDo(print())//output to the log request and response
//ASSERT
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(expected)));
}
private void assertThrowsFor(IAction<?> iAction) {
assertThrows(ActionValidationException.class, () -> {
try {
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 ClearingMemberCategoryNewAction getClearingMemberCategoryNewAction(String category, Long companyId) {
ClearingMemberCategoryNewAction clearingMemberCategoryNewAction = new ClearingMemberCategoryNewAction();
clearingMemberCategoryNewAction.setClearingMemberCategory(category);
clearingMemberCategoryNewAction.setCompanyId(companyId);
return clearingMemberCategoryNewAction;
}
}

View file

@ -0,0 +1,129 @@
package ru.spcex.clearing.backendapi.controller.queue.company;
import com.hazelcast.core.IMap;
import org.junit.jupiter.api.Test;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import ru.clearing.classes.statics.data.company.CompanySymbols;
import ru.spcex.clearing.backendapi.controller.queue.AbstractControllerTest;
import ru.spcex.clearing.backendapi.controller.request.cud.company.ClearingMemberCategoryNewAction;
import ru.spcex.clearing.backendapi.controller.request.cud.company.CompanySymbolUpdateAction;
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
import ru.spcex.clearing.backendapi.controller.response.cud.QueueSuccessResponse;
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
import ru.spcex.clearing.backendapi.domain.actions.IAction;
import ru.spcex.clearing.backendapi.errors.ActionValidationException;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.ActionType;
import java.util.Collection;
import java.util.Map;
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;
import static ru.spcex.clearing.backendapi.controller.utils.JsonUtil.writeValue;
class EditCompanySymbolControllerTest extends AbstractControllerTest {
private static final String REST_URL = "/company-symbols/";
/**
* {@link EditCompanySymbolController#update(Long, CompanySymbolUpdateAction)}<br>
* Тест проверяет получение сущности {@link CompanySymbolUpdateAction} по REST API и отправку в Apache Kafka.<br>
* Входной запрос {@link CompanySymbolUpdateAction}:<br>
* {@link CompanySymbolUpdateAction#companyId} - 1000L<br>
* {@link CompanySymbolUpdateAction#companySymbol} - Symbol<br>
* {@link CompanySymbolUpdateAction#companySymbolValue} - SymbolValue<br>
* {@link CompanySymbolUpdateAction#id} - currentId<br>
*/
// @Test валидации пока нет
void addWithException() {
assertThrowsFor(getClearingMemberCategoryNewAction("Category", null));
assertThrowsFor(getClearingMemberCategoryNewAction("", 0L));
}
/**
* {@link EditCompanySymbolController#update(Long, CompanySymbolUpdateAction)}<br>
* Тест проверяет получение сущности {@link CompanySymbolUpdateAction} по REST API и отправку в Apache Kafka.<br>
* Входной запрос {@link CompanySymbolUpdateAction}:<br>
* {@link CompanySymbolUpdateAction#companyId} - 1000L<br>
* {@link CompanySymbolUpdateAction#companySymbol} - Symbol<br>
* {@link CompanySymbolUpdateAction#companySymbolValue} - SymbolValue<br>
* {@link CompanySymbolUpdateAction#id} - currentId<br>
*/
@Test
void update() throws Exception {
//ARRANGE
CompanySymbolUpdateAction companySymbolUpdateAction = new CompanySymbolUpdateAction();
companySymbolUpdateAction.setCompanyId(1000L);
companySymbolUpdateAction.setCompanySymbol("Symbol");
companySymbolUpdateAction.setCompanySymbolValue("SymbolValue");
companySymbolUpdateAction.setId(currentId.get());
CudResponse expected = new CudResponse();
expected.setCode(0L);
expected.setMessage("success");
expected.setPayload(new QueueSuccessResponse(ActionType.UPDATE, currentId.getAndIncrement()));
//ACT
perform(MockMvcRequestBuilders.put(REST_URL + companySymbolUpdateAction.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(writeValue(companySymbolUpdateAction)))
.andDo(print())//output to the log request and response
//ASSERT
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(expected)));
}
/**
* {@link EditCompanySymbolController#getAll()} <br>
* Тест проверяет получение запроса по REST API и отправку всех записей из таблицы hazelcast Map_BankAccount.<br>
* Входной запрос /clearing-member-categories/ <br>
* Ответ CommonGetAllResponse <br>
*/
@Test
void getAll() throws Exception {
//ARRANGE
CompanySymbols companySymbols = new CompanySymbols();
companySymbols.setCompanyId(1000L);
companySymbols.setCompanySymbol("Symbol");
companySymbols.setCompanySymbolValue("SymbolValue");
companySymbols.setId(currentId.get());
IMap<Long, CompanySymbols> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_CompanySymbols);
iMap.put(companySymbols.getId(), companySymbols);
Collection<CompanySymbols> values = iMap.values();
Collection<Map<String, Object>> all = responseFactory.responseFromObjectCollection(values);
CommonGetAllResponse expected = new CommonGetAllResponse();
expected.fromEntity(all);
//ACT
perform(MockMvcRequestBuilders.get(REST_URL)
.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(expected)));
}
private void assertThrowsFor(IAction<?> iAction) {
assertThrows(ActionValidationException.class, () -> {
try {
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 ClearingMemberCategoryNewAction getClearingMemberCategoryNewAction(String category, Long companyId) {
ClearingMemberCategoryNewAction clearingMemberCategoryNewAction = new ClearingMemberCategoryNewAction();
clearingMemberCategoryNewAction.setClearingMemberCategory(category);
clearingMemberCategoryNewAction.setCompanyId(companyId);
return clearingMemberCategoryNewAction;
}
}

View file

@ -0,0 +1,130 @@
package ru.spcex.clearing.backendapi.controller.queue.company;
import com.hazelcast.core.IMap;
import org.junit.jupiter.api.Test;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import ru.clearing.classes.statics.data.profile.Contact;
import ru.spcex.clearing.backendapi.controller.queue.AbstractControllerTest;
import ru.spcex.clearing.backendapi.controller.request.cud.company.ClearingMemberCategoryNewAction;
import ru.spcex.clearing.backendapi.controller.request.cud.company.CompanySymbolUpdateAction;
import ru.spcex.clearing.backendapi.controller.request.cud.company.ContactUpdateAction;
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
import ru.spcex.clearing.backendapi.controller.response.cud.QueueSuccessResponse;
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
import ru.spcex.clearing.backendapi.domain.actions.IAction;
import ru.spcex.clearing.backendapi.errors.ActionValidationException;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.ActionType;
import java.util.Collection;
import java.util.Map;
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;
import static ru.spcex.clearing.backendapi.controller.utils.JsonUtil.writeValue;
class EditContactControllerTest extends AbstractControllerTest {
private static final String REST_URL = "/contacts/";
/**
* {@link EditCompanySymbolController#update(Long, CompanySymbolUpdateAction)}<br>
* Тест проверяет получение сущности {@link CompanySymbolUpdateAction} по REST API и отправку в Apache Kafka.<br>
* Входной запрос {@link CompanySymbolUpdateAction}:<br>
* {@link CompanySymbolUpdateAction#companyId} - 1000L<br>
* {@link CompanySymbolUpdateAction#companySymbol} - Symbol<br>
* {@link CompanySymbolUpdateAction#companySymbolValue} - SymbolValue<br>
* {@link CompanySymbolUpdateAction#id} - currentId<br>
*/
// @Test валидации пока нет
void addWithException() {
assertThrowsFor(getClearingMemberCategoryNewAction("Category", null));
assertThrowsFor(getClearingMemberCategoryNewAction("", 0L));
}
/**
* {@link EditContactController#update(Long, ContactUpdateAction)}<br>
* Тест проверяет получение сущности {@link ContactUpdateAction} по REST API и отправку в Apache Kafka.<br>
* Входной запрос {@link ContactUpdateAction}:<br>
* {@link ContactUpdateAction#companyId} - 1000L<br>
* {@link ContactUpdateAction#contactType} - ContactType<br>
* {@link ContactUpdateAction#contactValue} - ContactValue<br>
* {@link ContactUpdateAction#id} - currentId<br>
*/
@Test
void update() throws Exception {
//ARRANGE
ContactUpdateAction companySymbolUpdateAction = new ContactUpdateAction();
companySymbolUpdateAction.setCompanyId(1000L);
companySymbolUpdateAction.setContactType("ContactType");
companySymbolUpdateAction.setContactValue("ContactValue");
companySymbolUpdateAction.setId(currentId.get());
CudResponse expected = new CudResponse();
expected.setCode(0L);
expected.setMessage("success");
expected.setPayload(new QueueSuccessResponse(ActionType.UPDATE, currentId.getAndIncrement()));
//ACT
perform(MockMvcRequestBuilders.put(REST_URL + companySymbolUpdateAction.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(writeValue(companySymbolUpdateAction)))
.andDo(print())//output to the log request and response
//ASSERT
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(expected)));
}
/**
* {@link EditContactController#getAll()} <br>
* Тест проверяет получение запроса по REST API и отправку всех записей из таблицы hazelcast Map_BankAccount.<br>
* Входной запрос /contacts/ <br>
* Ответ CommonGetAllResponse <br>
*/
@Test
void getAll() throws Exception {
//ARRANGE
Contact companySymbolUpdateAction = new Contact();
companySymbolUpdateAction.setCompanyId(1000L);
companySymbolUpdateAction.setContactType("ContactType");
companySymbolUpdateAction.setContactValue("ContactValue");
companySymbolUpdateAction.setId(currentId.get());
IMap<Long, Contact> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Contact);
iMap.put(companySymbolUpdateAction.getId(), companySymbolUpdateAction);
Collection<Contact> values = iMap.values();
Collection<Map<String, Object>> all = responseFactory.responseFromObjectCollection(values);
CommonGetAllResponse expected = new CommonGetAllResponse();
expected.fromEntity(all);
//ACT
perform(MockMvcRequestBuilders.get(REST_URL)
.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(expected)));
}
private void assertThrowsFor(IAction<?> iAction) {
assertThrows(ActionValidationException.class, () -> {
try {
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 ClearingMemberCategoryNewAction getClearingMemberCategoryNewAction(String category, Long companyId) {
ClearingMemberCategoryNewAction clearingMemberCategoryNewAction = new ClearingMemberCategoryNewAction();
clearingMemberCategoryNewAction.setClearingMemberCategory(category);
clearingMemberCategoryNewAction.setCompanyId(companyId);
return clearingMemberCategoryNewAction;
}
}

View file

@ -0,0 +1,64 @@
package ru.spcex.clearing.backendapi.controller.queue.company;
import com.hazelcast.core.IMap;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import ru.clearing.classes.statics.data.profile.ProfileDocument;
import ru.spcex.clearing.backendapi.controller.queue.AbstractControllerTest;
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import java.time.LocalDate;
import java.util.Collection;
import java.util.Map;
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;
import static ru.spcex.clearing.backendapi.controller.utils.JsonUtil.writeValue;
class ProfileDocumentControllerTest extends AbstractControllerTest {
private static final String REST_URL = "/profile-documents/";
/**
* {@link ProfileDocumentController#getAll()} <br>
* Тест проверяет получение запроса по REST API и отправку всех записей из таблицы hazelcast Map_BankAccount.<br>
* Входной запрос /contacts/ <br>
* Ответ CommonGetAllResponse <br>
*/
@Test
void getAll() throws Exception {
//ARRANGE
ProfileDocument profileDocument = new ProfileDocument();
profileDocument.setCompanyId(1000L);
profileDocument.setDocumentType("DocumentType");
profileDocument.setIssueDate(LocalDate.now());
profileDocument.setIssuePlace("IssuePlace");
profileDocument.setIssuer("Issuer");
profileDocument.setIssuerCode("IssuerCode");
profileDocument.setName("Name");
profileDocument.setNumber("Number");
profileDocument.setPlace("Place");
profileDocument.setValidFromDate(LocalDate.now());
profileDocument.setValidToDate(LocalDate.now());
profileDocument.setLink("Link");
profileDocument.setId(currentId.get());
IMap<Long, ProfileDocument> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ProfileDocument);
iMap.put(profileDocument.getId(), profileDocument);
Collection<ProfileDocument> values = iMap.values();
Collection<Map<String, Object>> all = responseFactory.responseFromObjectCollection(values);
CommonGetAllResponse expected = new CommonGetAllResponse();
expected.fromEntity(all);
//ACT
perform(MockMvcRequestBuilders.get(REST_URL)
.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(expected)));
}
}

View file

@ -1,28 +0,0 @@
package ru.spcex.clearing.backendapi.controller.queue.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ru.spcex.clearing.backendapi.controller.queue.account.BankAccountController;
import ru.spcex.clearing.backendapi.service.IOperator;
import ru.spcex.clearing.backendapi.service.impl.StateLoaderImpl;
@Configuration
public class BankAccountControllerConfig {
@Autowired
@Qualifier("iOperatorTest")
private IOperator operator;
@Autowired
@Qualifier("stateLoaderImpl")
private StateLoaderImpl stateLoader;
@Bean
public BankAccountController createBankAccountController() {
return new BankAccountController(operator, stateLoader);
}
}

View file

@ -1,25 +0,0 @@
package ru.spcex.clearing.backendapi.controller.queue.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ru.spcex.clearing.backendapi.controller.queue.company.DeleteCompanyController;
import ru.spcex.clearing.backendapi.service.IOperator;
import ru.spcex.clearing.backendapi.service.impl.StateLoaderImpl;
@Configuration
public class DeleteCompanyControllerConfig {
@Autowired
@Qualifier("iOperatorTest")
private IOperator operator;
@Autowired
@Qualifier("stateLoaderImpl")
private StateLoaderImpl stateLoader;
@Bean
public DeleteCompanyController createDeleteCompanyController() {
return new DeleteCompanyController(operator, stateLoader);
}
}

View file

@ -0,0 +1,59 @@
package ru.spcex.clearing.backendapi.controller.queue.misc;
import com.hazelcast.core.IMap;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import ru.clearing.classes.statics.data.misc.Notification;
import ru.spcex.clearing.backendapi.controller.queue.AbstractControllerTest;
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import java.time.Instant;
import java.time.LocalDate;
import java.util.Collection;
import java.util.Map;
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;
import static ru.spcex.clearing.backendapi.controller.utils.JsonUtil.writeValue;
class NotificationControllerTest extends AbstractControllerTest {
private static final String REST_URL = "/notifications/";
/**
* {@link NotificationController#getAll()} <br>
* Тест проверяет получение запроса по REST API и отправку всех записей из таблицы hazelcast Map_BankAccount.<br>
* Входной запрос /contacts/ <br>
* Ответ CommonGetAllResponse <br>
*/
@Test
void getAll() throws Exception {
//ARRANGE
Notification profileDocument = new Notification();
profileDocument.setClearingDate(LocalDate.now());
profileDocument.setSenderId(1000L);
profileDocument.setAddresseeId(1000L);
profileDocument.setObjectType("ObjectType");
profileDocument.setObjectId(Instant.now());
profileDocument.setNotificationStatus("Status");
profileDocument.setId(currentId.get());
IMap<Long, Notification> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Notification);
iMap.put(profileDocument.getId(), profileDocument);
Collection<Notification> values = iMap.values();
Collection<Map<String, Object>> all = responseFactory.responseFromObjectCollection(values);
CommonGetAllResponse expected = new CommonGetAllResponse();
expected.fromEntity(all);
//ACT
perform(MockMvcRequestBuilders.get(REST_URL)
.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(expected)));
}
}

View file

@ -1,4 +1,4 @@
package ru.spcex.clearing.backendapi.controller.queue.utils;
package ru.spcex.clearing.backendapi.controller.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@ -9,7 +9,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static ru.spcex.clearing.backendapi.controller.queue.config.Jackson2HttpConverterTestConfig.JacksonObjectMapper.getMapper;
import static ru.spcex.clearing.backendapi.controller.config.Jackson2HttpConverterTestConfig.JacksonObjectMapper.getMapper;
public class JsonUtil {

View file

@ -1,4 +1,4 @@
package ru.spcex.clearing.backendapi.controller.queue.utils;
package ru.spcex.clearing.backendapi.controller.utils;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;