mirror of
https://github.com/valitydev/fraudbusters-management.git
synced 2024-11-06 08:25:17 +00:00
remove rest template from new kafka test
This commit is contained in:
parent
37f526314e
commit
14e47e8e02
@ -3,6 +3,12 @@ package com.rbkmoney.fraudbusters.management;
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.ChannelType;
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.NotificationStatus;
|
||||
import com.rbkmoney.damsel.wb_list.*;
|
||||
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.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.domain.tables.records.WbListRecordsRecord;
|
||||
import com.rbkmoney.swag.fraudbusters.management.model.Channel;
|
||||
@ -149,4 +155,32 @@ public abstract class TestObjectFactory {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static ListRowsInsertRequest testListRowsInsertRequest(PaymentListRecord... values) {
|
||||
List<PaymentCountInfo> collect = List.of(values).stream()
|
||||
.map(paymentListRecord -> {
|
||||
PaymentCountInfo paymentCountInfo = new PaymentCountInfo();
|
||||
paymentCountInfo.setListRecord(paymentListRecord);
|
||||
return paymentCountInfo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
ListRowsInsertRequest insertRequest = new ListRowsInsertRequest();
|
||||
insertRequest.setListType(ListType.black);
|
||||
insertRequest.setRecords(collect);
|
||||
return insertRequest;
|
||||
}
|
||||
|
||||
public static P2pListRowsInsertRequest testListRowsInsertRequest(P2pListRecord... values) {
|
||||
List<P2pCountInfo> collect = List.of(values).stream()
|
||||
.map(p2pListRecord -> {
|
||||
P2pCountInfo p2pCountInfo = new P2pCountInfo();
|
||||
p2pCountInfo.setListRecord(p2pListRecord);
|
||||
return p2pCountInfo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
P2pListRowsInsertRequest p2pListRowsInsertRequest = new P2pListRowsInsertRequest();
|
||||
p2pListRowsInsertRequest.setListType(ListType.black);
|
||||
p2pListRowsInsertRequest.setRecords(collect);
|
||||
return p2pListRowsInsertRequest;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,19 +4,19 @@ import com.rbkmoney.damsel.wb_list.ChangeCommand;
|
||||
import com.rbkmoney.damsel.wb_list.Command;
|
||||
import com.rbkmoney.damsel.wb_list.ListType;
|
||||
import com.rbkmoney.fraudbusters.management.config.KafkaITest;
|
||||
import com.rbkmoney.fraudbusters.management.controller.ErrorController;
|
||||
import com.rbkmoney.fraudbusters.management.dao.payment.wblist.WbListDao;
|
||||
import com.rbkmoney.fraudbusters.management.domain.tables.pojos.WbListRecords;
|
||||
import com.rbkmoney.fraudbusters.management.utils.MethodPaths;
|
||||
import com.rbkmoney.fraudbusters.management.resource.payment.PaymentsListsResource;
|
||||
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaConsumer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
@ -25,32 +25,33 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.testcontainers.shaded.com.trilead.ssh2.ChannelCondition.TIMEOUT;
|
||||
|
||||
@KafkaITest
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class DeleteFromListTest {
|
||||
|
||||
@Value("${kafka.topic.wblist.command}")
|
||||
public String topicCommand;
|
||||
@MockBean
|
||||
public WbListDao wbListDao;
|
||||
@Autowired
|
||||
TestRestTemplate restTemplate;
|
||||
String paymentListPath;
|
||||
|
||||
@Autowired
|
||||
private KafkaConsumer<ChangeCommand> testCommandKafkaConsumer;
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private PaymentsListsResource paymentsListsResource;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
paymentListPath = String.format(MethodPaths.SERVICE_BASE_URL + MethodPaths.INSERT_PAYMENTS_LIST_ROW_PATH,
|
||||
port);
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(paymentsListsResource, new ErrorController()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteFromList() {
|
||||
void deleteFromList() throws Exception {
|
||||
String test = "test";
|
||||
when(wbListDao.getById(test)).thenReturn(new WbListRecords("id",
|
||||
"partyId",
|
||||
@ -60,7 +61,8 @@ public class DeleteFromListTest {
|
||||
"test",
|
||||
LocalDateTime.now(), null, null, LocalDateTime.now()));
|
||||
|
||||
deleteFromWhiteList(test);
|
||||
mockMvc.perform(delete("/payments-lists/{id}", test))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
List<ChangeCommand> eventList = new ArrayList<>();
|
||||
testCommandKafkaConsumer.read(topicCommand, data -> eventList.add(data.value()));
|
||||
@ -70,8 +72,4 @@ public class DeleteFromListTest {
|
||||
assertEquals(eventList.get(0).command, Command.DELETE);
|
||||
assertEquals(eventList.get(0).getRow().getListType(), ListType.white);
|
||||
}
|
||||
|
||||
private void deleteFromWhiteList(String id) {
|
||||
restTemplate.delete(String.format(MethodPaths.SERVICE_BASE_URL + MethodPaths.DELETE_LIST_ROWS_PATH, port, id));
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,17 @@
|
||||
package com.rbkmoney.fraudbusters.management.kafka;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.rbkmoney.damsel.wb_list.ChangeCommand;
|
||||
import com.rbkmoney.damsel.wb_list.Command;
|
||||
import com.rbkmoney.damsel.wb_list.ListType;
|
||||
import com.rbkmoney.fraudbusters.management.TestObjectFactory;
|
||||
import com.rbkmoney.fraudbusters.management.config.KafkaITest;
|
||||
import com.rbkmoney.fraudbusters.management.controller.ErrorController;
|
||||
import com.rbkmoney.fraudbusters.management.dao.p2p.wblist.P2PWbListDao;
|
||||
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.utils.MethodPaths;
|
||||
import com.rbkmoney.fraudbusters.management.resource.payment.PaymentsListsResource;
|
||||
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaConsumer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -16,27 +19,24 @@ 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.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.testcontainers.shaded.com.trilead.ssh2.ChannelCondition.TIMEOUT;
|
||||
|
||||
@KafkaITest
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class InsertInListTest {
|
||||
|
||||
public static final String BASE_URL = "http://localhost:";
|
||||
private static final String VALUE = "value";
|
||||
private static final String SHOP_ID = "shopId";
|
||||
private static final String PARTY_ID = "partyId";
|
||||
@ -47,59 +47,45 @@ public class InsertInListTest {
|
||||
@MockBean
|
||||
public P2PWbListDao wbListDao;
|
||||
@Autowired
|
||||
TestRestTemplate restTemplate;
|
||||
String paymentListPath;
|
||||
@Autowired
|
||||
private KafkaConsumer<ChangeCommand> testCommandKafkaConsumer;
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
|
||||
|
||||
@Autowired
|
||||
private PaymentsListsResource paymentsListsResource;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
paymentListPath = String.format(MethodPaths.SERVICE_BASE_URL + MethodPaths.INSERT_PAYMENTS_LIST_ROW_PATH,
|
||||
port);
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(paymentsListsResource, new ErrorController()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void insertToList() {
|
||||
void insertToList() throws Exception {
|
||||
Mockito.doNothing().when(wbListDao).saveListRecord(any());
|
||||
|
||||
PaymentListRecord record = new PaymentListRecord();
|
||||
record.setListName(LIST_NAME);
|
||||
record.setPartyId(PARTY_ID);
|
||||
record.setShopId(SHOP_ID);
|
||||
record.setValue(VALUE);
|
||||
|
||||
PaymentListRecord recordSecond = new PaymentListRecord();
|
||||
recordSecond.setListName(LIST_NAME);
|
||||
recordSecond.setPartyId(PARTY_ID);
|
||||
recordSecond.setShopId(SHOP_ID);
|
||||
recordSecond.setValue(VALUE + 2);
|
||||
|
||||
insertToBlackList(record, recordSecond);
|
||||
ListRowsInsertRequest listRowsInsertRequest = TestObjectFactory.testListRowsInsertRequest(record, recordSecond);
|
||||
mockMvc.perform(post("/payments-lists")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(listRowsInsertRequest)))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void insertToBlackList(PaymentListRecord... values) {
|
||||
List<PaymentCountInfo> collect = List.of(values).stream()
|
||||
.map(paymentListRecord -> {
|
||||
PaymentCountInfo paymentCountInfo = new PaymentCountInfo();
|
||||
paymentCountInfo.setListRecord(paymentListRecord);
|
||||
return paymentCountInfo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
ListRowsInsertRequest insertRequest = new ListRowsInsertRequest();
|
||||
insertRequest.setListType(ListType.black);
|
||||
insertRequest.setRecords(collect);
|
||||
HttpEntity<ListRowsInsertRequest> entity = new HttpEntity<>(insertRequest,
|
||||
new org.springframework.http.HttpHeaders());
|
||||
restTemplate.exchange(paymentListPath, HttpMethod.POST, entity,
|
||||
String.class);
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,41 @@
|
||||
package com.rbkmoney.fraudbusters.management.kafka;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.rbkmoney.damsel.wb_list.ChangeCommand;
|
||||
import com.rbkmoney.damsel.wb_list.Command;
|
||||
import com.rbkmoney.damsel.wb_list.ListType;
|
||||
import com.rbkmoney.fraudbusters.management.TestObjectFactory;
|
||||
import com.rbkmoney.fraudbusters.management.config.KafkaITest;
|
||||
import com.rbkmoney.fraudbusters.management.controller.ErrorController;
|
||||
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.resource.p2p.P2pListsResource;
|
||||
import com.rbkmoney.testcontainers.annotations.kafka.config.KafkaConsumer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
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.http.MediaType;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.testcontainers.shaded.com.trilead.ssh2.ChannelCondition.TIMEOUT;
|
||||
|
||||
@KafkaITest
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class P2pInsertInListTest {
|
||||
|
||||
public static final String IDENTITY_ID = "identityId";
|
||||
@ -45,24 +47,33 @@ public class P2pInsertInListTest {
|
||||
@MockBean
|
||||
public P2PWbListDao wbListDao;
|
||||
@Autowired
|
||||
TestRestTemplate restTemplate;
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
private KafkaConsumer<ChangeCommand> testCommandKafkaConsumer;
|
||||
|
||||
@Autowired
|
||||
private KafkaConsumer<ChangeCommand> testCommandKafkaConsumer;
|
||||
private P2pListsResource p2pListsResource;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(p2pListsResource, new ErrorController()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockUser("customUsername")
|
||||
void insertInBlackList() {
|
||||
void insertInBlackList() throws Exception {
|
||||
doNothing().when(wbListDao).saveListRecord(any());
|
||||
|
||||
P2pListRecord record = new P2pListRecord();
|
||||
record.setListName(LIST_NAME);
|
||||
record.setIdentityId(IDENTITY_ID);
|
||||
record.setValue(VALUE);
|
||||
|
||||
insertToBlackList(record);
|
||||
P2pListRowsInsertRequest p2pListRowsInsertRequest = TestObjectFactory.testListRowsInsertRequest(record);
|
||||
mockMvc.perform(post("/p2p/lists")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(p2pListRowsInsertRequest)))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
List<ChangeCommand> eventList = new ArrayList<>();
|
||||
testCommandKafkaConsumer.read(topicCommand, data -> eventList.add(data.value()));
|
||||
@ -72,23 +83,4 @@ public class P2pInsertInListTest {
|
||||
assertEquals(Command.CREATE, eventList.get(0).command);
|
||||
assertEquals(ListType.black, eventList.get(0).getRow().getListType());
|
||||
}
|
||||
|
||||
private void insertToBlackList(P2pListRecord... values) {
|
||||
List<P2pCountInfo> collect = List.of(values).stream()
|
||||
.map(p2pListRecord -> {
|
||||
P2pCountInfo p2pCountInfo = new P2pCountInfo();
|
||||
p2pCountInfo.setListRecord(p2pListRecord);
|
||||
return p2pCountInfo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
P2pListRowsInsertRequest p2pListRowsInsertRequest = new P2pListRowsInsertRequest();
|
||||
p2pListRowsInsertRequest.setListType(ListType.black);
|
||||
p2pListRowsInsertRequest.setRecords(collect);
|
||||
HttpEntity<P2pListRowsInsertRequest> entity = new HttpEntity<>(p2pListRowsInsertRequest,
|
||||
new org.springframework.http.HttpHeaders());
|
||||
ResponseEntity<String> response =
|
||||
restTemplate.exchange("http://localhost:" + port + "/fb-management/v1/p2p/lists",
|
||||
HttpMethod.POST, entity, String.class);
|
||||
System.out.println(response);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user