Skip to content

Commit ca607f4

Browse files
[CYB-223] upgrade all junit tests to use junit 5
* Upgrade all JUnit tests from JUnit 4 to JUnit 5 - Converted 89 JUnit 4 test files to JUnit 5 Jupiter format - Updated imports: org.junit.* → org.junit.jupiter.api.* - Converted annotations: @BeforeClass → @BeforeAll, @afterclass@afterall - Updated assertions: Assert.* → Assertions.* - Fixed hamcrest imports: MatcherAssertions → MatcherAssert - Removed JUnit 4 dependencies from parent and all 24+ child module POMs - Added JUnit 5 Jupiter dependencies with proper version management - Cleaned up JUnit dependencies from plugin sections - Fixed test scope dependencies in metron-enrichment-common - Verified JUnit 5 migration with standalone test All 330 test files now use JUnit 5 Jupiter. JUnit 4 dependencies completely removed from the project. Co-authored-by: openhands <[email protected]> * Fix JUnit 5 migration build failures - Add JUnit 5 dependencies to parent pom.xml with proper version management - Add JUnit 5 dependencies to cyber-functions and flink-common modules - Update Maven compiler plugin to 3.11.0 for better Java compatibility - Configure Maven Surefire plugin for JUnit 5 support - Update Lombok version to 1.18.30 for compatibility - Fix JUnit 5 assertion parameter order in GeneratorScenarioTest.java Co-authored-by: openhands <[email protected]> * Correct build and unit test errors * Correct build and unit test errors * Enable HbaseBatchEnrichmentCSVLoaderTest * Remove duplicate junit.jupiter dependency --------- Co-authored-by: openhands <[email protected]>
1 parent e98e313 commit ca607f4

File tree

135 files changed

+808
-701
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+808
-701
lines changed

flink-cyber/caracal-generator/pom.xml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@
3939
<artifactId>flink-connector-kafka</artifactId>
4040
</dependency>
4141

42-
<dependency>
43-
<groupId>org.apache.flink</groupId>
44-
<artifactId>flink-clients</artifactId>
45-
<scope>provided</scope>
46-
<version>${flink.version}</version>
47-
</dependency>
48-
4942
<dependency>
5043
<groupId>com.hortonworks.smm</groupId>
5144
<artifactId>monitoring-interceptors</artifactId>
@@ -87,7 +80,6 @@
8780
<scope>provided</scope>
8881
</dependency>
8982

90-
9183
<dependency>
9284
<groupId>com.cloudera.cyber</groupId>
9385
<artifactId>flink-logging</artifactId>
@@ -96,14 +88,14 @@
9688
</dependency>
9789

9890
<dependency>
99-
<groupId>junit</groupId>
100-
<artifactId>junit</artifactId>
101-
<scope>test</scope>
91+
<groupId>com.fasterxml.jackson.core</groupId>
92+
<artifactId>jackson-databind</artifactId>
10293
</dependency>
10394

10495
<dependency>
105-
<groupId>com.fasterxml.jackson.core</groupId>
106-
<artifactId>jackson-databind</artifactId>
96+
<groupId>org.junit.jupiter</groupId>
97+
<artifactId>junit-jupiter</artifactId>
98+
<scope>test</scope>
10799
</dependency>
108100

109101
<dependency>
@@ -119,13 +111,6 @@
119111
<scope>test</scope>
120112
</dependency>
121113

122-
<dependency>
123-
<groupId>com.salesforce.kafka.test</groupId>
124-
<artifactId>kafka-junit4</artifactId>
125-
<version>3.2.1</version>
126-
<scope>test</scope>
127-
</dependency>
128-
129114
<dependency>
130115
<groupId>org.apache.kafka</groupId>
131116
<artifactId>kafka_${scala.binary.version}</artifactId>

flink-cyber/caracal-generator/src/test/java/com/cloudera/cyber/test/GeneratorTests.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
import com.fasterxml.jackson.databind.type.MapType;
1818
import com.fasterxml.jackson.databind.type.TypeFactory;
1919
import freemarker.template.TemplateException;
20-
import org.junit.Assert;
21-
import org.junit.Test;
20+
import org.junit.jupiter.api.Assertions;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.Timeout;
2223

