migration to junit 5

This commit is contained in:
Michele Artini 2021-11-03 10:51:04 +01:00
parent e774487903
commit caeb3c8ddb
14 changed files with 288 additions and 125 deletions

View File

@ -33,6 +33,31 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<!-- Tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -22,10 +22,37 @@
<artifactId>dnet-broker-apps-common</artifactId> <artifactId>dnet-broker-apps-common</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId> <artifactId>hadoop-client</artifactId>
</dependency> </dependency>
<!-- Tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -60,12 +60,31 @@
<artifactId>dhp-schemas</artifactId> <artifactId>dhp-schemas</artifactId>
</dependency> </dependency>
<!-- JUnit --> <!-- Tests -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

View File

@ -1,8 +1,8 @@
package eu.dnetlib.data.mdstore.manager.controller; package eu.dnetlib.data.mdstore.manager.controller;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Date; import java.util.Date;

View File

@ -1,7 +1,7 @@
package eu.dnetlib.data.mdstore.manager.controller; package eu.dnetlib.data.mdstore.manager.controller;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;

View File

@ -72,6 +72,31 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- Tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -32,6 +32,25 @@
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
</dependency> </dependency>
<!-- Tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

View File

@ -73,10 +73,10 @@
<version>0.3.0</version> <version>0.3.0</version>
</dependency> </dependency>
<!-- JUNIT --> <!-- Tests -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
@ -86,6 +86,18 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -91,10 +91,15 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- JUNIT -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>junit</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
@ -105,9 +110,17 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.mockito</groupId>
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -7,8 +7,8 @@ import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
@ -26,7 +26,7 @@ import eu.dnetlib.broker.common.subscriptions.NotificationMode;
import eu.dnetlib.broker.common.subscriptions.Subscription; import eu.dnetlib.broker.common.subscriptions.Subscription;
import eu.dnetlib.broker.common.utils.DateParser; import eu.dnetlib.broker.common.utils.DateParser;
@Ignore @Disabled
// @RunWith(SpringJUnit4ClassRunner.class) // @RunWith(SpringJUnit4ClassRunner.class)
// @ContextConfiguration(locations = { "classpath:/applicationContext-test-queries.xml" }) // @ContextConfiguration(locations = { "classpath:/applicationContext-test-queries.xml" })
public class IndexClientTest { public class IndexClientTest {
@ -44,12 +44,12 @@ public class IndexClientTest {
System.out.println("Start searching"); System.out.println("Start searching");
final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.boolQuery() .withQuery(QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("topic", topic)) .must(QueryBuilders.matchQuery("topic", topic))
.must(QueryBuilders.rangeQuery("creationDate").from(fromDate))) .must(QueryBuilders.rangeQuery("creationDate").from(fromDate)))
.withSearchType(SearchType.DEFAULT) .withSearchType(SearchType.DEFAULT)
.withPageable(PageRequest.of(0, 10)) .withPageable(PageRequest.of(0, 10))
.build(); .build();
int count = 0; int count = 0;
final CloseableIterator<SearchHit<Event>> it = esOperations.searchForStream(searchQuery, Event.class, IndexCoordinates.of(indexName)); final CloseableIterator<SearchHit<Event>> it = esOperations.searchForStream(searchQuery, Event.class, IndexCoordinates.of(indexName));
@ -63,7 +63,7 @@ public class IndexClientTest {
} }
@Test @Test
@Ignore @Disabled
public void testSearchSubscription() { public void testSearchSubscription() {
System.out.println("Start searching"); System.out.println("Start searching");
@ -73,25 +73,25 @@ public class IndexClientTest {
s.setTopic("ENRICH/MORE/OPENACCESS_VERSION"); s.setTopic("ENRICH/MORE/OPENACCESS_VERSION");
s.setFrequency(NotificationFrequency.daily); s.setFrequency(NotificationFrequency.daily);
s.setMode(NotificationMode.MOCK); s.setMode(NotificationMode.MOCK);
s.setConditions( s.setConditions("[{\"field\":\"targetDatasourceName\",\"fieldType\":\"STRING\",\"operator\":\"EXACT\",\"listParams\":[{\"value\":\"Research Papers in Economics\"}]},{\"field\":\"trust\",\"fieldType\":\"FLOAT\",\"operator\":\"RANGE\",\"listParams\":[{\"value\":\"0\",\"otherValue\":\"1\"}]}]");
"[{\"field\":\"targetDatasourceName\",\"fieldType\":\"STRING\",\"operator\":\"EXACT\",\"listParams\":[{\"value\":\"Research Papers in Economics\"}]},{\"field\":\"trust\",\"fieldType\":\"FLOAT\",\"operator\":\"RANGE\",\"listParams\":[{\"value\":\"0\",\"otherValue\":\"1\"}]}]");
final BoolQueryBuilder mapQuery = QueryBuilders.boolQuery(); final BoolQueryBuilder mapQuery = QueryBuilders.boolQuery();
s.getConditionsAsList().stream() s.getConditionsAsList()
.map(MapCondition::asQueryBuilder) .stream()
.filter(Objects::nonNull) .map(MapCondition::asQueryBuilder)
.forEach(mapQuery::must); .filter(Objects::nonNull)
.forEach(mapQuery::must);
final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.boolQuery() .withQuery(QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("topic", s.getTopic())) .must(QueryBuilders.matchQuery("topic", s.getTopic()))
.must(QueryBuilders.rangeQuery("creationDate").from(s.getLastNotificationDate())) .must(QueryBuilders.rangeQuery("creationDate").from(s.getLastNotificationDate()))
.must(QueryBuilders.nestedQuery("map", mapQuery, ScoreMode.None))) .must(QueryBuilders.nestedQuery("map", mapQuery, ScoreMode.None)))
.withSearchType(SearchType.DEFAULT) .withSearchType(SearchType.DEFAULT)
.withPageable(PageRequest.of(0, 10)) .withPageable(PageRequest.of(0, 10))
.build(); .build();
int count = 0; int count = 0;
final CloseableIterator<SearchHit<Event>> it = esOperations.searchForStream(searchQuery, Event.class, IndexCoordinates.of(indexName)); final CloseableIterator<SearchHit<Event>> it = esOperations.searchForStream(searchQuery, Event.class, IndexCoordinates.of(indexName));

View File

@ -1,30 +1,30 @@
package eu.dnetlib.broker.common.subscriptions; package eu.dnetlib.broker.common.subscriptions;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import eu.dnetlib.broker.common.elasticsearch.Event; import eu.dnetlib.broker.common.elasticsearch.Event;
import eu.dnetlib.broker.common.utils.DateParser; import eu.dnetlib.broker.common.utils.DateParser;
import eu.dnetlib.broker.common.utils.MapValueType; import eu.dnetlib.broker.common.utils.MapValueType;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class ConditionTest { public class ConditionTest {
@Mock @Mock
private Event event; private Event event;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
final Map<String, Object> map = new HashMap<>(); final Map<String, Object> map = new HashMap<>();
@ -40,94 +40,94 @@ public class ConditionTest {
@Test @Test
public void testVerifyEvent_String() { public void testVerifyEvent_String() {
assertTrue((new MapCondition("repo", MapValueType.STRING, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("PUMA", null)))) assertTrue(new MapCondition("repo", MapValueType.STRING, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("PUMA", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("repo", MapValueType.STRING, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("People", null)))) assertFalse(new MapCondition("repo", MapValueType.STRING, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("People", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
} }
@Test @Test
public void testVerifyEvent_Integer() { public void testVerifyEvent_Integer() {
assertTrue((new MapCondition("total", MapValueType.INTEGER, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("1234", null)))) assertTrue(new MapCondition("total", MapValueType.INTEGER, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("1234", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("total", MapValueType.INTEGER, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("2222", null)))) assertFalse(new MapCondition("total", MapValueType.INTEGER, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("2222", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1000", "2000")))) assertTrue(new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1000", "2000")))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1200.52", "1300,45")))) assertTrue(new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1200.52", "1300,45")))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1000", null)))) assertTrue(new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1000", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams(null, "2000")))) assertTrue(new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams(null, "2000")))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("0", "1000")))) assertFalse(new MapCondition("total", MapValueType.INTEGER, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("0", "1000")))
.verifyEvent(this.event)); .verifyEvent(this.event));
} }
@Test @Test
public void testVerifyEvent_Float() { public void testVerifyEvent_Float() {
assertTrue((new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("1.23d", null)))) assertTrue(new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("1.23d", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("1.2d", null)))) assertFalse(new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("1.2d", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1", "2")))) assertTrue(new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1", "2")))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1.2", "1.35")))) assertTrue(new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1.2", "1.35")))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1", null)))) assertTrue(new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("1", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams(null, "2")))) assertTrue(new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams(null, "2")))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("2", "3.2")))) assertFalse(new MapCondition("impact", MapValueType.FLOAT, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("2", "3.2")))
.verifyEvent(this.event)); .verifyEvent(this.event));
} }
@Test @Test
public void testVerifyEvent_Date() { public void testVerifyEvent_Date() {
assertTrue((new MapCondition("date", MapValueType.DATE, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("2012-05-15", null)))) assertTrue(new MapCondition("date", MapValueType.DATE, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("2012-05-15", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("date", MapValueType.DATE, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("2012-05-16", null)))) assertFalse(new MapCondition("date", MapValueType.DATE, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("2012-05-16", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("date", MapValueType.DATE, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("2012-05-01", "2012-05-31")))) assertTrue(new MapCondition("date", MapValueType.DATE, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("2012-05-01", "2012-05-31")))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("date", MapValueType.DATE, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("2012-05-01", null)))) assertTrue(new MapCondition("date", MapValueType.DATE, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("2012-05-01", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("date", MapValueType.DATE, ConditionOperator.RANGE, Arrays.asList(new ConditionParams(null, "2012-05-31")))) assertTrue(new MapCondition("date", MapValueType.DATE, ConditionOperator.RANGE, Arrays.asList(new ConditionParams(null, "2012-05-31")))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("date", MapValueType.DATE, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("2013-01-01", "2013-12-31")))) assertFalse(new MapCondition("date", MapValueType.DATE, ConditionOperator.RANGE, Arrays.asList(new ConditionParams("2013-01-01", "2013-12-31")))
.verifyEvent(this.event)); .verifyEvent(this.event));
} }
@Test @Test
public void testVerifyEvent_Boolean() { public void testVerifyEvent_Boolean() {
assertTrue((new MapCondition("open", MapValueType.BOOLEAN, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("false", null)))) assertTrue(new MapCondition("open", MapValueType.BOOLEAN, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("false", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("open", MapValueType.BOOLEAN, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("true", null)))) assertFalse(new MapCondition("open", MapValueType.BOOLEAN, ConditionOperator.EXACT, Arrays.asList(new ConditionParams("true", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
} }
@Test @Test
public void testVerifyEvent_List_String() { public void testVerifyEvent_List_String() {
assertTrue((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL, assertTrue(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL,
Arrays.asList(new ConditionParams("artini michele", null)))).verifyEvent(this.event)); Arrays.asList(new ConditionParams("artini michele", null))).verifyEvent(this.event));
assertTrue((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL, Arrays.asList(new ConditionParams("artini", null)))) assertTrue(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL, Arrays.asList(new ConditionParams("artini", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertTrue((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY, assertTrue(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY,
Arrays.asList(new ConditionParams("artini michele", null)))).verifyEvent(this.event)); Arrays.asList(new ConditionParams("artini michele", null))).verifyEvent(this.event));
assertTrue((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY, assertTrue(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY,
Arrays.asList(new ConditionParams("artini giuseppe", null)))).verifyEvent(this.event)); Arrays.asList(new ConditionParams("artini giuseppe", null))).verifyEvent(this.event));
assertTrue((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY, Arrays.asList(new ConditionParams("artini", null)))) assertTrue(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY, Arrays.asList(new ConditionParams("artini", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL, assertFalse(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL,
Arrays.asList(new ConditionParams("artini giuseppe", null)))).verifyEvent(this.event)); Arrays.asList(new ConditionParams("artini giuseppe", null))).verifyEvent(this.event));
assertFalse((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL, Arrays.asList(new ConditionParams("giuseppe", null)))) assertFalse(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL, Arrays.asList(new ConditionParams("giuseppe", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
assertFalse((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL, assertFalse(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ALL,
Arrays.asList(new ConditionParams("bardi claudio", null)))).verifyEvent(this.event)); Arrays.asList(new ConditionParams("bardi claudio", null))).verifyEvent(this.event));
assertFalse((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY, assertFalse(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY,
Arrays.asList(new ConditionParams("andrea mannocci", null)))).verifyEvent(this.event)); Arrays.asList(new ConditionParams("andrea mannocci", null))).verifyEvent(this.event));
assertFalse((new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY, Arrays.asList(new ConditionParams("mannocci", null)))) assertFalse(new MapCondition("authors", MapValueType.LIST_STRING, ConditionOperator.MATCH_ANY, Arrays.asList(new ConditionParams("mannocci", null)))
.verifyEvent(this.event)); .verifyEvent(this.event));
} }
} }

View File

@ -1,26 +1,19 @@
package eu.dnetlib.broker.common.utils; package eu.dnetlib.broker.common.utils;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import eu.dnetlib.broker.common.utils.MapValue;
import eu.dnetlib.broker.common.utils.MapValueType;
public class MapValueTest { public class MapValueTest {
@Before
public void setUp() throws Exception {}
@Test @Test
public void test_null_value() { public void test_null_value() {
final MapValue v = new MapValue(MapValueType.STRING, null); final MapValue v = new MapValue(MapValueType.STRING, null);

View File

@ -19,7 +19,31 @@
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

View File

@ -135,6 +135,12 @@
<artifactId>mockito-junit-jupiter</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>