mirror of
https://github.com/valitydev/wb-list-manager.git
synced 2024-11-06 01:35:17 +00:00
update test to junit5, up java 15
This commit is contained in:
parent
9676d131d4
commit
b8111a41a1
5
Jenkinsfile
vendored
5
Jenkinsfile
vendored
@ -5,12 +5,11 @@ build('wb-list-manager', 'java-maven') {
|
||||
|
||||
def javaServicePipeline
|
||||
runStage('load JavaService pipeline') {
|
||||
javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaService.groovy")
|
||||
javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaServiceInsideDocker.groovy")
|
||||
}
|
||||
|
||||
def serviceName = env.REPO_NAME
|
||||
def mvnArgs = '-DjvmArgs="-Xmx256m"'
|
||||
def useJava11 = true
|
||||
|
||||
javaServicePipeline(serviceName, useJava11, mvnArgs)
|
||||
javaServicePipeline(serviceName, mvnArgs)
|
||||
}
|
||||
|
14
pom.xml
14
pom.xml
@ -6,11 +6,11 @@
|
||||
<parent>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>service-parent-pom</artifactId>
|
||||
<version>1.2.5</version>
|
||||
<version>2.0.8</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>wb-list-manager</artifactId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>wb-list-manager</name>
|
||||
@ -116,7 +116,13 @@
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>kafka</artifactId>
|
||||
<version>1.14.3</version>
|
||||
<version>1.15.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>1.15.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@ -178,7 +184,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.8.7</version>
|
||||
<configuration>
|
||||
<destFile>${sonar.jacoco.reportPath}</destFile>
|
||||
<append>true</append>
|
||||
|
@ -63,7 +63,7 @@ public class WbListServiceHandler implements WbListServiceSrv.Iface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getRowInfo(Row row) throws ListNotFound, TException {
|
||||
public Result getRowInfo(Row row) {
|
||||
log.info("WbListServiceHandler getRowInfo row: {}", row);
|
||||
Optional<com.rbkmoney.wb.list.manager.model.Row> result = getCascadeRow(row);
|
||||
if (result.isPresent() && row.getListType() == ListType.grey) {
|
||||
|
@ -11,16 +11,16 @@ import java.io.IOException;
|
||||
|
||||
@WebServlet("/wb_list/v1")
|
||||
@RequiredArgsConstructor
|
||||
public class FraudInspectorServlet extends GenericServlet {
|
||||
public class WbListServlet extends GenericServlet {
|
||||
|
||||
private final WbListServiceSrv.Iface fraudInspectorHandler;
|
||||
private final WbListServiceSrv.Iface wbListHandler;
|
||||
private Servlet thriftServlet;
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
thriftServlet = new THServiceBuilder()
|
||||
.build(WbListServiceSrv.Iface.class, fraudInspectorHandler);
|
||||
.build(WbListServiceSrv.Iface.class, wbListHandler);
|
||||
}
|
||||
|
||||
@Override
|
@ -20,10 +20,10 @@ public class CommandServiceImpl implements CommandService {
|
||||
|
||||
@Override
|
||||
public Event apply(ChangeCommand command) {
|
||||
log.info("WbListStreamFactory apply command: {}", command);
|
||||
log.info("CommandService apply command: {}", command);
|
||||
Event event = new Event();
|
||||
Row row = commandToRowConverter.convert(command);
|
||||
log.info("WbListStreamFactory apply row: {}", row);
|
||||
log.info("CommandService apply row: {}", row);
|
||||
switch (command.command) {
|
||||
case CREATE:
|
||||
listRepository.create(row);
|
||||
@ -34,7 +34,7 @@ public class CommandServiceImpl implements CommandService {
|
||||
event.setEventType(EventType.DELETED);
|
||||
break;
|
||||
default:
|
||||
log.warn("WbListStreamFactory command for list not found! command: {}", command);
|
||||
log.warn("CommandService command for list not found! command: {}", command);
|
||||
throw new RuntimeException("WbListStreamFactory command for list not found!");
|
||||
}
|
||||
event.setRow(command.getRow());
|
||||
|
@ -1,38 +0,0 @@
|
||||
package com.rbkmoney.wb.list.manager;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.runner.RunWith;
|
||||
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.GenericContainer;
|
||||
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(initializers = AbstractRiakIntegrationTest.Initializer.class)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
public abstract class AbstractRiakIntegrationTest {
|
||||
|
||||
@ClassRule
|
||||
public static GenericContainer riak = new GenericContainer("basho/riak-kv")
|
||||
.withExposedPorts(8098, 8087)
|
||||
.withPrivilegedMode(true)
|
||||
.waitingFor(new WaitAllStrategy()
|
||||
.withStartupTimeout(Duration.ofMinutes(2)));
|
||||
|
||||
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
TestPropertyValues
|
||||
.of("riak.port=" + riak.getMappedPort(8087))
|
||||
.applyTo(configurableApplicationContext.getEnvironment());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.rbkmoney.wb.list.manager;
|
||||
|
||||
import com.rbkmoney.kafka.common.serialization.ThriftSerializer;
|
||||
import com.rbkmoney.wb.list.manager.extension.RiakContainerExtension;
|
||||
import com.rbkmoney.wb.list.manager.serializer.EventDeserializer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
@ -11,17 +12,18 @@ import org.apache.kafka.clients.producer.Producer;
|
||||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
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.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.testcontainers.containers.KafkaContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
@ -29,17 +31,21 @@ import java.util.Properties;
|
||||
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
@Testcontainers
|
||||
@Slf4j
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith({SpringExtension.class, RiakContainerExtension.class})
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
@ContextConfiguration(initializers = KafkaAbstractTest.Initializer.class)
|
||||
public abstract class KafkaAbstractTest extends AbstractRiakIntegrationTest {
|
||||
public abstract class KafkaAbstractTest {
|
||||
|
||||
public static final String KAFKA_DOCKER_VERSION = "5.0.1";
|
||||
private static final String CONFLUENT_IMAGE_NAME = "confluentinc/cp-kafka";
|
||||
private static final String CONFLUENT_PLATFORM_VERSION = "6.0.3";
|
||||
|
||||
@ClassRule
|
||||
public static KafkaContainer kafka = new KafkaContainer(KAFKA_DOCKER_VERSION)
|
||||
@Container
|
||||
public static KafkaContainer kafka = new KafkaContainer(DockerImageName
|
||||
.parse(CONFLUENT_IMAGE_NAME)
|
||||
.withTag(CONFLUENT_PLATFORM_VERSION))
|
||||
.withEmbeddedZookeeper()
|
||||
.withStartupTimeout(Duration.ofMinutes(2));
|
||||
|
||||
@ -66,13 +72,13 @@ public abstract class KafkaAbstractTest extends AbstractRiakIntegrationTest {
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
TestPropertyValues
|
||||
.of("kafka.bootstrap.servers=" + kafka.getBootstrapServers())
|
||||
.of("kafka.bootstrap.servers=" + kafka.getBootstrapServers(),
|
||||
"riak.port=" + RiakContainerExtension.RIAK.getMappedPort(8087))
|
||||
.applyTo(configurableApplicationContext.getEnvironment());
|
||||
initTopic("wb-list-command");
|
||||
initTopic("wb-list-event-sink");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private <T> Consumer<String, T> initTopic(String topicName) {
|
||||
Consumer<String, T> consumer = createConsumer();
|
||||
try {
|
||||
|
@ -8,8 +8,7 @@ import com.basho.riak.client.core.query.RiakObject;
|
||||
import com.rbkmoney.wb.list.manager.config.RiakConfig;
|
||||
import com.rbkmoney.wb.list.manager.model.Row;
|
||||
import com.rbkmoney.wb.list.manager.repository.ListRepository;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@ -19,6 +18,7 @@ import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
@ContextConfiguration(classes = {ListRepository.class, RiakConfig.class})
|
||||
@ -37,7 +37,7 @@ public class RiakTest extends KafkaAbstractTest {
|
||||
private RiakClient client;
|
||||
|
||||
@Test
|
||||
public void riakTest() throws ExecutionException, InterruptedException {
|
||||
void riakTest() throws ExecutionException, InterruptedException {
|
||||
sleep(10000);
|
||||
|
||||
Row row = new Row();
|
||||
@ -52,17 +52,16 @@ public class RiakTest extends KafkaAbstractTest {
|
||||
RiakObject obj = response.getValue(RiakObject.class);
|
||||
|
||||
String result = obj.getValue().toString();
|
||||
Assert.assertEquals(VALUE, result);
|
||||
assertEquals(VALUE, result);
|
||||
|
||||
Optional<Row> resultGet = listRepository.get(KEY);
|
||||
Assert.assertFalse(resultGet.isEmpty());
|
||||
Assert.assertEquals(VALUE, resultGet.get().getValue());
|
||||
assertFalse(resultGet.isEmpty());
|
||||
assertEquals(VALUE, resultGet.get().getValue());
|
||||
|
||||
listRepository.remove(row);
|
||||
response = client.execute(fv);
|
||||
obj = response.getValue(RiakObject.class);
|
||||
Assert.assertNull(obj);
|
||||
|
||||
assertNull(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,14 +13,12 @@ import org.apache.kafka.clients.producer.Producer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
import org.apache.thrift.TException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
@ -30,13 +28,12 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
@Slf4j
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT)
|
||||
@ContextConfiguration(classes = WbListManagerApplication.class)
|
||||
public class WbListManagerApplicationTest extends KafkaAbstractTest {
|
||||
|
||||
public static final String IDENTITY_ID = "identityId";
|
||||
@ -71,7 +68,7 @@ public class WbListManagerApplicationTest extends KafkaAbstractTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kafkaRowTest() throws Exception {
|
||||
void kafkaRowTest() throws Exception {
|
||||
THClientBuilder clientBuilder = new THClientBuilder()
|
||||
.withAddress(new URI(String.format(SERVICE_URL, serverPort)))
|
||||
.withNetworkTimeout(300000);
|
||||
@ -204,7 +201,6 @@ public class WbListManagerApplicationTest extends KafkaAbstractTest {
|
||||
return rowWithCountInfo;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private com.rbkmoney.damsel.wb_list.Row createRow() {
|
||||
Row row = createListRow();
|
||||
row.setId(IdInfo.payment_id(new PaymentId()
|
||||
@ -214,7 +210,6 @@ public class WbListManagerApplicationTest extends KafkaAbstractTest {
|
||||
return row;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ChangeCommandWrapper createCommand(com.rbkmoney.damsel.wb_list.Row row) {
|
||||
ChangeCommandWrapper changeCommand = new ChangeCommandWrapper();
|
||||
changeCommand.setCommand(Command.CREATE);
|
||||
@ -222,8 +217,6 @@ public class WbListManagerApplicationTest extends KafkaAbstractTest {
|
||||
return changeCommand;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private com.rbkmoney.damsel.wb_list.Row createRowOld() {
|
||||
Row row = createListRow()
|
||||
.setShopId(SHOP_ID)
|
||||
@ -231,7 +224,6 @@ public class WbListManagerApplicationTest extends KafkaAbstractTest {
|
||||
return row;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Row createListRow() {
|
||||
Row row = new Row();
|
||||
row.setListName(LIST_NAME);
|
||||
@ -240,7 +232,6 @@ public class WbListManagerApplicationTest extends KafkaAbstractTest {
|
||||
return row;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private com.rbkmoney.damsel.wb_list.Row createRowWithCountInfo(String startTimeCount, String partyId,
|
||||
String shopId) {
|
||||
com.rbkmoney.damsel.wb_list.Row row = new com.rbkmoney.damsel.wb_list.Row();
|
||||
|
@ -4,28 +4,20 @@ import com.rbkmoney.damsel.wb_list.*;
|
||||
import com.rbkmoney.kafka.common.serialization.ThriftSerializer;
|
||||
import com.rbkmoney.wb.list.manager.exception.RiakExecutionException;
|
||||
import com.rbkmoney.wb.list.manager.repository.ListRepository;
|
||||
import com.rbkmoney.wb.list.manager.serializer.EventDeserializer;
|
||||
import com.rbkmoney.wb.list.manager.utils.ChangeCommandWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@ -34,11 +26,9 @@ import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
@Slf4j
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT)
|
||||
@TestPropertySource(properties = {"retry.timeout=100"})
|
||||
@ContextConfiguration(classes = WbListManagerApplication.class)
|
||||
public class WbListSafetyApplicationTest extends KafkaAbstractTest {
|
||||
|
||||
private static final String VALUE = "value";
|
||||
@ -55,9 +45,6 @@ public class WbListSafetyApplicationTest extends KafkaAbstractTest {
|
||||
@MockBean
|
||||
private ListRepository listRepository;
|
||||
|
||||
@Value("${riak.bucket}")
|
||||
private String bucketName;
|
||||
|
||||
public static <T> Producer<String, T> createProducer() {
|
||||
Properties props = new Properties();
|
||||
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers());
|
||||
@ -67,18 +54,8 @@ public class WbListSafetyApplicationTest extends KafkaAbstractTest {
|
||||
return new KafkaProducer<>(props);
|
||||
}
|
||||
|
||||
public static <T> Consumer<String, T> createConsumer() {
|
||||
Properties props = new Properties();
|
||||
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers());
|
||||
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
|
||||
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, EventDeserializer.class);
|
||||
props.put(ConsumerConfig.GROUP_ID_CONFIG, "test");
|
||||
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
|
||||
return new KafkaConsumer<>(props);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kafkaRowTestException() throws Exception {
|
||||
void kafkaRowTestException() throws Exception {
|
||||
doThrow(new RiakExecutionException(),
|
||||
new RiakExecutionException())
|
||||
.doNothing()
|
||||
@ -97,7 +74,6 @@ public class WbListSafetyApplicationTest extends KafkaAbstractTest {
|
||||
Mockito.verify(listRepository, times(3)).create(any());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ChangeCommandWrapper createCommand() {
|
||||
ChangeCommandWrapper changeCommand = new ChangeCommandWrapper();
|
||||
changeCommand.setCommand(Command.CREATE);
|
||||
@ -106,7 +82,6 @@ public class WbListSafetyApplicationTest extends KafkaAbstractTest {
|
||||
return changeCommand;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private com.rbkmoney.damsel.wb_list.Row createRow() {
|
||||
com.rbkmoney.damsel.wb_list.Row row = new com.rbkmoney.damsel.wb_list.Row();
|
||||
row.setId(IdInfo.payment_id(new PaymentId()
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.rbkmoney.wb.list.manager.extension;
|
||||
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class RiakContainerExtension implements BeforeAllCallback {
|
||||
|
||||
public static GenericContainer RIAK;
|
||||
@Override
|
||||
public void beforeAll(ExtensionContext extensionContext) throws Exception {
|
||||
RIAK = new GenericContainer("basho/riak-kv")
|
||||
.withExposedPorts(8098, 8087)
|
||||
.withPrivilegedMode(true)
|
||||
.waitingFor(new WaitAllStrategy()
|
||||
.withStartupTimeout(Duration.ofMinutes(2)));
|
||||
|
||||
RIAK.start();
|
||||
}
|
||||
}
|
@ -8,110 +8,110 @@ import com.rbkmoney.damsel.wb_list.Result;
|
||||
import com.rbkmoney.wb.list.manager.model.Row;
|
||||
import com.rbkmoney.wb.list.manager.repository.ListRepository;
|
||||
import org.apache.thrift.TException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class WbListServiceHandlerTest {
|
||||
|
||||
public static final String VALUE = "value";
|
||||
public static final String PARTY_ID = "partyId";
|
||||
public static final String SHOP_ID = "shopId";
|
||||
public static final String LIST_NAME = "listName";
|
||||
WbListServiceHandler wbListServiceHandler;
|
||||
private WbListServiceHandler wbListServiceHandler;
|
||||
|
||||
@Mock
|
||||
ListRepository listRepository;
|
||||
private ListRepository listRepository;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
wbListServiceHandler = new WbListServiceHandler(listRepository, new ObjectMapper());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isExist() throws TException {
|
||||
void isExist() throws TException {
|
||||
com.rbkmoney.damsel.wb_list.Row row = createRow();
|
||||
boolean exist = wbListServiceHandler.isExist(row);
|
||||
Assert.assertTrue(exist);
|
||||
assertTrue(exist);
|
||||
|
||||
Mockito.when(listRepository.get(anyString())).thenReturn(Optional.empty());
|
||||
exist = wbListServiceHandler.isExist(row);
|
||||
Assert.assertFalse(exist);
|
||||
assertFalse(exist);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRowInfo() throws TException {
|
||||
void getRowInfo() {
|
||||
com.rbkmoney.damsel.wb_list.Row row = createRow();
|
||||
Result result = wbListServiceHandler.getRowInfo(row);
|
||||
Assert.assertFalse(result == null);
|
||||
assertFalse(result == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAllExist() throws TException {
|
||||
void isAllExist() throws TException {
|
||||
ArrayList<com.rbkmoney.damsel.wb_list.Row> list = new ArrayList<>();
|
||||
boolean exist = wbListServiceHandler.isAllExist(list);
|
||||
Assert.assertTrue(exist);
|
||||
assertTrue(exist);
|
||||
|
||||
list.add(createRow());
|
||||
list.add(createRow());
|
||||
Mockito.when(listRepository.get(anyString())).thenReturn(Optional.of(new Row()));
|
||||
Assert.assertTrue(wbListServiceHandler.isAllExist(list));
|
||||
assertTrue(wbListServiceHandler.isAllExist(list));
|
||||
|
||||
Mockito.when(listRepository.get(anyString()))
|
||||
.thenReturn(Optional.of(new Row()))
|
||||
.thenReturn(Optional.empty());
|
||||
Assert.assertFalse(wbListServiceHandler.isAllExist(list));
|
||||
assertFalse(wbListServiceHandler.isAllExist(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAnyExist() throws TException {
|
||||
void isAnyExist() throws TException {
|
||||
ArrayList<com.rbkmoney.damsel.wb_list.Row> list = new ArrayList<>();
|
||||
boolean exist = wbListServiceHandler.isAnyExist(list);
|
||||
Assert.assertFalse(exist);
|
||||
assertFalse(exist);
|
||||
|
||||
list.add(createRow());
|
||||
list.add(createRow());
|
||||
Mockito.when(listRepository.get(anyString()))
|
||||
.thenReturn(Optional.of(new Row()))
|
||||
.thenReturn(Optional.empty());
|
||||
Assert.assertTrue(wbListServiceHandler.isAnyExist(list));
|
||||
assertTrue(wbListServiceHandler.isAnyExist(list));
|
||||
|
||||
Mockito.when(listRepository.get(anyString()))
|
||||
.thenReturn(Optional.empty())
|
||||
.thenReturn(Optional.empty());
|
||||
Assert.assertFalse(wbListServiceHandler.isAnyExist(list));
|
||||
assertFalse(wbListServiceHandler.isAnyExist(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isNoOneExist() throws TException {
|
||||
void isNoOneExist() throws TException {
|
||||
ArrayList<com.rbkmoney.damsel.wb_list.Row> list = new ArrayList<>();
|
||||
boolean exist = wbListServiceHandler.isNotOneExist(list);
|
||||
Assert.assertTrue(exist);
|
||||
assertTrue(exist);
|
||||
|
||||
list.add(createRow());
|
||||
list.add(createRow());
|
||||
Mockito.when(listRepository.get(anyString()))
|
||||
.thenReturn(Optional.empty())
|
||||
.thenReturn(Optional.empty());
|
||||
Assert.assertTrue(wbListServiceHandler.isNotOneExist(list));
|
||||
assertTrue(wbListServiceHandler.isNotOneExist(list));
|
||||
|
||||
Mockito.when(listRepository.get(anyString()))
|
||||
.thenReturn(Optional.empty())
|
||||
.thenReturn(Optional.of(new Row()));
|
||||
Assert.assertFalse(wbListServiceHandler.isNotOneExist(list));
|
||||
assertFalse(wbListServiceHandler.isNotOneExist(list));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private com.rbkmoney.damsel.wb_list.Row createRow() {
|
||||
Row value = new Row();
|
||||
value.setValue(VALUE);
|
||||
|
Loading…
Reference in New Issue
Block a user