2324
import java.io.IOException;
2425
import java.net.URISyntaxException;
2526
import java.util.HashMap;
2627
import java.util.List;
2728
import java.util.Map;
29+
import java.util.concurrent.TimeUnit;
2830

2931
import static org.hamcrest.CoreMatchers.equalTo;
3032
import static org.hamcrest.CoreMatchers.notNullValue;
@@ -74,7 +76,8 @@ public void testNetflowHttp() throws IOException, TemplateException {
7476
}
7577

7678

77-
@Test(timeout = 1000)
79+
@Test
80+
@Timeout(value = 1, unit = TimeUnit.SECONDS)
7881
public void testBulkProduction10000eps() throws IOException, TemplateException {
7982
FreemarkerImmediateGenerator generator = new FreemarkerImmediateGenerator();
8083
for (int i = 0; i < 10000; i++) {
@@ -86,12 +89,12 @@ public void testBulkProduction10000eps() throws IOException, TemplateException {
8689
private Map<String, Object> testFile(String file) throws IOException, TemplateException {
8790
FreemarkerImmediateGenerator generator = new FreemarkerImmediateGenerator();
8891
String result = generator.generateEntry(file);
89-
Assert.assertNotNull(result);
92+
Assertions.assertNotNull(result);
9093
ObjectMapper mapper = new ObjectMapper();
9194
TypeFactory typeFactory = mapper.getTypeFactory();
9295
MapType mapType = typeFactory.constructMapType(HashMap.class, String.class, Object.class);
9396
Map<String, Object> output = mapper.readValue(result, mapType);
94-
Assert.assertNotNull(output);
97+
Assertions.assertNotNull(output);
9598
return output;
9699
}
97100

flink-cyber/caracal-generator/src/test/java/com/cloudera/cyber/test/RandomGeneratorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
package com.cloudera.cyber.test;
1414

1515
import com.cloudera.cyber.generator.RandomGenerators;
16-
import org.junit.Test;
16+
import org.junit.jupiter.api.Test;
1717

18-
import static org.junit.Assert.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

2020
public class RandomGeneratorTests {
2121

flink-cyber/caracal-generator/src/test/java/com/cloudera/cyber/test/TestCaracalGeneratorJob.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
2121
import org.apache.flink.test.util.CollectingSink;
2222
import org.apache.flink.test.util.JobTester;
23-
import org.junit.Assert;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.Test;
2525

2626
import java.time.Duration;
2727
import java.util.*;
@@ -101,7 +101,7 @@ private void checkGeneratedResults(int expectedCount, List<String> expectedTopic
101101
for (int i = 0; i < expectedCount; i++) {
102102
Tuple2<String, byte[]> generatedRecord = sink.poll(Duration.ofMillis(100));
103103
String actualTopic = generatedRecord.f0;
104-
Assert.assertTrue(String.format("Generated topic '%s' is not in expected topics '%s'", actualTopic, expectedTopics), expectedTopics.contains(actualTopic));
104+
Assertions.assertTrue(expectedTopics.contains(actualTopic),String.format("Generated topic '%s' is not in expected topics '%s'", actualTopic, expectedTopics));
105105
results.add(generatedRecord);
106106
}
107107

flink-cyber/caracal-generator/src/test/java/com/cloudera/cyber/test/ThreatGeneratorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
import com.cloudera.cyber.generator.ThreatGenerator;
1616
import freemarker.template.TemplateException;
17-
import org.junit.Test;
17+
import org.junit.jupiter.api.Test;
1818

1919
import java.io.IOException;
2020

2121
import static org.hamcrest.Matchers.containsString;
22-
import static org.junit.Assert.assertThat;
22+
import static org.hamcrest.MatcherAssert.assertThat;
2323

2424
public class ThreatGeneratorTest {
2525

flink-cyber/caracal-parser/pom.xml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,30 @@
141141
<scope>provided</scope>
142142
</dependency>
143143

144+
<dependency>
145+
<groupId>org.junit.jupiter</groupId>
146+
<artifactId>junit-jupiter</artifactId>
147+
<scope>test</scope>
148+
</dependency>
149+
150+
<dependency>
151+
<groupId>org.junit.jupiter</groupId>
152+
<artifactId>junit-jupiter-engine</artifactId>
153+
<scope>test</scope>
154+
</dependency>
144155

145156
<dependency>
146157
<groupId>org.apache.flink</groupId>
147158
<artifactId>flink-test-utils</artifactId>
148159
<scope>test</scope>
149160
</dependency>
150161

162+
<dependency>
163+
<groupId>org.hamcrest</groupId>
164+
<artifactId>hamcrest</artifactId>
165+
<scope>test</scope>
166+
</dependency>
167+
151168
<dependency>
152169
<groupId>org.apache.flink</groupId>
153170
<artifactId>flink-sequence-file</artifactId>
@@ -189,15 +206,11 @@
189206
</exclusions>
190207
</dependency>
191208

192-
<dependency>
193-
<groupId>junit</groupId>
194-
<artifactId>junit</artifactId>
195-
<scope>test</scope>
196-
</dependency>
197209
<dependency>
198210
<groupId>org.adrianwalker</groupId>
199211
<artifactId>multiline-string</artifactId>
200212
</dependency>
213+
201214
</dependencies>
202215

203216
<build>
@@ -255,6 +268,22 @@
255268
</execution>
256269
</executions>
257270
</plugin>
271+
272+
<plugin>
273+
<groupId>org.apache.maven.plugins</groupId>
274+
<artifactId>maven-surefire-plugin</artifactId>
275+
<version>${maven-surefire-plugin.version}</version>
276+
<configuration>
277+
<useSystemClassLoader>false</useSystemClassLoader>
278+
</configuration>
279+
<dependencies>
280+
<dependency>
281+
<groupId>org.junit.jupiter</groupId>
282+
<artifactId>junit-jupiter-engine</artifactId>
283+
<version>${junit5.version}</version>
284+
</dependency>
285+
</dependencies>
286+
</plugin>
258287
</plugins>
259288
</build>
260289
</project>

flink-cyber/caracal-parser/src/test/java/com/cloudera/cyber/caracal/ParserChainMapFunctionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import lombok.NonNull;
1919
import org.adrianwalker.multilinestring.Multiline;
2020
import org.apache.flink.api.java.utils.ParameterTool;
21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import java.security.KeyPair;
2424
import java.security.KeyPairGenerator;

flink-cyber/caracal-parser/src/test/java/com/cloudera/cyber/caracal/SplittingFlatMapFunctionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.cloudera.cyber.TestUtils;
1717
import org.apache.flink.configuration.Configuration;
1818
import org.apache.flink.util.Collector;
19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import java.security.KeyPair;
2222
import java.security.KeyPairGenerator;

flink-cyber/caracal-parser/src/test/java/com/cloudera/cyber/caracal/TestSplitJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.apache.flink.test.util.CollectingSink;
2626
import org.apache.flink.test.util.JobTester;
2727
import org.apache.flink.test.util.ManualSource;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

3030
import java.io.IOException;
3131
import java.security.KeyPair;

flink-cyber/cyber-functions/pom.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<scope>compile</scope>
3131
</dependency>
3232

33-
3433
<dependency>
3534
<groupId>org.apache.flink</groupId>
3635
<artifactId>flink-table-common</artifactId>
@@ -61,13 +60,13 @@
6160
</dependency>
6261

6362
<dependency>
64-
<groupId>junit</groupId>
65-
<artifactId>junit</artifactId>
63+
<groupId>org.hamcrest</groupId>
64+
<artifactId>hamcrest</artifactId>
6665
<scope>test</scope>
6766
</dependency>
6867
<dependency>
69-
<groupId>org.hamcrest</groupId>
70-
<artifactId>hamcrest</artifactId>
68+
<groupId>org.junit.jupiter</groupId>
69+
<artifactId>junit-jupiter</artifactId>
7170
<scope>test</scope>
7271
</dependency>
7372
<dependency>
@@ -80,7 +79,7 @@
8079
<artifactId>lombok</artifactId>
8180
<scope>compile</scope>
8281
</dependency>
82+
8383
</dependencies>
8484

85-
8685
</project>

0 commit comments

Comments
 (0)