Skip to content

Commit b71ddce

Browse files
justinleetleet
authored and
leet
committed
METRON-2307 Migrate to JUnit5 (justinleet) closes #1554
1 parent 83effe4 commit b71ddce

File tree

447 files changed

+9644
-10623
lines changed

Some content is hidden

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

447 files changed

+9644
-10623
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ matrix:
6060

6161
- name: Verify Licenses
6262
script:
63+
- time mvn install -T 2C -q -DskipTests=true -Dmaven.javadoc.skip=true -B -V -Dskip.npm
6364
- time ./dev-utilities/build-utils/verify_licenses.sh
6465

6566
before_cache:

dependencies_with_url.csv

+11-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ javax.xml.bind:jaxb-api:jar:2.2.2:compile,CDDL,https://jaxb.dev.java.net/
5050
javax.xml.bind:jaxb-api:jar:2.3.0:compile,CDDL,https://jaxb.dev.java.net/
5151
javax.xml.stream:stax-api:jar:1.0-2:compile,COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0,https://docs.oracle.com/javase/7/docs/api/javax/xml/stream/package-summary.html
5252
jline:jline:jar:0.9.94:compile,BSD,http://jline.sourceforge.net
53+
junit:junit:jar:3.8.1:compile,Common Public License Version 1.0,http://junit.org
54+
junit:junit:jar:4.10:compile,Common Public License Version 1.0,http://junit.org
55+
junit:junit:jar:4.11:compile,Common Public License Version 1.0,http://junit.org
5356
junit:junit:jar:4.12:compile,Eclipse Public License 1.0,http://junit.org
5457
net.razorvine:pyrolite:jar:4.13:compile,MIT,https://github.com/irmen/Pyrolite
5558
net.sf.jopt-simple:jopt-simple:jar:3.2:compile,The MIT License,http://jopt-simple.sourceforge.net
@@ -77,7 +80,7 @@ org.jruby.joni:joni:jar:2.1.2:compile,MIT License,https://github.com/jruby/joni
7780
org.lz4:lz4-java:jar:1.4.0:compile,ASLv2,https://github.com/lz4/lz4-java
7881
org.mitre.taxii:taxii:jar:1.1.0.1:compile,The BSD 3-Clause License,https://github.com/TAXIIProject/java-taxii
7982
org.mitre:stix:jar:1.2.0.2:compile,The BSD 3-Clause License,https://github.com/STIXProject/java-stix
80-
org.mockito:mockito-core:jar:1.10.19:compile,The MIT License,http://www.mockito.org
83+
org.mockito:mockito-core:jar:3.1.0:compile,The MIT License,http://www.mockito.org
8184
org.roaringbitmap:RoaringBitmap:jar:0.5.11:compile,ASLv2,https://github.com/RoaringBitmap/RoaringBitmap
8285
org.scala-lang:scala-library:jar:2.10.6:compile,BSD-like,http://www.scala-lang.org/
8386
org.scala-lang.modules:scala-parser-combinators_2.11:jar:1.0.4:compile,BSD-like,http://www.scala-lang.org/
@@ -503,3 +506,10 @@ org.elasticsearch:securesm:jar:1.2:compile
503506
com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile,ASLv2,http://stephenc.github.io/jcip-annotations/
504507
com.nimbusds:nimbus-jose-jwt:jar:4.41.2:compile,ASLv2,https://bitbucket.org/connect2id/nimbus-jose-jwt/wiki/Home
505508
tomcat:jasper-compiler:jar:5.5.23:compile,ASLv2,https://tomcat.apache.org/
509+
org.apiguardian:apiguardian-api:jar:1.1.0:compile,ASLv2,https://github.com/apiguardian-team/apiguardian/blob/master/LICENSE
510+
org.junit.jupiter:junit-jupiter-api:jar:5.5.2:compile,EPL 2.0,https://junit.org
511+
org.junit.platform:junit-platform-engine:jar:1.5.2:compile,EPL 2.0,https://junit.org
512+
org.junit.platform:junit-platform-commons:jar:1.5.2:compile,EPL 2.0,https://junit.org
513+
net.bytebuddy:byte-buddy-agent:jar:1.9.10:compile,ASLv2,https://bytebuddy.net/
514+
net.bytebuddy:byte-buddy:jar:1.9.10:compile,ASLv2,https://bytebuddy.net/
515+
org.objenesis:objenesis:jar:2.6:compile,ASLv2,http://objenesis.org/license.html

