up test to junit5 + annotations

This commit is contained in:
ggmaleva 2021-10-01 17:11:17 +03:00
parent 2a9d5884ed
commit f200d68977
No known key found for this signature in database
GPG Key ID: 0E412B78565B108F
29 changed files with 405 additions and 389 deletions

View File

@ -17,11 +17,8 @@ import com.rbkmoney.fraudbusters.management.service.iface.AuditService;
import com.rbkmoney.fraudbusters.management.service.payment.PaymentsListsService;
import com.rbkmoney.fraudbusters.management.utils.*;
import com.rbkmoney.fraudbusters.management.utils.parser.CsvPaymentCountInfoParser;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -37,7 +34,6 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
@ -46,11 +42,11 @@ import org.springframework.web.util.UriComponentsBuilder;
import java.util.HashMap;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = {ParametersService.class, PaymentsListsResource.class,
UserInfoService.class, WbListRecordToRowConverter.class, PaymentCountInfoGenerator.class,
CountInfoUtils.class, CountInfoApiUtils.class, CsvPaymentCountInfoParser.class,
@ -91,8 +87,8 @@ public class ExceptionApplicationTest {
String paymentListPath;
String paymentListFilterPath;
@Before
public void init() {
@BeforeEach
void init() {
paymentListPath = String.format(MethodPaths.SERVICE_BASE_URL + MethodPaths.INSERT_PAYMENTS_LIST_ROW_PATH,
serverPort);
paymentListFilterPath = String.format(MethodPaths.SERVICE_BASE_URL + MethodPaths.INSERT_PAYMENTS_FILTER_PATH,
@ -109,7 +105,7 @@ public class ExceptionApplicationTest {
}
@Test
public void executionRestTest() {
void executionRestTest() {
RestTemplate restTemplate = restTemplateBuilder.build();
Mockito.when(wbListCommandService.sendListRecords(any(), any(), any(), any()))
.thenReturn(ResponseEntity.ok(List.of(ID_TEST)));
@ -117,16 +113,17 @@ public class ExceptionApplicationTest {
ResponseEntity<List<String>> response = restTemplate.exchange(paymentListPath, HttpMethod.POST,
new HttpEntity<>(createRequest()), new ParameterizedTypeReference<>() {
});
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
Assert.assertEquals(response.getBody().get(0), ID_TEST);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(response.getBody().get(0), ID_TEST);
}
@Test(expected = HttpServerErrorException.InternalServerError.class)
public void executionRestDaoExceptionTest() {
@Test
void executionRestDaoExceptionTest() {
RestTemplate restTemplate = restTemplateBuilder.build();
Mockito.when(wbListCommandService.sendListRecords(any(), any(), any(), any()))
.thenThrow(new DaoException(TEST_MESSAGE));
restTemplate.postForEntity(paymentListPath, createRequest(), ErrorResponse.class);
assertThrows(HttpServerErrorException.InternalServerError.class,
() -> restTemplate.postForEntity(paymentListPath, createRequest(), ErrorResponse.class));
}
private ListRowsInsertRequest createRequest() {
@ -138,17 +135,18 @@ public class ExceptionApplicationTest {
return listRowsInsertRequest;
}
@Test(expected = HttpServerErrorException.InternalServerError.class)
public void executionRestKafkaSerializationTest() {
@Test
void executionRestKafkaSerializationTest() {
RestTemplate restTemplate = restTemplateBuilder.build();
Mockito.when(wbListCommandService.sendListRecords(any(), any(), any(), any()))
.thenThrow(new KafkaSerializationException(TEST_MESSAGE));
restTemplate.postForEntity(paymentListPath, createRequest(), ErrorResponse.class);
assertThrows(HttpServerErrorException.InternalServerError.class,
() -> restTemplate.postForEntity(paymentListPath, createRequest(), ErrorResponse.class));
}
@Test(expected = HttpClientErrorException.BadRequest.class)
public void getRestTestBadRequest() {
@Test
void getRestTestBadRequest() {
Mockito.when(wbListCommandService.sendListRecords(any(), any(), any(), any()))
.thenThrow(new KafkaSerializationException(TEST_MESSAGE));
HashMap<String, Object> uriVariables = new HashMap<>();
@ -159,6 +157,7 @@ public class ExceptionApplicationTest {
uriVariables.put("partyId", PARTY_ID);
uriVariables.put("shopId", SHOP_ID);
RestTemplate restTemplate = restTemplateBuilder.build();
restTemplate.getForEntity(builder.buildAndExpand(uriVariables).toUri(), ErrorResponse.class);
assertThrows(HttpClientErrorException.BadRequest.class,
() -> restTemplate.getForEntity(builder.buildAndExpand(uriVariables).toUri(), ErrorResponse.class));
}
}

View File

@ -2,6 +2,7 @@ package com.rbkmoney.fraudbusters.management;
import com.rbkmoney.damsel.fraudbusters.P2PServiceSrv;
import com.rbkmoney.damsel.fraudbusters.ValidateTemplateResponse;
import com.rbkmoney.fraudbusters.management.config.KafkaITest;
import com.rbkmoney.fraudbusters.management.dao.p2p.group.P2PGroupDao;
import com.rbkmoney.fraudbusters.management.dao.p2p.group.P2pGroupReferenceDao;
import com.rbkmoney.fraudbusters.management.dao.p2p.reference.P2pReferenceDao;
@ -14,11 +15,9 @@ import com.rbkmoney.fraudbusters.management.filter.UnknownP2pTemplateInReference
import com.rbkmoney.fraudbusters.management.resource.p2p.P2PTemplateCommandResource;
import com.rbkmoney.fraudbusters.management.resource.p2p.P2pGroupCommandResource;
import com.rbkmoney.fraudbusters.management.service.iface.AuditService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.auth.BasicUserPrincipal;
import org.apache.thrift.TException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@ -28,7 +27,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Collections;
import java.util.List;
@ -38,11 +36,10 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@Slf4j
@RunWith(SpringRunner.class)
@KafkaITest
@EnableAutoConfiguration(exclude = {FlywayAutoConfiguration.class, JooqAutoConfiguration.class})
@SpringBootTest(classes = FraudbustersManagementApplication.class)
public class P2pTemplateApplicationTest extends AbstractKafkaIntegrationTest {
@SpringBootTest
public class P2pTemplateApplicationTest {
public static final String TEMPLATE_ID = "template_id";
public static final String IDENTITY_ID = "identity_id";
@ -73,7 +70,7 @@ public class P2pTemplateApplicationTest extends AbstractKafkaIntegrationTest {
P2pGroupCommandResource groupCommandResource;
@Test
public void templateTest() throws TException {
void templateTest() throws TException {
when(iface.validateCompilationTemplate(anyList())).thenReturn(new ValidateTemplateResponse()
.setErrors(List.of()));
@ -93,7 +90,7 @@ public class P2pTemplateApplicationTest extends AbstractKafkaIntegrationTest {
}
@Test
public void referenceTest() {
void referenceTest() {
when(unknownP2pTemplateInReferenceFilter.test(any())).thenReturn(true);
P2pReferenceModel referenceModel = createReference(ID, TEMPLATE_ID);
@ -128,7 +125,7 @@ public class P2pTemplateApplicationTest extends AbstractKafkaIntegrationTest {
}
@Test
public void groupReferenceTest() {
void groupReferenceTest() {
P2pGroupReferenceModel groupReferenceModel = new P2pGroupReferenceModel();
groupReferenceModel.setId(ID);
String identityId = IDENTITY_ID;

View File

@ -2,21 +2,18 @@ package com.rbkmoney.fraudbusters.management;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rbkmoney.damsel.wb_list.*;
import com.rbkmoney.fraudbusters.management.config.KafkaITest;
import com.rbkmoney.fraudbusters.management.dao.p2p.wblist.P2PWbListDao;
import com.rbkmoney.fraudbusters.management.domain.p2p.P2pCountInfo;
import com.rbkmoney.fraudbusters.management.domain.p2p.P2pListRecord;
import com.rbkmoney.fraudbusters.management.domain.p2p.request.P2pListRowsInsertRequest;
import com.rbkmoney.fraudbusters.management.domain.tables.pojos.P2pWbListRecords;
import com.rbkmoney.fraudbusters.management.serializer.CommandChangeDeserializer;
import com.rbkmoney.fraudbusters.management.service.iface.AuditService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaConsumer;
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaProducer;
import org.apache.thrift.TBase;
import org.junit.jupiter.api.Test;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@ -30,26 +27,23 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.junit4.SpringRunner;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.testcontainers.shaded.com.trilead.ssh2.ChannelCondition.TIMEOUT;
@Slf4j
@RunWith(SpringRunner.class)
@KafkaITest
@EnableAutoConfiguration(exclude = {FlywayAutoConfiguration.class, JooqAutoConfiguration.class})
@SpringBootTest(
classes = FraudbustersManagementApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class P2pWbListApplicationTest extends AbstractKafkaIntegrationTest {
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class P2pWbListApplicationTest {
public static final String IDENTITY_ID = "identityId";
private static final String VALUE = "value";
@ -69,20 +63,23 @@ public class P2pWbListApplicationTest extends AbstractKafkaIntegrationTest {
@LocalServerPort
private int port;
@Autowired
private KafkaProducer<TBase<?, ?>> testThriftKafkaProducer;
@Autowired
private KafkaConsumer<ChangeCommand> testCommandKafkaConsumer;
@Test
public void listenCreated() throws ExecutionException, InterruptedException {
void listenCreated() {
clearInvocations(wbListDao);
Event event = new Event();
Row row = createRow(ListType.black);
event.setRow(row);
event.setEventType(EventType.CREATED);
ProducerRecord producerRecord = new ProducerRecord<>(topicEventSink, "test", event);
try (Producer<String, Event> producer = createProducer()) {
producer.send(producerRecord).get();
producer.send(new ProducerRecord<>(topicEventSink, "test_1", event)).get();
producer.send(new ProducerRecord<>(topicEventSink, "test_2", event)).get();
}
testThriftKafkaProducer.send(topicEventSink, event);
testThriftKafkaProducer.send(topicEventSink, event);
testThriftKafkaProducer.send(topicEventSink, event);
await().untilAsserted(() -> {
verify(wbListDao, times(3)).saveListRecord(any());
@ -90,7 +87,7 @@ public class P2pWbListApplicationTest extends AbstractKafkaIntegrationTest {
}
@Test
public void listenCreatedGrey() throws ExecutionException, InterruptedException {
void listenCreatedGrey() {
clearInvocations(wbListDao);
Event event = new Event();
@ -105,12 +102,9 @@ public class P2pWbListApplicationTest extends AbstractKafkaIntegrationTest {
event.setRow(row);
try (Producer<String, Event> producer = createProducer()) {
ProducerRecord<String, Event> producerRecord = new ProducerRecord<>(topicEventSink, "test", event);
producer.send(producerRecord).get();
producer.send(new ProducerRecord<>(topicEventSink, "test_1", event)).get();
producer.send(new ProducerRecord<>(topicEventSink, "test_2", event)).get();
}
testThriftKafkaProducer.send(topicEventSink, event);
testThriftKafkaProducer.send(topicEventSink, event);
testThriftKafkaProducer.send(topicEventSink, event);
await().untilAsserted(() -> {
verify(wbListDao, times(3)).saveListRecord(any());
@ -118,25 +112,23 @@ public class P2pWbListApplicationTest extends AbstractKafkaIntegrationTest {
}
@Test
public void listenDeleted() throws ExecutionException, InterruptedException {
void listenDeleted() {
Event event = new Event();
Row row = createRow(ListType.black);
event.setRow(row);
event.setEventType(EventType.DELETED);
try (Producer<String, Event> producer = createProducer()) {
ProducerRecord<String, Event> producerRecord = new ProducerRecord<>(topicEventSink, "test", event);
producer.send(producerRecord).get();
await().untilAsserted(() -> {
verify(wbListDao, times(1)).removeRecord((P2pWbListRecords) any());
});
}
testThriftKafkaProducer.send(topicEventSink, event);
await().untilAsserted(() -> {
verify(wbListDao, times(1)).removeRecord(any(P2pWbListRecords.class));
});
}
@Test
public void getAvailableListNames() {
void getAvailableListNames() {
final String[] names = restTemplate.getForObject(
"http://localhost:" + port + "/fb-management/v1/p2p/lists/availableListNames", String[].class);
Assert.assertEquals(6, names.length);
assertEquals(6, names.length);
}
private Row createRow(ListType listType) {
@ -152,7 +144,7 @@ public class P2pWbListApplicationTest extends AbstractKafkaIntegrationTest {
@Test
@WithMockUser("customUsername")
public void executeTest() {
void insertInBlackList() {
doNothing().when(wbListDao).saveListRecord(any());
P2pListRecord record = new P2pListRecord();
@ -162,33 +154,13 @@ public class P2pWbListApplicationTest extends AbstractKafkaIntegrationTest {
insertToBlackList(record);
try (Consumer<String, ChangeCommand> consumer = createConsumer(CommandChangeDeserializer.class)) {
consumer.subscribe(Collections.singletonList(topicCommand));
List<ChangeCommand> eventList = consumeCommand(consumer);
List<ChangeCommand> eventList = new ArrayList<>();
testCommandKafkaConsumer.read(topicCommand, data -> eventList.add(data.value()));
Unreliables.retryUntilTrue(TIMEOUT, TimeUnit.SECONDS, () -> eventList.size() == 1);
Assert.assertEquals(1, eventList.size());
Assert.assertEquals(eventList.get(0).command, Command.CREATE);
Assert.assertEquals(eventList.get(0).getRow().getListType(), ListType.black);
}
String test = "test";
when(wbListDao.getById(test)).thenReturn(new P2pWbListRecords("id",
"identity",
com.rbkmoney.fraudbusters.management.domain.enums.ListType.white,
"test",
"test",
"test",
LocalDateTime.now()));
deleteFromWhiteList(test);
try (Consumer<String, ChangeCommand> consumer = createConsumer(CommandChangeDeserializer.class)) {
consumer.subscribe(Collections.singletonList(topicCommand));
List<ChangeCommand> eventList = consumeCommand(consumer);
Assert.assertEquals(1, eventList.size());
Assert.assertEquals(Command.DELETE, eventList.get(0).command);
Assert.assertEquals(ListType.white, eventList.get(0).getRow().getListType());
}
assertEquals(1, eventList.size());
assertEquals(Command.CREATE, eventList.get(0).command);
assertEquals(ListType.black, eventList.get(0).getRow().getListType());
}
private void insertToBlackList(P2pListRecord... values) {
@ -210,19 +182,30 @@ public class P2pWbListApplicationTest extends AbstractKafkaIntegrationTest {
System.out.println(response);
}
@Test
@WithMockUser("customUsername")
void deleteFromWhiteList() {
String test = "test";
when(wbListDao.getById(test)).thenReturn(new P2pWbListRecords("id",
"identity",
com.rbkmoney.fraudbusters.management.domain.enums.ListType.white,
"test",
"test",
"test",
LocalDateTime.now()));
deleteFromWhiteList(test);
List<ChangeCommand> eventList2 = new ArrayList<>();
testCommandKafkaConsumer.read(topicCommand, data -> eventList2.add(data.value()));
Unreliables.retryUntilTrue(TIMEOUT, TimeUnit.SECONDS, () -> eventList2.size() == 1);
assertEquals(1, eventList2.size());
assertEquals(Command.DELETE, eventList2.get(0).command);
assertEquals(ListType.white, eventList2.get(0).getRow().getListType());
}
private void deleteFromWhiteList(String id) {
restTemplate.delete("http://localhost:" + port + "/fb-management/v1/p2p/lists/" + id);
}
private List<ChangeCommand> consumeCommand(Consumer<String, ChangeCommand> consumer) {
List<ChangeCommand> eventList = new ArrayList<>();
ConsumerRecords<String, ChangeCommand> consumerRecords =
consumer.poll(Duration.ofSeconds(10));
consumerRecords.forEach(command -> {
log.info("poll command: {}", command.value());
eventList.add(command.value());
});
consumer.close();
return eventList;
}
}

View File

@ -4,6 +4,7 @@ import com.rbkmoney.damsel.fraudbusters.MerchantInfo;
import com.rbkmoney.damsel.fraudbusters.PaymentServiceSrv;
import com.rbkmoney.damsel.fraudbusters.ReferenceInfo;
import com.rbkmoney.damsel.fraudbusters.ValidateTemplateResponse;
import com.rbkmoney.fraudbusters.management.config.KafkaITest;
import com.rbkmoney.fraudbusters.management.dao.payment.DefaultPaymentReferenceDaoImpl;
import com.rbkmoney.fraudbusters.management.dao.payment.group.PaymentGroupDao;
import com.rbkmoney.fraudbusters.management.dao.payment.group.PaymentGroupReferenceDao;
@ -21,8 +22,7 @@ import com.rbkmoney.fraudbusters.management.resource.payment.PaymentsReferenceRe
import com.rbkmoney.fraudbusters.management.resource.payment.PaymentsTemplatesResource;
import com.rbkmoney.fraudbusters.management.service.iface.AuditService;
import com.rbkmoney.swag.fraudbusters.management.model.*;
import com.rbkmoney.testcontainers.annotations.KafkaSpringBootTest;
import com.rbkmoney.testcontainers.annotations.kafka.KafkaTestcontainerSingleton;
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaProducer;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;
@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -48,12 +49,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@KafkaTestcontainerSingleton(topicsKeys = {
"kafka.topic.fraudbusters.unknown-initiating-entity"
})
@KafkaITest
@Slf4j
@EnableAutoConfiguration(exclude = {FlywayAutoConfiguration.class, JooqAutoConfiguration.class})
@KafkaSpringBootTest
@SpringBootTest
public class TemplateApplicationTest {
public static final String PARTY_ID = "party_id";
@ -94,7 +93,7 @@ public class TemplateApplicationTest {
PaymentGroupsResource paymentGroupsResource;
@Autowired
private com.rbkmoney.testcontainers.annotations.kafka.config.KafkaProducer<TBase<?, ?>> testThriftKafkaProducer;
private KafkaProducer<TBase<?, ?>> testThriftKafkaProducer;
@Test
void templateTest() throws TException {

View File

@ -1,24 +1,26 @@
package com.rbkmoney.fraudbusters.management;
import com.rbkmoney.damsel.wb_list.*;
import com.rbkmoney.fraudbusters.management.config.KafkaITest;
import com.rbkmoney.fraudbusters.management.dao.payment.wblist.WbListDao;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentCountInfo;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentListRecord;
import com.rbkmoney.fraudbusters.management.domain.payment.request.ListRowsInsertRequest;
import com.rbkmoney.fraudbusters.management.domain.tables.pojos.WbListRecords;
import com.rbkmoney.fraudbusters.management.serializer.CommandChangeDeserializer;
import com.rbkmoney.fraudbusters.management.service.iface.AuditService;
import com.rbkmoney.fraudbusters.management.utils.MethodPaths;
import com.rbkmoney.swag.fraudbusters.management.model.ListResponse;
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaConsumer;
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaProducer;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.thrift.TBase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
@ -30,28 +32,26 @@ import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.testcontainers.shaded.com.trilead.ssh2.ChannelCondition.TIMEOUT;
@KafkaITest
@Slf4j
@RunWith(SpringRunner.class)
@EnableAutoConfiguration(exclude = {FlywayAutoConfiguration.class, JooqAutoConfiguration.class})
@SpringBootTest(
classes = FraudbustersManagementApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WbListApplicationTest extends AbstractKafkaIntegrationTest {
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WbListApplicationTest {
public static final String BASE_URL = "http://localhost:";
private static final String VALUE = "value";
@ -71,33 +71,37 @@ public class WbListApplicationTest extends AbstractKafkaIntegrationTest {
@LocalServerPort
private int port;
@Before
public void init() {
@Autowired
private KafkaProducer<TBase<?, ?>> testThriftKafkaProducer;
@Autowired
private KafkaConsumer<ChangeCommand> testCommandKafkaConsumer;
@BeforeEach
void init() {
paymentListPath = String.format(MethodPaths.SERVICE_BASE_URL + MethodPaths.INSERT_PAYMENTS_LIST_ROW_PATH,
port);
}
@Test
public void listenCreated() throws ExecutionException, InterruptedException {
void listenCreated() {
Mockito.clearInvocations(wbListDao);
Event event = new Event();
Row row = createRow(ListType.black);
event.setRow(row);
event.setEventType(EventType.CREATED);
try (Producer<String, Event> producer = createProducer()) {
ProducerRecord<String, Event> producerRecord = new ProducerRecord<>(topicEventSink, "test", event);
producer.send(producerRecord).get();
producer.send(new ProducerRecord<>(topicEventSink, "test_1", event)).get();
producer.send(new ProducerRecord<>(topicEventSink, "test_2", event)).get();
}
testThriftKafkaProducer.send(topicEventSink, event);
testThriftKafkaProducer.send(topicEventSink, event);
testThriftKafkaProducer.send(topicEventSink, event);
await().untilAsserted(() -> {
Mockito.verify(wbListDao, Mockito.times(3)).saveListRecord(any());
});
}
@Test
public void listenCreatedGrey() throws ExecutionException, InterruptedException {
void listenCreatedGrey() {
Mockito.clearInvocations(wbListDao);
Event event = new Event();
@ -112,33 +116,27 @@ public class WbListApplicationTest extends AbstractKafkaIntegrationTest {
event.setRow(row);
try (Producer<String, Event> producer = createProducer()) {
ProducerRecord<String, Event> producerRecord = new ProducerRecord<>(topicEventSink, "test", event);
producer.send(producerRecord).get();
producer.send(new ProducerRecord<>(topicEventSink, "test_1", event)).get();
producer.send(new ProducerRecord<>(topicEventSink, "test_2", event)).get();
}
testThriftKafkaProducer.send(topicEventSink, event);
testThriftKafkaProducer.send(topicEventSink, event);
testThriftKafkaProducer.send(topicEventSink, event);
await().untilAsserted(() -> {
Mockito.verify(wbListDao, Mockito.times(3)).saveListRecord(any());
Mockito.verify(wbListDao, Mockito.times(3)).saveListRecord(any(WbListRecords.class));
});
}
@Test
public void listenDeleted() throws ExecutionException, InterruptedException {
void listenDeleted() {
Event event = new Event();
Row row = createRow(ListType.black);
event.setRow(row);
event.setEventType(EventType.DELETED);
try (Producer<String, Event> producer = createProducer()) {
ProducerRecord<String, Event> producerRecord = new ProducerRecord<>(topicEventSink, "test", event);
producer.send(producerRecord).get();
producer.close();
testThriftKafkaProducer.send(topicEventSink, event);
await().untilAsserted(() -> {
Mockito.verify(wbListDao, Mockito.times(1)).removeRecord(any(WbListRecords.class));
});
await().untilAsserted(() -> {
Mockito.verify(wbListDao, Mockito.times(1)).removeRecord((WbListRecords) any());
});
}
}
private Row createRow(ListType listType) {
@ -152,7 +150,7 @@ public class WbListApplicationTest extends AbstractKafkaIntegrationTest {
}
@Test
public void executeTest() {
void insertToBlackList() {
Mockito.doNothing().when(wbListDao).saveListRecord(any());
PaymentListRecord record = new PaymentListRecord();
@ -169,14 +167,17 @@ public class WbListApplicationTest extends AbstractKafkaIntegrationTest {
insertToBlackList(record, recordSecond);
try (Consumer<String, ChangeCommand> consumer = createConsumer(CommandChangeDeserializer.class)) {
consumer.subscribe(Collections.singletonList(topicCommand));
List<ChangeCommand> eventList = consumeCommand(consumer);
assertEquals(2, eventList.size());
assertEquals(eventList.get(0).command, Command.CREATE);
assertEquals(eventList.get(0).getRow().getListType(), ListType.black);
}
List<ChangeCommand> eventList = new ArrayList<>();
testCommandKafkaConsumer.read(topicCommand, data -> eventList.add(data.value()));
Unreliables.retryUntilTrue(TIMEOUT, TimeUnit.SECONDS, () -> eventList.size() == 2);
assertEquals(2, eventList.size());
assertEquals(eventList.get(0).command, Command.CREATE);
assertEquals(eventList.get(0).getRow().getListType(), ListType.black);
}
@Test
void deleteFromWhiteList() {
String test = "test";
when(wbListDao.getById(test)).thenReturn(new WbListRecords("id",
"partyId",
@ -187,30 +188,33 @@ public class WbListApplicationTest extends AbstractKafkaIntegrationTest {
LocalDateTime.now(), null, null, LocalDateTime.now()));
deleteFromWhiteList(test);
try (Consumer<String, ChangeCommand> consumer = createConsumer(CommandChangeDeserializer.class)) {
consumer.subscribe(Collections.singletonList(topicCommand));
List<ChangeCommand> eventList = consumeCommand(consumer);
assertEquals(1, eventList.size());
assertEquals(eventList.get(0).command, Command.DELETE);
assertEquals(eventList.get(0).getRow().getListType(), ListType.white);
}
List<ChangeCommand> eventList2 = new ArrayList<>();
testCommandKafkaConsumer.read(topicCommand, data -> eventList2.add(data.value()));
Unreliables.retryUntilTrue(TIMEOUT, TimeUnit.SECONDS, () -> eventList2.size() == 1);
assertEquals(1, eventList2.size());
assertEquals(eventList2.get(0).command, Command.DELETE);
assertEquals(eventList2.get(0).getRow().getListType(), ListType.white);
}
@Test
void createListRow() {
String value = VALUE + 66;
HttpEntity<ListRowsInsertRequest> entity =
new HttpEntity<>(createListRowsInsertRequest(value), new org.springframework.http.HttpHeaders());
restTemplate.exchange(paymentListPath, HttpMethod.POST, entity, String.class);
try (Consumer<String, ChangeCommand> consumer = createConsumer(CommandChangeDeserializer.class)) {
consumer.subscribe(Collections.singletonList(topicCommand));
List<ChangeCommand> eventList = consumeCommand(consumer);
List<ChangeCommand> eventList3 = new ArrayList<>();
testCommandKafkaConsumer.read(topicCommand, data -> eventList3.add(data.value()));
Unreliables.retryUntilTrue(TIMEOUT, TimeUnit.SECONDS, () -> eventList3.size() == 1);
assertEquals(1, eventList.size());
assertEquals(eventList.get(0).command, Command.CREATE);
assertEquals(eventList.get(0).getRow().getListType(), ListType.black);
assertEquals(value, eventList.get(0).getRow().getValue());
log.info("{}", eventList.get(0).getRow());
}
assertEquals(1, eventList3.size());
assertEquals(eventList3.get(0).command, Command.CREATE);
assertEquals(eventList3.get(0).getRow().getListType(), ListType.black);
assertEquals(value, eventList3.get(0).getRow().getValue());
log.info("{}", eventList3.get(0).getRow());
String paymentListNames = String.format(MethodPaths.SERVICE_BASE_URL + MethodPaths.LISTS_NAMES_LIST_TYPE_PATH,

View File

@ -0,0 +1,20 @@
package com.rbkmoney.fraudbusters.management.config;
import com.rbkmoney.damsel.wb_list.ChangeCommand;
import com.rbkmoney.fraudbusters.management.serializer.CommandChangeDeserializer;
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaConsumer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ConsumerConfig {
@Value("${kafka.bootstrap-servers}")
private String bootstrapServers;
@Bean
public KafkaConsumer<ChangeCommand> testChangeCommandKafkaConsumer() {
return new KafkaConsumer<>(bootstrapServers, new CommandChangeDeserializer());
}
}

View File

@ -0,0 +1,37 @@
package com.rbkmoney.fraudbusters.management.config;
import com.rbkmoney.fraudbusters.management.FraudbustersManagementApplication;
import com.rbkmoney.testcontainers.annotations.kafka.KafkaTestcontainerSingleton;
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaConsumerConfig;
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaProducerConfig;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@KafkaTestcontainerSingleton(topicsKeys = {
"kafka.topic.fraudbusters.unknown-initiating-entity",
"kafka.topic.wblist.command",
"kafka.topic.wblist.event.sink",
"kafka.topic.fraudbusters.payment.template",
"kafka.topic.fraudbusters.payment.reference",
"kafka.topic.fraudbusters.payment.group.list",
"kafka.topic.fraudbusters.payment.group.reference",
"kafka.topic.fraudbusters.p2p.template",
"kafka.topic.fraudbusters.p2p.reference",
"kafka.topic.fraudbusters.p2p.group.list",
"kafka.topic.fraudbusters.p2p.group.reference"
})
@ContextConfiguration(
classes = {
FraudbustersManagementApplication.class,
KafkaProducerConfig.class,
KafkaConsumerConfig.class})
@DirtiesContext
public @interface KafkaITest {
}

View File

@ -0,0 +1,16 @@
package com.rbkmoney.fraudbusters.management.config;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainer;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@PostgresqlTestcontainer
@JooqTest
public @interface PostgresqlJooqITest {
}

View File

@ -1,18 +1,18 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.time.LocalDateTime;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {CheckedDataSetModelToCheckedDataSetApiConverter.class,
CheckedPaymentModelToCheckedDataSetRowConverter.class,
PaymentModelToPaymentApiConverter.class})
@ -26,7 +26,7 @@ public class TestCheckedDataSetModelToCheckedDataSetApiConverterTest {
CheckedDataSetModelToCheckedDataSetApiConverter checkedDataSetModelToCheckedDataSetApiConverter;
@Test
public void testConvert() {
void testConvert() {
CheckedDataSetModel testDataSetModel = CheckedDataSetModel.builder()
.initiator(TEST)
.testDataSetId(1L)

View File

@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
class TestHistoricalDataSetCheckResultToTestCheckedDataSetModelConverter {

View File

@ -1,43 +1,10 @@
package com.rbkmoney.fraudbusters.management.dao;
import org.junit.ClassRule;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.testcontainers.containers.PostgreSQLContainer;
import java.time.Duration;
@RunWith(SpringRunner.class)
@EnableConfigurationProperties({DataSourceProperties.class})
@ContextConfiguration(classes = {DataSourceAutoConfiguration.class, JdbcTemplateAutoConfiguration.class},
initializers = AbstractPostgresIntegrationTest.Initializer.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@PostgresqlTestcontainerSingleton
@JooqTest
public abstract class AbstractPostgresIntegrationTest {
@ClassRule
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer("postgres:9.6")
.withStartupTimeout(Duration.ofMinutes(5));
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of(
"spring.datasource.url=" + postgres.getJdbcUrl(),
"spring.datasource.username=" + postgres.getUsername(),
"spring.datasource.password=" + postgres.getPassword()
).applyTo(configurableApplicationContext);
}
}
}

View File

@ -1,12 +1,12 @@
package com.rbkmoney.fraudbusters.management.dao.audit;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.domain.enums.CommandType;
import com.rbkmoney.fraudbusters.management.domain.enums.ObjectType;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.fraudbusters.management.domain.tables.pojos.CommandAudit;
import org.jooq.SortOrder;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@ -15,18 +15,20 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
@PostgresqlJooqITest
@ContextConfiguration(classes = {CommandAuditDaoImpl.class})
public class CommandAuditDaoImplTest extends AbstractPostgresIntegrationTest {
public class CommandAuditDaoImplTest {
public static final String INITIATOR = "initiator";
public static final String STRUGA = "struga";
@Autowired
CommandAuditDao commandAuditDao;
@Test
public void insert() {
void insert() {
CommandAudit log = new CommandAudit();
log.setInitiator(INITIATOR);
log.setObject("{test}");

View File

@ -1,23 +1,22 @@
package com.rbkmoney.fraudbusters.management.dao.group;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.dao.payment.group.GroupReferenceDaoImpl;
import com.rbkmoney.fraudbusters.management.dao.payment.group.PaymentGroupReferenceDao;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentGroupReferenceModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import org.jooq.SortOrder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.*;
@PostgresqlJooqITest
@ContextConfiguration(classes = {GroupReferenceDaoImpl.class})
public class GroupReferenceDaoImplTest extends AbstractPostgresIntegrationTest {
public class GroupReferenceDaoImplTest {
public static final String PARTY_ID = "partyId";
public static final String SHOP_ID = "shopId";
@ -26,7 +25,7 @@ public class GroupReferenceDaoImplTest extends AbstractPostgresIntegrationTest {
PaymentGroupReferenceDao groupReferenceDao;
@Test
public void insert() {
void insert() {
PaymentGroupReferenceModel referenceModel = new PaymentGroupReferenceModel();
referenceModel.setPartyId(PARTY_ID);
referenceModel.setShopId(SHOP_ID);
@ -39,7 +38,7 @@ public class GroupReferenceDaoImplTest extends AbstractPostgresIntegrationTest {
groupReferenceDao.remove(referenceModel);
byId = groupReferenceDao.getByGroupId(GROUP_ID);
Assert.assertTrue(byId.isEmpty());
assertTrue(byId.isEmpty());
groupReferenceDao.insert(referenceModel);

View File

@ -1,12 +1,12 @@
package com.rbkmoney.fraudbusters.management.dao.group;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.dao.GroupDao;
import com.rbkmoney.fraudbusters.management.dao.payment.group.PaymentGroupDao;
import com.rbkmoney.fraudbusters.management.domain.GroupModel;
import com.rbkmoney.fraudbusters.management.domain.PriorityIdModel;
import com.rbkmoney.fraudbusters.management.utils.GroupRowToModelMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@ -14,10 +14,11 @@ import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
@PostgresqlJooqITest
@ContextConfiguration(classes = {PaymentGroupDao.class, GroupRowToModelMapper.class})
public class PaymentGroupDaoTest extends AbstractPostgresIntegrationTest {
public class PaymentGroupDaoTest {
public static final String GROUP_1 = "group_1";
public static final String GROUP_2 = "group_2";
@ -60,7 +61,7 @@ public class PaymentGroupDaoTest extends AbstractPostgresIntegrationTest {
}
@Test
public void update() {
void update() {
GroupModel groupModel = new GroupModel();
groupModel.setGroupId(UPDATE_GROUP);
groupModel.setPriorityTemplates(List.of(

View File

@ -1,18 +1,21 @@
package com.rbkmoney.fraudbusters.management.dao.p2p;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.dao.p2p.group.P2pGroupReferenceDao;
import com.rbkmoney.fraudbusters.management.dao.p2p.group.P2pGroupReferenceDaoImpl;
import com.rbkmoney.fraudbusters.management.domain.p2p.P2pGroupReferenceModel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@PostgresqlJooqITest
@ContextConfiguration(classes = {P2pGroupReferenceDaoImpl.class})
public class P2pGroupReferenceDaoImplTest extends AbstractPostgresIntegrationTest {
public class P2pGroupReferenceDaoImplTest {
public static final String GROUP_ID = "groupId";
public static final String IDENTITY_ID = "identity_id";
@ -22,19 +25,17 @@ public class P2pGroupReferenceDaoImplTest extends AbstractPostgresIntegrationTes
@Test
public void insert() {
String id = "id";
P2pGroupReferenceModel referenceModel = new P2pGroupReferenceModel();
referenceModel.setIdentityId(IDENTITY_ID);
referenceModel.setGroupId(GROUP_ID);
groupReferenceDao.insert(referenceModel);
List<P2pGroupReferenceModel> byId = groupReferenceDao.getByGroupId(GROUP_ID);
Assert.assertEquals(IDENTITY_ID, byId.get(0).getIdentityId());
assertEquals(IDENTITY_ID, byId.get(0).getIdentityId());
groupReferenceDao.remove(referenceModel);
byId = groupReferenceDao.getByGroupId(GROUP_ID);
Assert.assertTrue(byId.isEmpty());
assertTrue(byId.isEmpty());
}
}

View File

@ -1,27 +1,26 @@
package com.rbkmoney.fraudbusters.management.dao.p2p;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.dao.p2p.reference.P2pReferenceDao;
import com.rbkmoney.fraudbusters.management.dao.p2p.reference.P2pReferenceDaoImpl;
import com.rbkmoney.fraudbusters.management.domain.p2p.P2pReferenceModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import org.jooq.DSLContext;
import org.jooq.SortOrder;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import java.util.List;
import java.util.UUID;
import static com.rbkmoney.fraudbusters.management.domain.tables.P2pFReference.P2P_F_REFERENCE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.*;
@PostgresqlJooqITest
@ContextConfiguration(classes = {P2pReferenceDaoImpl.class})
public class P2pReferenceDaoImplTest extends AbstractPostgresIntegrationTest {
public class P2pReferenceDaoImplTest {
public static final String IDENTITY_ID = "identity_id";
public static final String SECOND = "second_";
@ -32,27 +31,27 @@ public class P2pReferenceDaoImplTest extends AbstractPostgresIntegrationTest {
P2pReferenceDao p2pReferenceDao;
@Autowired
private JdbcTemplate jdbcTemplate;
private DSLContext dslContext;
@After
public void cleanup() {
jdbcTemplate.execute("TRUNCATE " + P2P_F_REFERENCE.getSchema().getName() + "." + P2P_F_REFERENCE.getName());
@AfterEach
void cleanup() {
dslContext.deleteFrom(P2P_F_REFERENCE).execute();
}
@Test
public void insert() {
void insert() {
String id = "id";
P2pReferenceModel referenceModel = createReference(id);
p2pReferenceDao.insert(referenceModel);
P2pReferenceModel byId = p2pReferenceDao.getById(id);
Assert.assertEquals(referenceModel.getId(), byId.getId());
assertEquals(referenceModel.getId(), byId.getId());
p2pReferenceDao.remove(referenceModel);
byId = p2pReferenceDao.getById(id);
Assert.assertNull(byId);
assertNull(byId);
}
private P2pReferenceModel createReference(String id) {
@ -65,7 +64,7 @@ public class P2pReferenceDaoImplTest extends AbstractPostgresIntegrationTest {
}
@Test
public void constraintTest() {
void constraintTest() {
String id = "id";
P2pReferenceModel referenceModel = createReference(id);
@ -76,7 +75,7 @@ public class P2pReferenceDaoImplTest extends AbstractPostgresIntegrationTest {
p2pReferenceDao.insert(referenceModel);
P2pReferenceModel byId = p2pReferenceDao.getById(id);
Assert.assertEquals(byId.getTemplateId(), test);
assertEquals(byId.getTemplateId(), test);
String firstGlobal = UUID.randomUUID().toString();
referenceModel.setId(firstGlobal);
@ -91,22 +90,22 @@ public class P2pReferenceDaoImplTest extends AbstractPostgresIntegrationTest {
p2pReferenceDao.insert(referenceModel);
byId = p2pReferenceDao.getById(globalId);
Assert.assertEquals(byId.getTemplateId(), global);
assertEquals(byId.getTemplateId(), global);
byId = p2pReferenceDao.getById(firstGlobal);
Assert.assertNull(byId);
assertNull(byId);
List<P2pReferenceModel> listByTFilters = p2pReferenceDao.getListByTFilters(IDENTITY_ID, null, 10);
Assert.assertEquals(2, listByTFilters.size());
assertEquals(2, listByTFilters.size());
listByTFilters = p2pReferenceDao.getListByTFilters(null, true, 10);
Assert.assertEquals(1, listByTFilters.size());
assertEquals(1, listByTFilters.size());
}
@Test
public void filterTest() {
void filterTest() {
String id = "filter_id";
P2pReferenceModel referenceModel = createReference(id);
p2pReferenceDao.insert(referenceModel);

View File

@ -1,40 +1,37 @@
package com.rbkmoney.fraudbusters.management.dao.p2p;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.dao.TemplateDao;
import com.rbkmoney.fraudbusters.management.dao.p2p.template.P2pTemplateDao;
import com.rbkmoney.fraudbusters.management.domain.TemplateModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import lombok.extern.slf4j.Slf4j;
import org.jooq.SortOrder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.*;
@Slf4j
@PostgresqlJooqITest
@ContextConfiguration(classes = {P2pTemplateDao.class})
public class P2pTemplateDaoTest extends AbstractPostgresIntegrationTest {
public class P2pTemplateDaoTest {
@Autowired
TemplateDao templateDao;
@Test
public void insertTest() {
void insertTest() {
String id = "id";
TemplateModel templateModel = createTemplateModel(id);
templateDao.insert(templateModel);
TemplateModel byId = templateDao.getById(id);
Assert.assertEquals(templateModel.getId(), byId.getId());
assertEquals(templateModel.getId(), byId.getId());
templateDao.remove(id);
byId = templateDao.getById(id);
Assert.assertNull(byId);
assertNull(byId);
}
private TemplateModel createTemplateModel(String id) {
@ -68,16 +65,16 @@ public class P2pTemplateDaoTest extends AbstractPostgresIntegrationTest {
TemplateModel templateModel = createTemplateModel(dedId);
templateDao.insert(templateModel);
TemplateModel byId = templateDao.getById(dedId);
Assert.assertEquals(templateModel.getId(), byId.getId());
assertEquals(templateModel.getId(), byId.getId());
templateModel.setTemplate("rule:blackList_1:inBlackList");
templateDao.insert(templateModel);
byId = templateDao.getById(dedId);
Assert.assertEquals(templateModel.getId(), byId.getId());
assertEquals(templateModel.getId(), byId.getId());
templateDao.remove(dedId);
byId = templateDao.getById(dedId);
Assert.assertNull(byId);
assertNull(byId);
}
@Test
@ -95,7 +92,6 @@ public class P2pTemplateDaoTest extends AbstractPostgresIntegrationTest {
1,
null,
SortOrder.DESC));
log.info("list: {}", list);
assertEquals(1, list.size());
TemplateModel templateModel1 = list.get(0);
@ -106,7 +102,6 @@ public class P2pTemplateDaoTest extends AbstractPostgresIntegrationTest {
1,
null,
SortOrder.DESC));
log.info("list: {}", list);
assertEquals(1, list.size());
assertNotEquals(templateModel1.getId(), list.get(0).getId());
@ -119,7 +114,6 @@ public class P2pTemplateDaoTest extends AbstractPostgresIntegrationTest {
2,
null,
SortOrder.DESC));
log.info("list: {}", list);
assertEquals(2, list.size());
//filter and pagination by id
@ -130,7 +124,6 @@ public class P2pTemplateDaoTest extends AbstractPostgresIntegrationTest {
1,
null,
SortOrder.DESC));
log.info("list: {}", list);
assertEquals(1, list.size());
String id = list.get(0).getId();
@ -141,7 +134,6 @@ public class P2pTemplateDaoTest extends AbstractPostgresIntegrationTest {
1,
null,
SortOrder.DESC));
log.info("list: {}", list);
assertEquals(1, list.size());
assertNotEquals(id, list.get(0).getId());

View File

@ -1,11 +1,10 @@
package com.rbkmoney.fraudbusters.management.dao.payment;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.domain.payment.DefaultPaymentReferenceModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.util.CollectionUtils;
@ -15,8 +14,7 @@ import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*;
@JooqTest
@PostgresqlTestcontainerSingleton
@PostgresqlJooqITest
@ContextConfiguration(classes = {DefaultPaymentReferenceDaoImpl.class})
public class DefaultPaymentReferenceDaoImplTest {

View File

@ -1,14 +1,13 @@
package com.rbkmoney.fraudbusters.management.dao.payment;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.dao.payment.group.GroupReferenceDaoImpl;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentGroupReferenceModel;
import com.rbkmoney.fraudbusters.management.domain.tables.records.FGroupReferenceRecord;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import org.jooq.DSLContext;
import org.jooq.Result;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.test.context.ContextConfiguration;
import java.util.List;
@ -17,8 +16,7 @@ import static com.rbkmoney.fraudbusters.management.domain.tables.FGroupReference
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@JooqTest
@PostgresqlTestcontainerSingleton
@PostgresqlJooqITest
@ContextConfiguration(classes = {GroupReferenceDaoImpl.class})
public class PaymentGroupReferenceDaoImplTest {
@ -55,8 +53,8 @@ public class PaymentGroupReferenceDaoImplTest {
groupReferenceDao.insert(referenceModel);
FGroupReferenceRecord fGroupReferenceRecord = dslContext.fetchAny(F_GROUP_REFERENCE);
assertEquals(PARTY_ID, fGroupReferenceRecord.getPartyId());
FGroupReferenceRecord groupReferenceRecord = dslContext.fetchAny(F_GROUP_REFERENCE);
assertEquals(PARTY_ID, groupReferenceRecord.getPartyId());
;
}

View File

@ -1,23 +1,21 @@
package com.rbkmoney.fraudbusters.management.dao.payment;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.dao.TemplateDao;
import com.rbkmoney.fraudbusters.management.dao.payment.template.PaymentTemplateDao;
import com.rbkmoney.fraudbusters.management.domain.TemplateModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import lombok.extern.slf4j.Slf4j;
import org.jooq.SortOrder;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.test.context.ContextConfiguration;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@JooqTest
@PostgresqlTestcontainerSingleton
@PostgresqlJooqITest
@Slf4j
@ContextConfiguration(classes = {PaymentTemplateDao.class})
public class PaymentTemplateDaoTest {

View File

@ -1,18 +1,17 @@
package com.rbkmoney.fraudbusters.management.dao.payment;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.dao.payment.reference.PaymentReferenceDao;
import com.rbkmoney.fraudbusters.management.dao.payment.reference.PaymentReferenceDaoImpl;
import com.rbkmoney.fraudbusters.management.domain.ReferenceModel;
import com.rbkmoney.fraudbusters.management.domain.payment.DefaultPaymentReferenceModel;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentReferenceModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import org.jooq.DSLContext;
import org.jooq.SortOrder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.test.context.ContextConfiguration;
import java.io.IOException;
@ -23,8 +22,7 @@ import java.util.UUID;
import static com.rbkmoney.fraudbusters.management.domain.tables.FReference.F_REFERENCE;
import static org.junit.jupiter.api.Assertions.*;
@JooqTest
@PostgresqlTestcontainerSingleton
@PostgresqlJooqITest
@ContextConfiguration(classes = {PaymentReferenceDaoImpl.class, DefaultPaymentReferenceDaoImpl.class})
public class ReferenceDaoImplTest {

View File

@ -1,13 +1,12 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedPaymentModel;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.test.context.ContextConfiguration;
import java.time.LocalDateTime;
@ -16,8 +15,7 @@ import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;
@JooqTest
@PostgresqlTestcontainerSingleton
@PostgresqlJooqITest
@ContextConfiguration(classes = {DataSetCheckingResultDaoImpl.class, DataSetDaoImpl.class,
PaymentDaoImpl.class})
public class TestDataSetCheckingResultDaoImpl {

View File

@ -1,5 +1,6 @@
package com.rbkmoney.fraudbusters.management.dao.payment.wblist;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.converter.ListRecordToRowConverterImpl;
import com.rbkmoney.fraudbusters.management.converter.p2p.P2pCountInfoListRequestToRowConverter;
import com.rbkmoney.fraudbusters.management.converter.p2p.P2pListRecordToRowConverter;
@ -11,11 +12,9 @@ import com.rbkmoney.fraudbusters.management.domain.p2p.P2pCountInfo;
import com.rbkmoney.fraudbusters.management.domain.tables.pojos.P2pWbListRecords;
import com.rbkmoney.fraudbusters.management.utils.CountInfoUtils;
import com.rbkmoney.fraudbusters.management.utils.P2pCountInfoGenerator;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.test.context.ContextConfiguration;
import java.time.LocalDateTime;
@ -23,8 +22,7 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@JooqTest
@PostgresqlTestcontainerSingleton
@PostgresqlJooqITest
@ContextConfiguration(classes = {P2PWbListDaoImpl.class, P2pWbListRecordsToListRecordWithRowConverter.class,
P2pListRecordToRowConverter.class, P2pCountInfoListRequestToRowConverter.class,
ListRecordToRowConverterImpl.class,

View File

@ -1,5 +1,6 @@
package com.rbkmoney.fraudbusters.management.dao.payment.wblist;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.converter.ListRecordToRowConverterImpl;
import com.rbkmoney.fraudbusters.management.converter.payment.PaymentCountInfoRequestToRowConverter;
import com.rbkmoney.fraudbusters.management.converter.payment.PaymentListRecordToRowConverter;
@ -12,14 +13,12 @@ import com.rbkmoney.fraudbusters.management.utils.CountInfoApiUtils;
import com.rbkmoney.fraudbusters.management.utils.CountInfoUtils;
import com.rbkmoney.fraudbusters.management.utils.PaymentCountInfoGenerator;
import com.rbkmoney.swag.fraudbusters.management.model.PaymentCountInfo;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import org.jooq.DSLContext;
import org.jooq.SortOrder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.test.context.ContextConfiguration;
import java.time.LocalDateTime;
@ -31,8 +30,7 @@ import static com.rbkmoney.fraudbusters.management.TestObjectFactory.randomStrin
import static com.rbkmoney.fraudbusters.management.domain.tables.WbListRecords.WB_LIST_RECORDS;
import static org.junit.jupiter.api.Assertions.*;
@JooqTest
@PostgresqlTestcontainerSingleton
@PostgresqlJooqITest
@ContextConfiguration(classes = {WbListDaoImpl.class, WbListRecordsToCountInfoListRequestConverter.class,
PaymentListRecordToRowConverter.class, PaymentCountInfoRequestToRowConverter.class,
ListRecordToRowConverterImpl.class, CountInfoApiUtils.class,

View File

@ -1,7 +1,6 @@
package com.rbkmoney.fraudbusters.management.resource;
import com.rbkmoney.fraudbusters.management.converter.payment.TemplateModelToTemplateConverterImpl;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.dao.GroupDao;
import com.rbkmoney.fraudbusters.management.dao.TemplateDao;
import com.rbkmoney.fraudbusters.management.dao.payment.group.GroupReferenceDaoImpl;
@ -21,9 +20,10 @@ import com.rbkmoney.fraudbusters.management.utils.GroupRowToModelMapper;
import com.rbkmoney.fraudbusters.management.utils.UserInfoService;
import com.rbkmoney.swag.fraudbusters.management.model.EmulateResponse;
import com.rbkmoney.swag.fraudbusters.management.model.Template;
import org.junit.Assert;
import org.junit.Test;
import com.rbkmoney.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
@ -31,10 +31,14 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@JooqTest
@PostgresqlTestcontainerSingleton
@ContextConfiguration(classes = {PaymentEmulateResource.class, PaymentGroupDao.class, PaymentTemplateDao.class,
GroupReferenceDaoImpl.class, PaymentReferenceDaoImpl.class, GroupRowToModelMapper.class, UserInfoService.class,
TemplateModelToTemplateConverterImpl.class, PaymentEmulateService.class})
public class PaymentEmulateResourceTest extends AbstractPostgresIntegrationTest {
public class PaymentEmulateResourceTest {
private static final String PARTY_ID = "partyId";
private static final String SHOP_ID = "shopId";
@ -56,7 +60,7 @@ public class PaymentEmulateResourceTest extends AbstractPostgresIntegrationTest
TemplateDao templateDao;
@Test
public void getRulesByPartyAndShop() {
void getRulesByPartyAndShop() {
GroupModel groupModel = new GroupModel();
groupModel.setGroupId(GROUP_ID);
ArrayList<PriorityIdModel> priorityTemplates = new ArrayList<>();
@ -101,17 +105,17 @@ public class PaymentEmulateResourceTest extends AbstractPostgresIntegrationTest
PARTY_ID,
SHOP_ID);
Assert.assertTrue(rulesByPartyAndShop.hasBody());
assertTrue(rulesByPartyAndShop.hasBody());
EmulateResponse emulateResponse = rulesByPartyAndShop.getBody();
List<Template> templateModels = emulateResponse.getResult();
Assert.assertFalse(templateModels.isEmpty());
Assert.assertEquals(5, templateModels.size());
assertFalse(templateModels.isEmpty());
assertEquals(5, templateModels.size());
Assert.assertEquals(GLOBAL_TEMPLATE, templateModels.get(0).getId());
Assert.assertEquals(TEMPLATE_2, templateModels.get(1).getId());
Assert.assertEquals(TEMPLATE_1, templateModels.get(2).getId());
Assert.assertEquals(TEMPLATE_3, templateModels.get(3).getId());
Assert.assertEquals(TEMPLATE_1, templateModels.get(4).getId());
assertEquals(GLOBAL_TEMPLATE, templateModels.get(0).getId());
assertEquals(TEMPLATE_2, templateModels.get(1).getId());
assertEquals(TEMPLATE_1, templateModels.get(2).getId());
assertEquals(TEMPLATE_3, templateModels.get(3).getId());
assertEquals(TEMPLATE_1, templateModels.get(4).getId());
referenceDao.remove(referenceModel1);
@ -119,15 +123,15 @@ public class PaymentEmulateResourceTest extends AbstractPostgresIntegrationTest
PARTY_ID,
SHOP_ID);
emulateResponse = rulesByPartyAndShop.getBody();
Assert.assertTrue(rulesByPartyAndShop.hasBody());
assertTrue(rulesByPartyAndShop.hasBody());
templateModels = emulateResponse.getResult();
Assert.assertFalse(templateModels.isEmpty());
Assert.assertEquals(4, templateModels.size());
assertFalse(templateModels.isEmpty());
assertEquals(4, templateModels.size());
Assert.assertEquals(GLOBAL_TEMPLATE, templateModels.get(0).getId());
Assert.assertEquals(TEMPLATE_2, templateModels.get(1).getId());
Assert.assertEquals(TEMPLATE_1, templateModels.get(2).getId());
Assert.assertEquals(TEMPLATE_3, templateModels.get(3).getId());
assertEquals(GLOBAL_TEMPLATE, templateModels.get(0).getId());
assertEquals(TEMPLATE_2, templateModels.get(1).getId());
assertEquals(TEMPLATE_1, templateModels.get(2).getId());
assertEquals(TEMPLATE_3, templateModels.get(3).getId());
}
private void insertTemplate(String template, String id) {

View File

@ -12,14 +12,14 @@ import com.rbkmoney.fraudbusters.management.utils.UserInfoService;
import com.rbkmoney.fraudbusters.management.utils.parser.CsvPaymentCountInfoParser;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.thrift.TException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
@ -28,7 +28,7 @@ import java.io.IOException;
import static org.mockito.ArgumentMatchers.any;
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {PaymentsListsResource.class, CsvPaymentCountInfoParser.class,
WbListRecordsModelToWbListRecordConverter.class, PaymentsListsService.class})
public class PaymentListLoadDataResourceTest {
@ -50,7 +50,7 @@ public class PaymentListLoadDataResourceTest {
PaymentsListsResource paymentsListsResource;
@Test
public void loadFraudOperation() throws IOException, TException {
void loadFraudOperation() throws IOException, TException {
File file = new File("src/test/resources/csv/list-test.csv");
FileInputStream input = new FileInputStream(file);
MultipartFile multipartFile =

View File

@ -6,14 +6,14 @@ import com.rbkmoney.fraudbusters.management.utils.UserInfoService;
import com.rbkmoney.fraudbusters.management.utils.parser.CsvFraudPaymentParser;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.thrift.TException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
@ -22,7 +22,7 @@ import java.io.IOException;
import static org.mockito.ArgumentMatchers.any;
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {PaymentLoadDataResource.class, CsvFraudPaymentParser.class,
UserInfoService.class, PaymentLoadDataService.class})
public class PaymentLoadDataResourceTest {
@ -33,7 +33,7 @@ public class PaymentLoadDataResourceTest {
PaymentServiceSrv.Iface paymentServiceSrv;
@Test
public void loadFraudOperation() throws IOException, TException {
void loadFraudOperation() throws IOException, TException {
File file = new File("src/test/resources/csv/test.csv");
FileInputStream input = new FileInputStream(file);
MultipartFile multipartFile =

View File

@ -1,40 +1,52 @@
package com.rbkmoney.fraudbusters.management.service.payment;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.config.PostgresqlJooqITest;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.DataSetCheckingResultDaoImpl;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.DataSetDaoImpl;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.PaymentDaoImpl;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.fraudbusters.management.domain.tables.records.TestPaymentRecord;
import com.rbkmoney.fraudbusters.management.utils.DateTimeUtils;
import org.junit.Test;
import org.jooq.DSLContext;
import org.jooq.Result;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import java.time.LocalDateTime;
import java.util.List;
import static com.rbkmoney.fraudbusters.management.domain.tables.TestPayment.TEST_PAYMENT;
import static com.rbkmoney.fraudbusters.management.service.payment.DataSetModelUtils.TEST_INITIATOR;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@PostgresqlJooqITest
@ContextConfiguration(classes = {DataSetCheckingResultDaoImpl.class, PaymentsDataSetService.class,
DataSetDaoImpl.class, PaymentDaoImpl.class})
public class PaymentsDataSetServiceTest extends AbstractPostgresIntegrationTest {
public class PaymentsDataSetServiceTest {
@Autowired
PaymentsDataSetService paymentsDataSetService;
@Autowired
DSLContext dslContext;
@Test
@SuppressWarnings("VariableDeclarationUsageDistance")
public void filterDataSets() {
LocalDateTime lastModificationDate = LocalDateTime.now();
DataSetModel dataSetModel = DataSetModelUtils.initTestDataSetModel(lastModificationDate);
dataSetModel.setLastModificationInitiator(TEST_INITIATOR);
Long idFirst = paymentsDataSetService.insertDataSet(dataSetModel);
paymentsDataSetService.insertDataSet(dataSetModel);
dataSetModel.setName(DataSetModelUtils.TEST + "2");
dataSetModel.getPaymentModelList().get(0).setPaymentId(DataSetModelUtils.TEST + "2");
Long idSecond = paymentsDataSetService.insertDataSet(dataSetModel);
paymentsDataSetService.insertDataSet(dataSetModel);
DataSetModel dataSetModel3 = DataSetModelUtils.initTestDataSetModel(lastModificationDate.plusDays(1));
dataSetModel3.setLastModificationInitiator(TEST_INITIATOR);
paymentsDataSetService.insertDataSet(dataSetModel3);
String from = lastModificationDate.minusDays(1L).format(DateTimeUtils.DATE_TIME_FORMATTER);
String to = lastModificationDate.format(DateTimeUtils.DATE_TIME_FORMATTER);
@ -46,30 +58,28 @@ public class PaymentsDataSetServiceTest extends AbstractPostgresIntegrationTest
.build());
assertEquals(2, dataSetModels.size());
paymentsDataSetService.removeDataSet(String.valueOf(idFirst), TEST_INITIATOR);
dataSetModels = paymentsDataSetService.filterDataSets(
from,
to,
FilterRequest.builder()
.size(10)
.build());
assertEquals(1, dataSetModels.size());
paymentsDataSetService.removeDataSet(String.valueOf(idSecond), TEST_INITIATOR);
dataSetModels = paymentsDataSetService.filterDataSets(
from,
to,
FilterRequest.builder()
.size(10)
.build());
assertEquals(0, dataSetModels.size());
}
@Test
public void insertDataSet() {
public void removeDataSets() {
LocalDateTime lastModificationDate = LocalDateTime.now();
DataSetModel dataSetModel = DataSetModelUtils.initTestDataSetModel(lastModificationDate);
dataSetModel.setLastModificationInitiator(TEST_INITIATOR);
Long idFirst = paymentsDataSetService.insertDataSet(dataSetModel);
Result<TestPaymentRecord> dataSetModels = dslContext.fetch(TEST_PAYMENT);
assertEquals(1, dataSetModels.size());
paymentsDataSetService.removeDataSet(String.valueOf(idFirst), TEST_INITIATOR);
dataSetModels = dslContext.fetch(TEST_PAYMENT);
assertTrue(dataSetModels.isEmpty());
}
@Test
void insertDataSet() {
LocalDateTime lastModificationDate = LocalDateTime.now();
Long id = paymentsDataSetService.insertDataSet(DataSetModelUtils.initTestDataSetModel(lastModificationDate));
@ -87,7 +97,6 @@ public class PaymentsDataSetServiceTest extends AbstractPostgresIntegrationTest
});
paymentsDataSetService.removeDataSet(String.valueOf(id), TEST_INITIATOR);
}
}

View File

@ -4,8 +4,7 @@ import com.rbkmoney.damsel.fraudbusters.FraudPayment;
import com.rbkmoney.fraudbusters.management.utils.parser.CsvFraudPaymentParser;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.thrift.TException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
@ -15,22 +14,24 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CsvFraudPaymentParserTest {
CsvFraudPaymentParser csvFraudPaymentParser = new CsvFraudPaymentParser();
@Test
public void hasCsvFormat() throws IOException {
void hasCsvFormat() throws IOException {
File file = new File("src/test/resources/csv/test.csv");
FileInputStream input = new FileInputStream(file);
MultipartFile multipartFile =
new MockMultipartFile("file", file.getName(), "text/csv", IOUtils.toByteArray(input));
Assert.assertTrue(csvFraudPaymentParser.hasCsvFormat(multipartFile));
assertTrue(csvFraudPaymentParser.hasCsvFormat(multipartFile));
}
@Test
public void parse() throws FileNotFoundException {
void parse() throws FileNotFoundException {
File file = new File("src/test/resources/csv/test.csv");
FileInputStream input = new FileInputStream(file);
List<FraudPayment> parse = csvFraudPaymentParser.parse(input);