diff --git a/elasticsearch/pom.xml b/elasticsearch/pom.xml
index 1e36a4b1a7c..4e6c90a586f 100644
--- a/elasticsearch/pom.xml
+++ b/elasticsearch/pom.xml
@@ -84,9 +84,8 @@
- org.hamcrest
- hamcrest-all
- ${hamcrest.all.version}
+ org.junit.jupiter
+ junit-jupiter-params
test
diff --git a/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreterTest.java b/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreterTest.java
index a806dc3149f..793c652e7db 100644
--- a/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreterTest.java
+++ b/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreterTest.java
@@ -18,8 +18,8 @@
package org.apache.zeppelin.elasticsearch;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.apache.commons.lang3.RandomUtils;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
@@ -27,13 +27,11 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.experimental.theories.DataPoint;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import java.io.IOException;
import java.util.ArrayList;
@@ -43,6 +41,7 @@
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Stream;
import org.apache.zeppelin.completer.CompletionType;
import org.apache.zeppelin.display.AngularObjectRegistry;
@@ -51,10 +50,9 @@
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
-@RunWith(Theories.class)
public class ElasticsearchInterpreterTest {
- @DataPoint public static ElasticsearchInterpreter transportInterpreter;
- @DataPoint public static ElasticsearchInterpreter httpInterpreter;
+ public static ElasticsearchInterpreter transportInterpreter;
+ public static ElasticsearchInterpreter httpInterpreter;
private static Client elsClient;
private static Node elsNode;
@@ -70,7 +68,7 @@ public class ElasticsearchInterpreterTest {
private static final AtomicInteger deleteId = new AtomicInteger(2);
- @BeforeClass
+ @BeforeAll
public static void populate() throws IOException {
final Settings settings = Settings.settingsBuilder()
.put("cluster.name", ELS_CLUSTER_NAME)
@@ -140,7 +138,7 @@ public static void populate() throws IOException {
httpInterpreter.open();
}
- @AfterClass
+ @AfterAll
public static void clean() {
if (transportInterpreter != null) {
transportInterpreter.close();
@@ -168,8 +166,15 @@ private InterpreterContext buildContext(String noteAndParagraphId) {
.build();
}
- @Theory
- public void testCount(ElasticsearchInterpreter interpreter) {
+ private static Stream provideInterpreter() {
+ return Stream.of(
+ Arguments.of(transportInterpreter),
+ Arguments.of(httpInterpreter));
+ }
+
+ @ParameterizedTest
+ @MethodSource("provideInterpreter")
+ void testCount(ElasticsearchInterpreter interpreter) {
final InterpreterContext ctx = buildContext("testCount");
InterpreterResult res = interpreter.interpret("count /unknown", ctx);
@@ -186,8 +191,9 @@ public void testCount(ElasticsearchInterpreter interpreter) {
assertEquals(Code.SUCCESS, res.code());
}
- @Theory
- public void testGet(ElasticsearchInterpreter interpreter) {
+ @ParameterizedTest
+ @MethodSource("provideInterpreter")
+ void testGet(ElasticsearchInterpreter interpreter) {
final InterpreterContext ctx = buildContext("get");
InterpreterResult res = interpreter.interpret("get /logs/http/unknown", ctx);
@@ -209,8 +215,9 @@ public void testGet(ElasticsearchInterpreter interpreter) {
assertEquals(Code.SUCCESS, res.code());
}
- @Theory
- public void testSearch(ElasticsearchInterpreter interpreter) {
+ @ParameterizedTest
+ @MethodSource("provideInterpreter")
+ void testSearch(ElasticsearchInterpreter interpreter) {
final InterpreterContext ctx = buildContext("search");
InterpreterResult res = interpreter.interpret("size 10\nsearch /logs *", ctx);
@@ -231,8 +238,9 @@ public void testSearch(ElasticsearchInterpreter interpreter) {
assertEquals(Code.SUCCESS, res.code());
}
- @Theory
- public void testAgg(ElasticsearchInterpreter interpreter) {
+ @ParameterizedTest
+ @MethodSource("provideInterpreter")
+ void testAgg(ElasticsearchInterpreter interpreter) {
final InterpreterContext ctx = buildContext("agg");
// Single-value metric
@@ -265,8 +273,9 @@ public void testAgg(ElasticsearchInterpreter interpreter) {
assertEquals(Code.SUCCESS, res.code());
}
- @Theory
- public void testIndex(ElasticsearchInterpreter interpreter) {
+ @ParameterizedTest
+ @MethodSource("provideInterpreter")
+ void testIndex(ElasticsearchInterpreter interpreter) {
InterpreterResult res = interpreter.interpret("index /logs { \"date\": \"" + new Date() +
"\", \"method\": \"PUT\", \"status\": \"500\" }", null);
assertEquals(Code.ERROR, res.code());
@@ -283,8 +292,9 @@ public void testIndex(ElasticsearchInterpreter interpreter) {
assertEquals(Code.SUCCESS, res.code());
}
- @Theory
- public void testDelete(ElasticsearchInterpreter interpreter) {
+ @ParameterizedTest
+ @MethodSource("provideInterpreter")
+ void testDelete(ElasticsearchInterpreter interpreter) {
InterpreterResult res = interpreter.interpret("delete /logs/http/unknown", null);
assertEquals(Code.ERROR, res.code());
@@ -297,8 +307,9 @@ public void testDelete(ElasticsearchInterpreter interpreter) {
assertEquals("" + testDeleteId, res.message().get(0).getData());
}
- @Theory
- public void testMisc(ElasticsearchInterpreter interpreter) {
+ @ParameterizedTest
+ @MethodSource("provideInterpreter")
+ void testMisc(ElasticsearchInterpreter interpreter) {
InterpreterResult res = interpreter.interpret(null, null);
assertEquals(Code.SUCCESS, res.code());
@@ -306,8 +317,9 @@ public void testMisc(ElasticsearchInterpreter interpreter) {
assertEquals(Code.SUCCESS, res.code());
}
- @Theory
- public void testCompletion(ElasticsearchInterpreter interpreter) {
+ @ParameterizedTest
+ @MethodSource("provideInterpreter")
+ void testCompletion(ElasticsearchInterpreter interpreter) {
final List expectedResultOne = Arrays.asList(
new InterpreterCompletion("count", "count", CompletionType.command.name()));
final List expectedResultTwo = Arrays.asList(
@@ -317,13 +329,13 @@ public void testCompletion(ElasticsearchInterpreter interpreter) {
final List resultTwo = interpreter.completion("he", 0, null);
final List resultAll = interpreter.completion("", 0, null);
- Assert.assertEquals(expectedResultOne, resultOne);
- Assert.assertEquals(expectedResultTwo, resultTwo);
+ assertEquals(expectedResultOne, resultOne);
+ assertEquals(expectedResultTwo, resultTwo);
final List allCompletionList = new ArrayList<>();
for (final InterpreterCompletion ic : resultAll) {
allCompletionList.add(ic.getName());
}
- Assert.assertEquals(ElasticsearchInterpreter.COMMANDS, allCompletionList);
+ assertEquals(ElasticsearchInterpreter.COMMANDS, allCompletionList);
}
}
diff --git a/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilderTest.java b/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilderTest.java
index bbf9a51731c..39b019cd112 100644
--- a/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilderTest.java
+++ b/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilderTest.java
@@ -17,69 +17,69 @@
package org.apache.zeppelin.elasticsearch.client;
-import org.junit.Test;
import static org.apache.zeppelin.elasticsearch.client.ElasticsearchClientType.HTTP;
import static org.apache.zeppelin.elasticsearch.client.ElasticsearchClientType.HTTPS;
import static org.apache.zeppelin.elasticsearch.client.ElasticsearchClientType.TRANSPORT;
import static org.apache.zeppelin.elasticsearch.client.ElasticsearchClientType.UNKNOWN;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-public class ElasticsearchClientTypeBuilderTest {
+import org.junit.jupiter.api.Test;
+
+class ElasticsearchClientTypeBuilderTest {
@Test
- public void it_should_return_transport_as_default_value_when_property_is_empty() {
+ void it_should_return_transport_as_default_value_when_property_is_empty() {
//GIVEN
String empty = "";
//WHEN
ElasticsearchClientType clientType =
ElasticsearchClientTypeBuilder.withPropertyValue(empty).build();
//THEN
- assertThat(clientType, is(TRANSPORT));
+ assertEquals(TRANSPORT, clientType);
}
@Test
- public void it_should_return_transport_as_default_value_when_property_is_null() {
+ void it_should_return_transport_as_default_value_when_property_is_null() {
//GIVEN
String nullValue = null;
//WHEN
ElasticsearchClientType clientType =
ElasticsearchClientTypeBuilder.withPropertyValue(nullValue).build();
//THEN
- assertThat(clientType, is(TRANSPORT));
+ assertEquals(TRANSPORT, clientType);
}
@Test
- public void it_should_return_client_type_when_property_value_exists() {
+ void it_should_return_client_type_when_property_value_exists() {
//GIVEN
String clientType = "https";
//WHEN
ElasticsearchClientType esClientType =
ElasticsearchClientTypeBuilder.withPropertyValue(clientType).build();
//THEN
- assertThat(esClientType, is(HTTPS));
+ assertEquals(HTTPS, esClientType);
}
@Test
- public void it_should_return_client_type_and_ignore_case_when_property_value_exists() {
+ void it_should_return_client_type_and_ignore_case_when_property_value_exists() {
//GIVEN
String clientType = "hTtP";
//WHEN
ElasticsearchClientType esClientType =
ElasticsearchClientTypeBuilder.withPropertyValue(clientType).build();
//THEN
- assertThat(esClientType, is(HTTP));
+ assertEquals(HTTP, esClientType);
}
@Test
- public void it_should_return_unknown_when_property_value_does_not_exist() {
+ void it_should_return_unknown_when_property_value_does_not_exist() {
//GIVEN
String unknownValue = "an_unknown_value";
//WHEN
ElasticsearchClientType esClientType =
ElasticsearchClientTypeBuilder.withPropertyValue(unknownValue).build();
//THEN
- assertThat(esClientType, is(UNKNOWN));
+ assertEquals(UNKNOWN, esClientType);
}
}
diff --git a/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeTest.java b/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeTest.java
index 21deb4cf2fa..9ff921627bb 100644
--- a/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeTest.java
+++ b/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeTest.java
@@ -17,19 +17,19 @@
package org.apache.zeppelin.elasticsearch.client;
-import org.junit.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import org.junit.jupiter.api.Test;
-public class ElasticsearchClientTypeTest {
+class ElasticsearchClientTypeTest {
@Test
- public void it_should_return_http_when_reducing_on_http_types() {
+ void it_should_return_http_when_reducing_on_http_types() {
//GIVEN
List httpTypes =
new ArrayList<>(Arrays.asList(ElasticsearchClientType.HTTP, ElasticsearchClientType.HTTPS));
@@ -38,6 +38,6 @@ public void it_should_return_http_when_reducing_on_http_types() {
.map(ElasticsearchClientType::isHttp)
.reduce(true, (ident, elasticsearchClientType) -> ident && elasticsearchClientType);
//THEN
- assertThat(httpTypesReduced, is(true));
+ assertTrue(httpTypesReduced);
}
}