metron-analytics/metron-maas-common/src/test/java/org/apache/metron/maas/discovery/ServiceDiscoveryIntegrationTest.java

+19-18
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,22 @@
2929
import org.apache.metron.maas.config.Endpoint;
3030
import org.apache.metron.maas.config.Model;
3131
import org.apache.metron.maas.config.ModelEndpoint;
32-
import org.junit.After;
33-
import org.junit.Assert;
34-
import org.junit.Before;
35-
import org.junit.Test;
32+
import org.junit.jupiter.api.AfterEach;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
3635

3736
import java.net.URL;
3837
import java.util.concurrent.atomic.AtomicInteger;
3938

39+
import static org.junit.jupiter.api.Assertions.assertEquals;
40+
4041
public class ServiceDiscoveryIntegrationTest {
4142
private TestingServer testZkServer;
4243
private String zookeeperUrl;
4344
private CuratorFramework client;
4445
private ServiceDiscoverer discoverer;
4546

46-
@Before
47+
@BeforeEach
4748
public void setup() throws Exception {
4849
testZkServer = new TestingServer(true);
4950
zookeeperUrl = testZkServer.getConnectString();
@@ -93,31 +94,31 @@ public void testDiscovery() throws Exception {
9394
//wait for zk to percolate the changes.
9495
Thread.sleep(2000);
9596

96-
Assert.assertEquals(3, discoverer.getEndpoints(new Model("casey", "3.14159")).size());
97-
Assert.assertEquals(1, discoverer.getEndpoints(new Model("casey", "3.1416")).size());
98-
Assert.assertEquals(0, discoverer.getEndpoints(new Model("casey", "3.17")).size());
97+
assertEquals(3, discoverer.getEndpoints(new Model("casey", "3.14159")).size());
98+
assertEquals(1, discoverer.getEndpoints(new Model("casey", "3.1416")).size());
99+
assertEquals(0, discoverer.getEndpoints(new Model("casey", "3.17")).size());
99100

100101
discoverer.unregisterByContainer("1");
101102
Thread.sleep(2000);
102-
Assert.assertEquals(2, discoverer.getEndpoints(new Model("casey", "3.14159")).size());
103-
Assert.assertEquals(1, discoverer.getEndpoints(new Model("casey", "3.1416")).size());
104-
Assert.assertEquals(0, discoverer.getEndpoints(new Model("casey", "3.17")).size());
103+
assertEquals(2, discoverer.getEndpoints(new Model("casey", "3.14159")).size());
104+
assertEquals(1, discoverer.getEndpoints(new Model("casey", "3.1416")).size());
105+
assertEquals(0, discoverer.getEndpoints(new Model("casey", "3.17")).size());
105106

106-
Assert.assertEquals(2, discoverer.listEndpoints(new Model("casey", null)).keySet().size());
107-
Assert.assertEquals(1, discoverer.listEndpoints(new Model("casey", "3.1416")).keySet().size());
108-
Assert.assertEquals(1, discoverer.listEndpoints(new Model("casey", "3.1416"))
107+
assertEquals(2, discoverer.listEndpoints(new Model("casey", null)).keySet().size());
108+
assertEquals(1, discoverer.listEndpoints(new Model("casey", "3.1416")).keySet().size());
109+
assertEquals(1, discoverer.listEndpoints(new Model("casey", "3.1416"))
109110
.get(new Model("casey", "3.1416")).size()
110111
);
111-
Assert.assertEquals("4", discoverer.listEndpoints(new Model("casey", "3.1416"))
112+
assertEquals("4", discoverer.listEndpoints(new Model("casey", "3.1416"))
112113
.get(new Model("casey", "3.1416"))
113114
.get(0)
114115
.getContainerId()
115116
);
116-
Assert.assertEquals(0, discoverer.listEndpoints(new Model("casey", "3.17")).keySet().size());
117-
Assert.assertEquals(0, discoverer.listEndpoints(new Model("dummy", null)).keySet().size());
117+
assertEquals(0, discoverer.listEndpoints(new Model("casey", "3.17")).keySet().size());
118+
assertEquals(0, discoverer.listEndpoints(new Model("dummy", null)).keySet().size());
118119

119120
}
120-
@After
121+
@AfterEach
121122
public void teardown() throws Exception {
122123

123124
if(discoverer != null) {

metron-analytics/metron-maas-service/src/test/java/org/apache/metron/maas/service/MaasIntegrationTest.java

+35-33
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,17 @@
1616
* limitations under the License.
1717
*/
1818
package org.apache.metron.maas.service;
19-
import java.io.*;
20-
import java.net.HttpURLConnection;
21-
import java.net.InetAddress;
22-
import java.net.URL;
23-
import java.nio.charset.StandardCharsets;
24-
import java.util.*;
25-
import java.util.concurrent.atomic.AtomicBoolean;
26-
import java.util.logging.Level;
2719

2820
import com.google.common.base.Splitter;
2921
import com.google.common.collect.Iterables;
30-
import org.apache.hadoop.fs.FileSystem;
3122
import org.apache.commons.logging.Log;
3223
import org.apache.commons.logging.LogFactory;
3324
import org.apache.curator.RetryPolicy;
3425
import org.apache.curator.framework.CuratorFramework;
3526
import org.apache.curator.framework.CuratorFrameworkFactory;
3627
import org.apache.curator.retry.ExponentialBackoffRetry;
3728
import org.apache.hadoop.conf.Configuration;
29+
import org.apache.hadoop.fs.FileSystem;
3830
import org.apache.hadoop.fs.Path;
3931
import org.apache.hadoop.net.NetUtils;
4032
import org.apache.hadoop.util.Shell;
@@ -45,20 +37,30 @@
4537
import org.apache.metron.integration.ComponentRunner;
4638
import org.apache.metron.integration.components.YarnComponent;
4739
import org.apache.metron.integration.components.ZKServerComponent;
48-
import org.apache.metron.maas.discovery.ServiceDiscoverer;
4940
import org.apache.metron.maas.config.MaaSConfig;
5041
import org.apache.metron.maas.config.Model;
5142
import org.apache.metron.maas.config.ModelEndpoint;
43+
import org.apache.metron.maas.discovery.ServiceDiscoverer;
5244
import org.apache.metron.maas.queue.ZKQueue;
5345
import org.apache.metron.maas.submit.ModelSubmission;
5446
import org.apache.metron.maas.util.ConfigUtil;
5547
import org.apache.metron.test.utils.UnitTestHelper;
5648
import org.apache.zookeeper.KeeperException;
57-
import org.junit.After;
58-
import org.junit.AfterClass;
59-
import org.junit.Assert;
60-
import org.junit.BeforeClass;
61-
import org.junit.Test;
49+
import org.junit.jupiter.api.*;
50+
51+
import java.io.*;
52+
import java.net.HttpURLConnection;
53+
import java.net.InetAddress;
54+
import java.net.URL;
55+
import java.nio.charset.StandardCharsets;
56+
import java.util.ArrayList;
57+
import java.util.Arrays;
58+
import java.util.HashMap;
59+
import java.util.List;
60+
import java.util.concurrent.atomic.AtomicBoolean;
61+
import java.util.logging.Level;
62+
63+
import static org.junit.jupiter.api.Assertions.*;
6264

6365
public class MaasIntegrationTest {
6466
private static final Log LOG =
@@ -68,7 +70,7 @@ public class MaasIntegrationTest {
6870
private static YarnComponent yarnComponent;
6971
private static ZKServerComponent zkServerComponent;
7072

71-
@BeforeClass
73+
@BeforeAll
7274
public static void setupBeforeClass() throws Exception {
7375
UnitTestHelper.setJavaLoggingLevel(Level.SEVERE);
7476
LOG.info("Starting up YARN cluster");
@@ -90,25 +92,27 @@ public static void setupBeforeClass() throws Exception {
9092
client.start();
9193
}
9294

93-
@AfterClass
95+
@AfterAll
9496
public static void tearDownAfterClass(){
9597
if(client != null){
9698
client.close();
9799
}
98100
runner.stop();
99101
}
100102

101-
@After
103+
@AfterEach
102104
public void tearDown() {
103105
runner.reset();
104106
}
105107

106-
@Test(timeout=900000)
108+
@Test
109+
@Timeout(900000)
107110
public void testMaaSWithDomain() throws Exception {
108111
testDSShell(true);
109112
}
110113

111-
@Test(timeout=900000)
114+
@Test
115+
@Timeout(900000)
112116
public void testMaaSWithoutDomain() throws Exception {
113117
testDSShell(false);
114118
}
@@ -154,7 +158,7 @@ public void testDSShell(boolean haveDomain) throws Exception {
154158
LOG.info("Initializing DS Client");
155159
final Client client = new Client(new Configuration(conf));
156160
boolean initSuccess = client.init(args);
157-
Assert.assertTrue(initSuccess);
161+
assertTrue(initSuccess);
158162
LOG.info("Running DS Client");
159163
final AtomicBoolean result = new AtomicBoolean(false);
160164
Thread t = new Thread() {
@@ -198,7 +202,7 @@ public void run() {
198202
break;
199203
}
200204
}
201-
Assert.assertTrue(errorMessage, verified);
205+
assertTrue(verified, errorMessage);
202206
FileSystem fs = FileSystem.get(conf);
203207
try {
204208
new ModelSubmission().execute(FileSystem.get(conf)
@@ -234,13 +238,13 @@ public void run() {
234238
}
235239
Thread.sleep(2000);
236240
}
237-
Assert.assertTrue(passed);
241+
assertTrue(passed);
238242
}
239243

240244
{
241245
List<ModelEndpoint> endpoints = discoverer.getEndpoints(new Model("dummy", "1.0"));
242-
Assert.assertNotNull(endpoints);
243-
Assert.assertEquals(1, endpoints.size());
246+
assertNotNull(endpoints);
247+
assertEquals(1, endpoints.size());
244248
}
245249
new ModelSubmission().execute(FileSystem.get(conf)
246250
, new String[]{
@@ -266,7 +270,7 @@ public void run() {
266270
}
267271
Thread.sleep(2000);
268272
}
269-
Assert.assertTrue(passed);
273+
assertTrue(passed);
270274
}
271275
}
272276
finally {
@@ -336,10 +340,8 @@ private boolean checkHostname(String appHostname) throws Exception {
336340
return true;
337341
}
338342

339-
Assert.assertTrue("Unknown format for hostname " + appHostname,
340-
appHostname.contains("/"));
341-
Assert.assertTrue("Unknown format for hostname " + hostname,
342-
hostname.contains("/"));
343+
assertTrue(appHostname.contains("/"), "Unknown format for hostname " + appHostname);
344+
assertTrue(hostname.contains("/"), "Unknown format for hostname " + hostname);
343345

344346
String[] appHostnameParts = appHostname.split("/");
345347
String[] hostnameParts = hostname.split("/");
@@ -395,7 +397,7 @@ private int verifyContainerLog(int containerNum,
395397
break;
396398
}
397399
}
398-
Assert.assertTrue(currentContainerLogFileIndex != -1);
400+
assertTrue(currentContainerLogFileIndex != -1);
399401
File[] containerFiles =
400402
listOfFiles[currentContainerLogFileIndex].listFiles();
401403

@@ -417,7 +419,7 @@ private int verifyContainerLog(int containerNum,
417419
}
418420
} else if (output.getName().trim().equals("stdout")){
419421
if (! Shell.WINDOWS) {
420-
Assert.assertEquals("The current is" + sCurrentLine,
422+
assertEquals("The current is" + sCurrentLine,
421423
expectedContent.get(numOfline), sCurrentLine.trim());
422424
numOfline++;
423425
} else {
@@ -433,7 +435,7 @@ private int verifyContainerLog(int containerNum,
433435
*/
434436
if (Shell.WINDOWS && !count
435437
&& output.getName().trim().equals("stdout")) {
436-
Assert.assertTrue(stdOutContent.containsAll(expectedContent));
438+
assertTrue(stdOutContent.containsAll(expectedContent));
437439
}
438440
} catch (IOException e) {
439441
e.printStackTrace();

0 commit comments

Comments
 (0)