This is an automated email from the ASF dual-hosted git repository.
pdallig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 6181bfe42e [ZEPPELIN-5954] migrate elasticsearch to Junit5 (#4648)
6181bfe42e is described below
commit 6181bfe42e06c2203e92d776357584eada313ac1
Author: Philipp Dallig <[email protected]>
AuthorDate: Mon Sep 11 11:01:25 2023 +0200
[ZEPPELIN-5954] migrate elasticsearch to Junit5 (#4648)
---
elasticsearch/pom.xml | 5 +-
.../ElasticsearchInterpreterTest.java | 78 +++++++++++++---------
.../client/ElasticsearchClientTypeBuilderTest.java | 28 ++++----
.../client/ElasticsearchClientTypeTest.java | 12 ++--
4 files changed, 67 insertions(+), 56 deletions(-)
diff --git a/elasticsearch/pom.xml b/elasticsearch/pom.xml
index 1e36a4b1a7..4e6c90a586 100644
--- a/elasticsearch/pom.xml
+++ b/elasticsearch/pom.xml
@@ -84,9 +84,8 @@
</dependency>
<dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <version>${hamcrest.all.version}</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
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 a806dc3149..793c652e7d 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.client.Client;
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.List;
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;
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 class ElasticsearchInterpreterTest {
httpInterpreter.open();
}
- @AfterClass
+ @AfterAll
public static void clean() {
if (transportInterpreter != null) {
transportInterpreter.close();
@@ -168,8 +166,15 @@ public class ElasticsearchInterpreterTest {
.build();
}
- @Theory
- public void testCount(ElasticsearchInterpreter interpreter) {
+ private static Stream<Arguments> 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 class ElasticsearchInterpreterTest {
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 class ElasticsearchInterpreterTest {
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 class ElasticsearchInterpreterTest {
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 class ElasticsearchInterpreterTest {
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 class ElasticsearchInterpreterTest {
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 class ElasticsearchInterpreterTest {
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 class ElasticsearchInterpreterTest {
assertEquals(Code.SUCCESS, res.code());
}
- @Theory
- public void testCompletion(ElasticsearchInterpreter interpreter) {
+ @ParameterizedTest
+ @MethodSource("provideInterpreter")
+ void testCompletion(ElasticsearchInterpreter interpreter) {
final List<InterpreterCompletion> expectedResultOne = Arrays.asList(
new InterpreterCompletion("count", "count",
CompletionType.command.name()));
final List<InterpreterCompletion> expectedResultTwo = Arrays.asList(
@@ -317,13 +329,13 @@ public class ElasticsearchInterpreterTest {
final List<InterpreterCompletion> resultTwo = interpreter.completion("he",
0, null);
final List<InterpreterCompletion> resultAll = interpreter.completion("",
0, null);
- Assert.assertEquals(expectedResultOne, resultOne);
- Assert.assertEquals(expectedResultTwo, resultTwo);
+ assertEquals(expectedResultOne, resultOne);
+ assertEquals(expectedResultTwo, resultTwo);
final List<String> 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 bbf9a51731..39b019cd11 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 21deb4cf2f..9ff921627b 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<ElasticsearchClientType> httpTypes =
new ArrayList<>(Arrays.asList(ElasticsearchClientType.HTTP,
ElasticsearchClientType.HTTPS));
@@ -38,6 +38,6 @@ public class ElasticsearchClientTypeTest {
.map(ElasticsearchClientType::isHttp)
.reduce(true, (ident, elasticsearchClientType) -> ident &&
elasticsearchClientType);
//THEN
- assertThat(httpTypesReduced, is(true));
+ assertTrue(httpTypesReduced);
}
}