iterator = mock(Iterator.class);
// We want to make sure ColumnIterator will return exactly what the real iterator gives it. Let's us doctor mock iteracor to return items in a particular order.
@@ -79,10 +79,10 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
int i = 0;
while (columnIterator.hasNext()) {
String value = columnIterator.next();
- Assert.assertEquals(values[i++], value);
+ Assertions.assertEquals(values[i++], value);
}
// We should get back exactly as many items as were in the real iterator, no more no less
- Assert.assertEquals(3, i);
+ Assertions.assertEquals(3, i);
// this should be called only once!
verify(collection, times(1)).iterator();
@@ -127,10 +127,10 @@ public Cell answer(InvocationOnMock invocation)
int i = 0;
while (columnIterator.hasNext()) {
String value = columnIterator.next();
- Assert.assertEquals(qualifiers[i++], value);
+ Assertions.assertEquals(qualifiers[i++], value);
}
// We should get back exactly as many items as were in the real iterator, no more no less
- Assert.assertEquals(3, i);
+ Assertions.assertEquals(3, i);
// this should be called only once!
verify(list, times(1)).iterator();
diff --git a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/HBaseRangerAuthorizationTest.java b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/HBaseRangerAuthorizationTest.java
index 0d05e0f234..fda6041c27 100644
--- a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/HBaseRangerAuthorizationTest.java
+++ b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/HBaseRangerAuthorizationTest.java
@@ -48,8 +48,8 @@
import org.apache.hadoop.hbase.security.access.UserPermission;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.security.UserGroupInformation;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -82,14 +82,14 @@
*
* http://localhost:6080/service/plugins/policies/download/cl1_hbase
*/
-@org.junit.Ignore
+@org.junit.jupiter.api.Disabled
public class HBaseRangerAuthorizationTest {
private static final Logger LOG = LoggerFactory.getLogger(HBaseRangerAuthorizationTest.class.getName());
private static int port;
private static HBaseTestingUtility utility;
- @org.junit.BeforeClass
+ @org.junit.jupiter.api.BeforeAll
public static void setup() throws Exception {
port = getFreePort();
@@ -215,7 +215,7 @@ public static void setup() throws Exception {
conn.close();
}
- @org.junit.AfterClass
+ @org.junit.jupiter.api.AfterAll
public static void cleanup() throws Exception {
utility.shutdownMiniCluster();
}
@@ -234,7 +234,7 @@ public void testReadTablesAsProcessOwner() throws Exception {
for (TableDescriptor desc : tableDescriptors) {
LOG.info("Found table:[" + desc.getTableName().getNameAsString() + "]");
}
- Assert.assertEquals(6, tableDescriptors.size());
+ Assertions.assertEquals(6, tableDescriptors.size());
conn.close();
}
@@ -259,7 +259,7 @@ public Void run() throws Exception {
for (TableDescriptor desc : tableDescriptors) {
LOG.info("Found table:[" + desc.getTableName().getNameAsString() + "]");
}
- Assert.assertEquals(0, tableDescriptors.size());
+ Assertions.assertEquals(0, tableDescriptors.size());
conn.close();
return null;
@@ -300,7 +300,7 @@ public Void run() throws Exception {
try {
admin.disableTable(TableName.valueOf("temp2"));
admin.deleteTable(TableName.valueOf("temp2"));
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -333,7 +333,7 @@ public void testReadRowAsProcessOwner() throws Exception {
Get get = new Get(Bytes.toBytes("row1"));
Result result = table.get(get);
byte[] valResult = result.getValue(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"));
- Assert.assertTrue(Arrays.equals(valResult, Bytes.toBytes("val1")));
+ Assertions.assertTrue(Arrays.equals(valResult, Bytes.toBytes("val1")));
conn.close();
}
@@ -357,7 +357,7 @@ public Void run() throws Exception {
Get get = new Get(Bytes.toBytes("row1"));
Result result = table.get(get);
byte[] valResult = result.getValue(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"));
- Assert.assertTrue(Arrays.equals(valResult, Bytes.toBytes("val1")));
+ Assertions.assertTrue(Arrays.equals(valResult, Bytes.toBytes("val1")));
conn.close();
return null;
@@ -386,7 +386,7 @@ public Void run() throws Exception {
Get get = new Get(Bytes.toBytes("row1"));
Result result = table.get(get);
byte[] valResult = result.getValue(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"));
- Assert.assertNull("Failure expected on an unauthorized user", valResult);
+ Assertions.assertNull(valResult, "Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -411,7 +411,7 @@ public void testReadRowFromColFam2AsProcessOwner() throws Exception {
Get get = new Get(Bytes.toBytes("row1"));
Result result = table.get(get);
byte[] valResult = result.getValue(Bytes.toBytes("colfam2"), Bytes.toBytes("col1"));
- Assert.assertTrue(Arrays.equals(valResult, Bytes.toBytes("val2")));
+ Assertions.assertTrue(Arrays.equals(valResult, Bytes.toBytes("val2")));
conn.close();
}
@@ -435,7 +435,7 @@ public Void run() throws Exception {
Get get = new Get(Bytes.toBytes("row1"));
Result result = table.get(get);
byte[] valResult = result.getValue(Bytes.toBytes("colfam2"), Bytes.toBytes("col1"));
- Assert.assertNull(valResult);
+ Assertions.assertNull(valResult);
conn.close();
return null;
@@ -507,7 +507,7 @@ public Void run() throws Exception {
Put put = new Put(Bytes.toBytes("row3"));
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"), Bytes.toBytes("val2"));
table.put(put);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -538,7 +538,7 @@ public Void run() throws Exception {
Put put = new Put(Bytes.toBytes("row3"));
put.addColumn(Bytes.toBytes("colfam2"), Bytes.toBytes("col1"), Bytes.toBytes("val2"));
table.put(put);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -578,7 +578,7 @@ public void testReadRowInAnotherTable() throws Exception {
Get get = new Get(Bytes.toBytes("row1"));
Result result = table.get(get);
byte[] valResult = result.getValue(Bytes.toBytes("colfam2"), Bytes.toBytes("col1"));
- Assert.assertNull(valResult);
+ Assertions.assertNull(valResult);
conn.close();
@@ -596,7 +596,7 @@ public Void run() throws Exception {
Get get = new Get(Bytes.toBytes("row1"));
Result result = table.get(get);
byte[] valResult = result.getValue(Bytes.toBytes("colfam2"), Bytes.toBytes("col1"));
- Assert.assertNull("Failure expected on an unauthorized user", valResult);
+ Assertions.assertNull(valResult, "Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -664,7 +664,7 @@ public Void run() throws Exception {
// Delete the new row
Delete delete = new Delete(Bytes.toBytes("row5"));
table.delete(delete);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -770,7 +770,7 @@ public Void run() throws Exception {
}
// Clone snapshot
admin.cloneSnapshot("test_snapshot", clone);
- Assert.fail("Failure expected on an unauthorized group public");
+ Assertions.fail("Failure expected on an unauthorized group public");
} catch (Exception e) {
// Expected
}
@@ -811,7 +811,7 @@ public Void run() throws Exception {
try {
admin.createTable(tableDescriptor.build());
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -887,13 +887,13 @@ public Void run() throws Exception {
Get get = new Get(Bytes.toBytes("row1"));
Result result = table.get(get);
byte[] valResult = result.getValue(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"));
- Assert.assertTrue(Arrays.equals(valResult, Bytes.toBytes("val1")));
+ Assertions.assertTrue(Arrays.equals(valResult, Bytes.toBytes("val1")));
// Now try to read the "colfam2" column family of the temp3 table - this should fail
get = new Get(Bytes.toBytes("row1"));
result = table.get(get);
valResult = result.getValue(Bytes.toBytes("colfam2"), Bytes.toBytes("col1"));
- Assert.assertNull(valResult);
+ Assertions.assertNull(valResult);
conn.close();
return null;
@@ -911,7 +911,7 @@ public Void run() throws Exception {
try {
Result result = table.get(get);
byte[] valResult = result.getValue(Bytes.toBytes("colfam2"), Bytes.toBytes("col1"));
- Assert.assertNull("Failure expected on an unauthorized user", valResult);
+ Assertions.assertNull(valResult, "Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -980,7 +980,7 @@ public Void run() throws Exception {
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col2"), Bytes.toBytes("val2"));
try {
table.put(put);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -1002,7 +1002,7 @@ public Void run() throws Exception {
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"), Bytes.toBytes("val2"));
try {
table.put(put);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -1075,7 +1075,7 @@ public void run(AccessControlProtos.GetUserPermissionsResponse message) {
for (AccessControlProtos.UserPermission perm : message
.getUserPermissionList()) {
AccessControlUtil.toUserPermission(perm);
- Assert.fail();
+ Assertions.fail();
}
}
}
@@ -1100,7 +1100,7 @@ public Void run() throws Exception {
}
}
}
- Assert.assertTrue("QA is not found", found);
+ Assertions.assertTrue(found, "QA is not found");
return null;
}
});
@@ -1110,7 +1110,7 @@ public Void run() throws Exception {
getUserPermissions(userPermissions, requestTablePerms, authorizationCoprocessor, rpcController);
Permission p = Permission.newBuilder(TableName.valueOf("temp5")).withActions(Permission.Action.READ, Permission.Action.WRITE, Permission.Action.EXEC).build();
UserPermission userPermission = new UserPermission("@IT", p);
- Assert.assertTrue("@IT permission should be there", userPermissions.contains(userPermission));
+ Assertions.assertTrue(userPermissions.contains(userPermission), "@IT permission should be there");
}
}
@@ -1179,7 +1179,7 @@ public Void run() throws Exception {
Put put = new Put(Bytes.toBytes("row3"));
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"), Bytes.toBytes("val2"));
table.put(put);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -1208,7 +1208,7 @@ public Void run() throws Exception {
Put put = new Put(Bytes.toBytes("row3"));
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"), Bytes.toBytes("val2"));
table.put(put);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -1240,7 +1240,7 @@ public Void run() throws Exception {
numRowsInResult += 1;
}
//while there are 2 rows in this table, one of the columns is explicitly denied so only one column should be in the result
- Assert.assertEquals(1, numRowsInResult);
+ Assertions.assertEquals(1, numRowsInResult);
} catch (IOException ex) {
// expected
}
@@ -1264,7 +1264,7 @@ public Void run() throws Exception {
numRowsInResult += 1;
}
//there are 2 rows in this table, group IT2 does not have any denied columns
- Assert.assertEquals(2, numRowsInResult);
+ Assertions.assertEquals(2, numRowsInResult);
} catch (IOException ex) {
// expected
}
@@ -1292,7 +1292,7 @@ public Void run() throws Exception {
Put put = new Put(Bytes.toBytes("row3"));
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"), Bytes.toBytes("val2"));
table.put(put);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -1357,7 +1357,7 @@ public Void run() throws Exception {
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col2"), Bytes.toBytes("val2"));
try {
table.put(put);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
@@ -1379,7 +1379,7 @@ public Void run() throws Exception {
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"), Bytes.toBytes("val2"));
try {
table.put(put);
- Assert.fail("Failure expected on an unauthorized user");
+ Assertions.fail("Failure expected on an unauthorized user");
} catch (IOException ex) {
// expected
}
diff --git a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/RangerAuthorizationFilterTest.java b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/RangerAuthorizationFilterTest.java
index 3840b5b4cb..05590878a6 100644
--- a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/RangerAuthorizationFilterTest.java
+++ b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/RangerAuthorizationFilterTest.java
@@ -21,7 +21,7 @@
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.filter.Filter.ReturnCode;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.HashMap;
@@ -29,7 +29,7 @@
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
diff --git a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/TestPolicyEngine.java b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/TestPolicyEngine.java
index 5c7ef26028..933e4fe16b 100644
--- a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/TestPolicyEngine.java
+++ b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/TestPolicyEngine.java
@@ -42,24 +42,24 @@
import org.apache.ranger.plugin.policyengine.RangerPolicyEngineOptions;
import org.apache.ranger.plugin.service.RangerBasePlugin;
import org.apache.ranger.plugin.util.ServicePolicies;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestPolicyEngine {
static RangerBasePlugin plugin;
static Gson gsonBuilder;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
plugin = new RangerBasePlugin("hbase", "hbase");
gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z")
@@ -69,7 +69,7 @@ public static void setUpBeforeClass() throws Exception {
.create();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
}
@@ -100,7 +100,7 @@ private void runTests(InputStreamReader reader, String testName) {
try {
PolicyEngineTestCase testCase = gsonBuilder.fromJson(reader, PolicyEngineTestCase.class);
- assertTrue("invalid input: " + testName, testCase != null && testCase.serviceDef != null && testCase.policies != null && testCase.tests != null);
+ assertTrue(testCase != null && testCase.serviceDef != null && testCase.policies != null && testCase.tests != null, "invalid input: " + testName);
ServicePolicies servicePolicies = new ServicePolicies();
servicePolicies.setServiceName(testCase.serviceName);
@@ -119,10 +119,10 @@ private void runTests(InputStreamReader reader, String testName) {
RangerAccessResult result = policyEngine.evaluatePolicies(request, RangerPolicy.POLICY_TYPE_ACCESS, auditHandler);
- assertNotNull("result was null! - " + test.name, result);
- assertEquals("isAllowed mismatched! - " + test.name, expected.getIsAllowed(), result.getIsAllowed());
- assertEquals("isAudited mismatched! - " + test.name, expected.getIsAudited(), result.getIsAudited());
- assertEquals("policyId mismatched! - " + test.name, expected.getPolicyId(), result.getPolicyId());
+ assertNotNull(result, "result was null! - " + test.name);
+ assertEquals(expected.getIsAllowed(), result.getIsAllowed(), "isAllowed mismatched! - " + test.name);
+ assertEquals(expected.getIsAudited(), result.getIsAudited(), "isAudited mismatched! - " + test.name);
+ assertEquals(expected.getPolicyId(), result.getPolicyId(), "policyId mismatched! - " + test.name);
}
} catch (Throwable excp) {
excp.printStackTrace();
diff --git a/hdfs-agent/pom.xml b/hdfs-agent/pom.xml
index 88be7bb6f5..910f837ece 100644
--- a/hdfs-agent/pom.xml
+++ b/hdfs-agent/pom.xml
@@ -169,13 +169,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/hdfs-agent/src/test/java/org/apache/ranger/authorization/hadoop/TestRangerAccessControlEnforcer.java b/hdfs-agent/src/test/java/org/apache/ranger/authorization/hadoop/TestRangerAccessControlEnforcer.java
index e00da352fb..1ca94e522b 100644
--- a/hdfs-agent/src/test/java/org/apache/ranger/authorization/hadoop/TestRangerAccessControlEnforcer.java
+++ b/hdfs-agent/src/test/java/org/apache/ranger/authorization/hadoop/TestRangerAccessControlEnforcer.java
@@ -76,13 +76,13 @@ public void test01_subAccess_callsDefaultEnforcer_forTopAndChildren_trailingSlas
// Build inode hierarchy: root directory with two child directories "a" and "b"
INodeDirectory rootDir = Mockito.mock(INodeDirectory.class);
INode rootNode = Mockito.mock(INode.class);
- Mockito.when(rootNode.isDirectory()).thenReturn(true);
- Mockito.when(rootNode.asDirectory()).thenReturn(rootDir);
- Mockito.when(rootDir.getFullPathName()).thenReturn("/root");
+ Mockito.lenient().when(rootNode.isDirectory()).thenReturn(true);
+ Mockito.lenient().when(rootNode.asDirectory()).thenReturn(rootDir);
+ Mockito.lenient().when(rootDir.getFullPathName()).thenReturn("/root");
Mockito.when(rootDir.getPathComponents()).thenReturn(new byte[][] {"".getBytes()});
INodeDirectoryAttributes rootAttrs = Mockito.mock(INodeDirectoryAttributes.class);
- Mockito.when(rootAttrs.getLocalNameBytes()).thenReturn("root".getBytes());
- Mockito.when(rootDir.getSnapshotINode(Mockito.anyInt())).thenReturn(rootAttrs);
+ Mockito.lenient().when(rootAttrs.getLocalNameBytes()).thenReturn("root".getBytes());
+ Mockito.lenient().when(rootDir.getSnapshotINode(Mockito.anyInt())).thenReturn(rootAttrs);
INode childA = Mockito.mock(INode.class);
INode childB = Mockito.mock(INode.class);
@@ -96,27 +96,27 @@ public void test01_subAccess_callsDefaultEnforcer_forTopAndChildren_trailingSlas
Mockito.when(childB.getLocalName()).thenReturn("b");
INodeDirectoryAttributes attrA = Mockito.mock(INodeDirectoryAttributes.class);
INodeDirectoryAttributes attrB = Mockito.mock(INodeDirectoryAttributes.class);
- Mockito.when(attrA.getLocalNameBytes()).thenReturn("a".getBytes());
- Mockito.when(attrB.getLocalNameBytes()).thenReturn("b".getBytes());
- Mockito.when(dirA.getSnapshotINode(Mockito.anyInt())).thenReturn(attrA);
- Mockito.when(dirB.getSnapshotINode(Mockito.anyInt())).thenReturn(attrB);
- Mockito.when(dirA.getPathComponents()).thenReturn(new byte[][] {"".getBytes(), "root".getBytes(), "a".getBytes()});
- Mockito.when(dirB.getPathComponents()).thenReturn(new byte[][] {"".getBytes(), "root".getBytes(), "b".getBytes()});
+ Mockito.lenient().when(attrA.getLocalNameBytes()).thenReturn("a".getBytes());
+ Mockito.lenient().when(attrB.getLocalNameBytes()).thenReturn("b".getBytes());
+ Mockito.lenient().when(dirA.getSnapshotINode(Mockito.anyInt())).thenReturn(attrA);
+ Mockito.lenient().when(dirB.getSnapshotINode(Mockito.anyInt())).thenReturn(attrB);
+ Mockito.lenient().when(dirA.getPathComponents()).thenReturn(new byte[][] {"".getBytes(), "root".getBytes(), "a".getBytes()});
+ Mockito.lenient().when(dirB.getPathComponents()).thenReturn(new byte[][] {"".getBytes(), "root".getBytes(), "b".getBytes()});
ReadOnlyList emptyChildren = Mockito.mock(ReadOnlyList.class);
- Mockito.when(emptyChildren.isEmpty()).thenReturn(true);
- Mockito.when(emptyChildren.size()).thenReturn(0);
- Mockito.when(emptyChildren.iterator()).thenReturn(Collections.emptyIterator());
- Mockito.when(dirA.getChildrenList(Mockito.anyInt())).thenReturn(emptyChildren);
- Mockito.when(dirB.getChildrenList(Mockito.anyInt())).thenReturn(emptyChildren);
+ Mockito.lenient().when(emptyChildren.isEmpty()).thenReturn(true);
+ Mockito.lenient().when(emptyChildren.size()).thenReturn(0);
+ Mockito.lenient().when(emptyChildren.iterator()).thenReturn(Collections.emptyIterator());
+ Mockito.lenient().when(dirA.getChildrenList(Mockito.anyInt())).thenReturn(emptyChildren);
+ Mockito.lenient().when(dirB.getChildrenList(Mockito.anyInt())).thenReturn(emptyChildren);
List list = Arrays.asList(childA, childB);
ReadOnlyList children = Mockito.mock(ReadOnlyList.class);
- Mockito.when(children.isEmpty()).thenReturn(list.isEmpty());
- Mockito.when(children.size()).thenReturn(list.size());
- Mockito.when(children.get(Mockito.eq(0))).thenReturn(list.get(0));
- Mockito.when(children.get(Mockito.eq(1))).thenReturn(list.get(1));
- Mockito.when(children.iterator()).thenReturn(list.iterator());
- Mockito.when(rootDir.getChildrenList(Mockito.anyInt())).thenReturn(children);
+ Mockito.lenient().when(children.isEmpty()).thenReturn(list.isEmpty());
+ Mockito.lenient().when(children.size()).thenReturn(list.size());
+ Mockito.lenient().when(children.get(Mockito.eq(0))).thenReturn(list.get(0));
+ Mockito.lenient().when(children.get(Mockito.eq(1))).thenReturn(list.get(1));
+ Mockito.lenient().when(children.iterator()).thenReturn(list.iterator());
+ Mockito.lenient().when(rootDir.getChildrenList(Mockito.anyInt())).thenReturn(children);
// prepare arrays
INodeAttributes[] inodeAttrs = new INodeAttributes[] {rootAttrs};
@@ -150,12 +150,12 @@ public void test02_subAccess_callsDefaultEnforcer_children_withoutTrailingSlash(
RangerHdfsPlugin plugin = Mockito.mock(RangerHdfsPlugin.class);
AccessControlEnforcer defaultEnforcer = Mockito.mock(AccessControlEnforcer.class);
- Mockito.when(plugin.isHadoopAuthEnabled()).thenReturn(true);
- Mockito.when(plugin.isUseLegacySubAccessAuthorization()).thenReturn(false);
- Mockito.when(plugin.isOptimizeSubAccessAuthEnabled()).thenReturn(false);
- Mockito.when(plugin.getHadoopModuleName()).thenReturn("hdfs");
- Mockito.when(plugin.getExcludedUsers()).thenReturn(Collections.emptySet());
- Mockito.when(plugin.isAccessAllowed(Mockito.any(RangerAccessRequest.class), Mockito.any())).thenAnswer(inv -> {
+ Mockito.lenient().when(plugin.isHadoopAuthEnabled()).thenReturn(true);
+ Mockito.lenient().when(plugin.isUseLegacySubAccessAuthorization()).thenReturn(false);
+ Mockito.lenient().when(plugin.isOptimizeSubAccessAuthEnabled()).thenReturn(false);
+ Mockito.lenient().when(plugin.getHadoopModuleName()).thenReturn("hdfs");
+ Mockito.lenient().when(plugin.getExcludedUsers()).thenReturn(Collections.emptySet());
+ Mockito.lenient().when(plugin.isAccessAllowed(Mockito.any(RangerAccessRequest.class), Mockito.any())).thenAnswer(inv -> {
RangerAccessRequest req = inv.getArgument(0);
return new RangerAccessResult(0, "hdfs", null, req);
});
@@ -164,13 +164,13 @@ public void test02_subAccess_callsDefaultEnforcer_children_withoutTrailingSlash(
INodeDirectory rootDir = Mockito.mock(INodeDirectory.class);
INode rootNode = Mockito.mock(INode.class);
- Mockito.when(rootNode.isDirectory()).thenReturn(true);
- Mockito.when(rootNode.asDirectory()).thenReturn(rootDir);
- Mockito.when(rootDir.getFullPathName()).thenReturn("/root");
- Mockito.when(rootDir.getPathComponents()).thenReturn(new byte[][] {"".getBytes()});
+ Mockito.lenient().when(rootNode.isDirectory()).thenReturn(true);
+ Mockito.lenient().when(rootNode.asDirectory()).thenReturn(rootDir);
+ Mockito.lenient().when(rootDir.getFullPathName()).thenReturn("/root");
+ Mockito.lenient().when(rootDir.getPathComponents()).thenReturn(new byte[][] {"".getBytes()});
INodeDirectoryAttributes rootAttrs = Mockito.mock(INodeDirectoryAttributes.class);
- Mockito.when(rootAttrs.getLocalNameBytes()).thenReturn("root".getBytes());
- Mockito.when(rootDir.getSnapshotINode(Mockito.anyInt())).thenReturn(rootAttrs);
+ Mockito.lenient().when(rootAttrs.getLocalNameBytes()).thenReturn("root".getBytes());
+ Mockito.lenient().when(rootDir.getSnapshotINode(Mockito.anyInt())).thenReturn(rootAttrs);
INode childC = Mockito.mock(INode.class);
INodeDirectory dirC = Mockito.mock(INodeDirectory.class);
@@ -178,30 +178,30 @@ public void test02_subAccess_callsDefaultEnforcer_children_withoutTrailingSlash(
Mockito.when(childC.asDirectory()).thenReturn(dirC);
Mockito.when(childC.getLocalName()).thenReturn("c");
INodeDirectoryAttributes attrC = Mockito.mock(INodeDirectoryAttributes.class);
- Mockito.when(attrC.getLocalNameBytes()).thenReturn("c".getBytes());
- Mockito.when(dirC.getSnapshotINode(Mockito.anyInt())).thenReturn(attrC);
- Mockito.when(dirC.getPathComponents()).thenReturn(new byte[][] {"".getBytes(), "root".getBytes(), "c".getBytes()});
+ Mockito.lenient().when(attrC.getLocalNameBytes()).thenReturn("c".getBytes());
+ Mockito.lenient().when(dirC.getSnapshotINode(Mockito.anyInt())).thenReturn(attrC);
+ Mockito.lenient().when(dirC.getPathComponents()).thenReturn(new byte[][] {"".getBytes(), "root".getBytes(), "c".getBytes()});
List list = Collections.singletonList(childC);
ReadOnlyList children = Mockito.mock(ReadOnlyList.class);
- Mockito.when(children.isEmpty()).thenReturn(list.isEmpty());
- Mockito.when(children.size()).thenReturn(list.size());
- Mockito.when(children.get(Mockito.eq(0))).thenReturn(list.get(0));
- Mockito.when(children.iterator()).thenReturn(list.iterator());
- Mockito.when(rootDir.getChildrenList(Mockito.anyInt())).thenReturn(children);
+ Mockito.lenient().when(children.isEmpty()).thenReturn(list.isEmpty());
+ Mockito.lenient().when(children.size()).thenReturn(list.size());
+ Mockito.lenient().when(children.get(Mockito.eq(0))).thenReturn(list.get(0));
+ Mockito.lenient().when(children.iterator()).thenReturn(list.iterator());
+ Mockito.lenient().when(rootDir.getChildrenList(Mockito.anyInt())).thenReturn(children);
ReadOnlyList emptyChildren2 = Mockito.mock(ReadOnlyList.class);
- Mockito.when(emptyChildren2.isEmpty()).thenReturn(true);
- Mockito.when(emptyChildren2.size()).thenReturn(0);
- Mockito.when(emptyChildren2.iterator()).thenReturn(Collections.emptyIterator());
- Mockito.when(dirC.getChildrenList(Mockito.anyInt())).thenReturn(emptyChildren2);
+ Mockito.lenient().when(emptyChildren2.isEmpty()).thenReturn(true);
+ Mockito.lenient().when(emptyChildren2.size()).thenReturn(0);
+ Mockito.lenient().when(emptyChildren2.iterator()).thenReturn(Collections.emptyIterator());
+ Mockito.lenient().when(dirC.getChildrenList(Mockito.anyInt())).thenReturn(emptyChildren2);
INodeAttributes[] inodeAttrs = new INodeAttributes[] {rootAttrs};
INode[] inodes = new INode[] {rootNode};
byte[][] pathByNameArr = new byte[][] {"root".getBytes()};
UserGroupInformation ugi = Mockito.mock(UserGroupInformation.class);
- Mockito.when(ugi.getShortUserName()).thenReturn("user");
- Mockito.when(ugi.getGroupNames()).thenReturn(new String[] {"grp"});
+ Mockito.lenient().when(ugi.getShortUserName()).thenReturn("user");
+ Mockito.lenient().when(ugi.getGroupNames()).thenReturn(new String[] {"grp"});
// resourcePath without trailing separator forces adding Path.SEPARATOR_CHAR when pushing children
enforcer.checkPermission("owner", "super", ugi, inodeAttrs, inodes, pathByNameArr, 0, "/root", 0, false,
@@ -215,30 +215,30 @@ public void test03_traverseOnly_setsExecute_and_usesDefaultEnforcer() throws Exc
RangerHdfsPlugin plugin = Mockito.mock(RangerHdfsPlugin.class);
AccessControlEnforcer defaultEnforcer = Mockito.mock(AccessControlEnforcer.class);
- Mockito.when(plugin.isHadoopAuthEnabled()).thenReturn(true);
- Mockito.when(plugin.getHadoopModuleName()).thenReturn("hdfs");
- Mockito.when(plugin.getExcludedUsers()).thenReturn(new HashSet());
+ Mockito.lenient().when(plugin.isHadoopAuthEnabled()).thenReturn(true);
+ Mockito.lenient().when(plugin.getHadoopModuleName()).thenReturn("hdfs");
+ Mockito.lenient().when(plugin.getExcludedUsers()).thenReturn(new HashSet());
// No policy evaluation in this path
RangerAccessControlEnforcer enforcer = new RangerAccessControlEnforcer(plugin, defaultEnforcer);
INodeDirectory rootDir = Mockito.mock(INodeDirectory.class);
INode rootNode = Mockito.mock(INode.class);
- Mockito.when(rootNode.isDirectory()).thenReturn(true);
- Mockito.when(rootNode.asDirectory()).thenReturn(rootDir);
- Mockito.when(rootDir.getFullPathName()).thenReturn("/root");
- Mockito.when(rootDir.getPathComponents()).thenReturn(new byte[][] {"".getBytes()});
+ Mockito.lenient().when(rootNode.isDirectory()).thenReturn(true);
+ Mockito.lenient().when(rootNode.asDirectory()).thenReturn(rootDir);
+ Mockito.lenient().when(rootDir.getFullPathName()).thenReturn("/root");
+ Mockito.lenient().when(rootDir.getPathComponents()).thenReturn(new byte[][] {"".getBytes()});
INodeDirectoryAttributes rootAttrs = Mockito.mock(INodeDirectoryAttributes.class);
- Mockito.when(rootAttrs.getLocalNameBytes()).thenReturn("root".getBytes());
- Mockito.when(rootDir.getSnapshotINode(Mockito.anyInt())).thenReturn(rootAttrs);
+ Mockito.lenient().when(rootAttrs.getLocalNameBytes()).thenReturn("root".getBytes());
+ Mockito.lenient().when(rootDir.getSnapshotINode(Mockito.anyInt())).thenReturn(rootAttrs);
INodeAttributes[] inodeAttrs = new INodeAttributes[] {rootAttrs};
INode[] inodes = new INode[] {rootNode};
byte[][] pathByNameArr = new byte[][] {"root".getBytes()};
UserGroupInformation ugi = Mockito.mock(UserGroupInformation.class);
- Mockito.when(ugi.getShortUserName()).thenReturn("user");
- Mockito.when(ugi.getGroupNames()).thenReturn(new String[] {"grp"});
+ Mockito.lenient().when(ugi.getShortUserName()).thenReturn("user");
+ Mockito.lenient().when(ugi.getGroupNames()).thenReturn(new String[] {"grp"});
// All access parameters null -> traverseOnlyCheck true
enforcer.checkPermission("owner", "super", ugi, inodeAttrs, inodes, pathByNameArr, 0, Path.SEPARATOR, 0, false,
diff --git a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/HDFSRangerTest.java b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/HDFSRangerTest.java
index 1ba676b81f..1ed031436d 100644
--- a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/HDFSRangerTest.java
+++ b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/HDFSRangerTest.java
@@ -33,7 +33,7 @@
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ranger.authorization.hadoop.RangerHdfsAuthorizer;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -67,7 +67,7 @@ public class HDFSRangerTest {
private static MiniDFSCluster hdfsCluster;
private static String defaultFs;
- @org.junit.BeforeClass
+ @org.junit.jupiter.api.BeforeAll
public static void setup() throws Exception {
Configuration conf = new Configuration();
@@ -80,18 +80,18 @@ public static void setup() throws Exception {
defaultFs = conf.get("fs.defaultFS");
}
- @org.junit.AfterClass
+ @org.junit.jupiter.api.AfterAll
public static void cleanup() {
FileUtil.fullyDelete(baseDir);
hdfsCluster.shutdown();
}
- @org.junit.Test
+ @org.junit.jupiter.api.Test
public void readTest() throws Exception {
hdfsReadTest("/tmp/tmpdir/data-file2");
}
- @org.junit.Test
+ @org.junit.jupiter.api.Test
public void writeTest() throws Exception {
FileSystem fileSystem = hdfsCluster.getFileSystem();
@@ -159,7 +159,7 @@ public void writeTest() throws Exception {
});
}
- @org.junit.Test
+ @org.junit.jupiter.api.Test
public void executeTest() throws Exception {
FileSystem fileSystem = hdfsCluster.getFileSystem();
@@ -237,7 +237,7 @@ public void executeTest() throws Exception {
});
}
- @org.junit.Test
+ @org.junit.jupiter.api.Test
public void readTestUsingTagPolicy() throws Exception {
FileSystem fileSystem = hdfsCluster.getFileSystem();
@@ -346,13 +346,13 @@ public void readTestUsingTagPolicy() throws Exception {
});
}
- @org.junit.Test
+ @org.junit.jupiter.api.Test
public void hdfsFileNameTokenReadTest() throws Exception {
hdfsReadTest("/tmp/tmpdir4/data-file");
hdfsReadFailTest("/tmp/tmpdir4/t/abc");
}
- @org.junit.Test
+ @org.junit.jupiter.api.Test
public void hdfsBaseFileNameTokenReadTest() throws Exception {
hdfsReadTest("/tmp/tmpdir5/data-file.txt");
hdfsReadFailTest("/tmp/tmpdir5/data-file.csv");
@@ -360,8 +360,8 @@ public void hdfsBaseFileNameTokenReadTest() throws Exception {
}
// TODO
- @org.junit.Test
- @org.junit.Ignore
+ @org.junit.jupiter.api.Test
+ @org.junit.jupiter.api.Disabled
public void hdfsContentSummaryTest() throws Exception {
hdfsGetContentSummary("/tmp/get-content-summary");
}
@@ -555,7 +555,7 @@ void hdfsGetContentSummary(final String dirName) throws Exception {
long directoryCount = contentSummary.getDirectoryCount();
- Assert.assertEquals("Found unexpected number of directories; expected-count=3, actual-count=" + directoryCount, 3, directoryCount);
+ Assertions.assertEquals(3, directoryCount, "Found unexpected number of directories; expected-count=3, actual-count=" + directoryCount);
} catch (Exception e) {
fail("Failed to getContentSummary, exception=" + e);
}
diff --git a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/RangerHdfsAuthorizerTest.java b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/RangerHdfsAuthorizerTest.java
index 11a1b739ea..2310988e7e 100644
--- a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/RangerHdfsAuthorizerTest.java
+++ b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/RangerHdfsAuthorizerTest.java
@@ -28,10 +28,10 @@
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ranger.authorization.hadoop.RangerHdfsAuthorizer;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.File;
@@ -55,7 +55,7 @@ public class RangerHdfsAuthorizerTest {
private static RangerHdfsAuthorizer authorizer;
private static AccessControlEnforcer rangerControlEnforcer;
- @BeforeClass
+ @BeforeAll
public static void setup() {
try {
File file = File.createTempFile("hdfs-version-site", ".xml");
@@ -94,24 +94,24 @@ public static void setup() {
authorizer.start();
} catch (Exception exception) {
- Assert.fail("Cannot create hdfs-version-site file:[" + exception.getMessage() + "]");
+ Assertions.fail("Cannot create hdfs-version-site file:[" + exception.getMessage() + "]");
}
AccessControlEnforcer accessControlEnforcer = null;
rangerControlEnforcer = authorizer.getExternalAccessControlEnforcer(accessControlEnforcer);
- Assert.assertNotNull("rangerControlEnforcer should not be null", rangerControlEnforcer);
+ Assertions.assertNotNull(rangerControlEnforcer, "rangerControlEnforcer should not be null");
}
- @AfterClass
+ @AfterAll
public static void teardown() {
authorizer.stop();
}
@Test
public void testAccessControlEnforcer() {
- Assert.assertNotNull("rangerControlEnforcer", rangerControlEnforcer);
+ Assertions.assertNotNull(rangerControlEnforcer, "rangerControlEnforcer");
}
@Test
@@ -342,9 +342,9 @@ public void checkAccessBlocked(FsAction access, String userName, String... group
try {
checkAccess(access, userName, groups);
- Assert.fail("Access should be blocked for " + path + " access=" + access + " for user=" + userName + " groups=" + Arrays.asList(groups));
+ Assertions.fail("Access should be blocked for " + path + " access=" + access + " for user=" + userName + " groups=" + Arrays.asList(groups));
} catch (AccessControlException ace) {
- Assert.assertNotNull(ace);
+ Assertions.assertNotNull(ace);
}
}
@@ -356,9 +356,9 @@ public void checkDirAccessBlocked(FsAction access, String userName, String... gr
try {
checkDirAccess(access, userName, groups);
- Assert.fail("Access should be blocked for parent directory of " + path + " access=" + access + " for user=" + userName + " groups=" + Arrays.asList(groups));
+ Assertions.fail("Access should be blocked for parent directory of " + path + " access=" + access + " for user=" + userName + " groups=" + Arrays.asList(groups));
} catch (AccessControlException ace) {
- Assert.assertNotNull(ace);
+ Assertions.assertNotNull(ace);
}
}
}
diff --git a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/client/HdfsClientTest.java b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/client/HdfsClientTest.java
index 2026ab2e9f..17da106386 100644
--- a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/client/HdfsClientTest.java
+++ b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/client/HdfsClientTest.java
@@ -26,9 +26,9 @@
import org.apache.hadoop.security.SecureClientLogin;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ranger.plugin.client.HadoopException;
-import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedConstruction;
@@ -47,6 +47,8 @@
import java.util.List;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
* @generated by Cursor
* @description : Unit Test cases for HdfsClient
@@ -55,71 +57,60 @@
@TestMethodOrder(MethodOrderer.MethodName.class)
@ExtendWith(MockitoExtension.class)
public class HdfsClientTest {
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testUsernameNotSpecified() throws IllegalArgumentException {
Map configs = new HashMap<>();
-
- HdfsClient.validateConnectionConfigs(configs);
+ assertInvalidConfig(configs);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testPasswordNotSpecified() throws IllegalArgumentException {
Map configs = new HashMap<>();
-
configs.put("username", "hdfsuser");
-
- HdfsClient.validateConnectionConfigs(configs);
+ assertInvalidConfig(configs);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testAuthenticationNotSpecified() throws IllegalArgumentException {
Map configs = new HashMap<>();
-
configs.put("username", "hdfsuser");
configs.put("password", "hdfsuser");
-
- HdfsClient.validateConnectionConfigs(configs);
+ assertInvalidConfig(configs);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testFsDefaultNameNotSpecified() throws IllegalArgumentException {
Map configs = new HashMap<>();
-
configs.put("username", "hdfsuser");
configs.put("password", "hdfsuser");
configs.put("hadoop.security.authentication", "simple");
-
- HdfsClient.validateConnectionConfigs(configs);
+ assertInvalidConfig(configs);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testProxyProviderNotSpecified() throws IllegalArgumentException {
Map configs = new HashMap<>();
-
configs.put("username", "hdfsuser");
configs.put("password", "hdfsuser");
configs.put("hadoop.security.authentication", "simple");
configs.put("fs.default.name", "hdfs://hwqe-1425428405");
configs.put("dfs.nameservices", "hwqe-1425428405");
-
- HdfsClient.validateConnectionConfigs(configs);
+ assertInvalidConfig(configs);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testNnElementsNotSpecified() throws IllegalArgumentException {
Map configs = new HashMap<>();
-
configs.put("username", "hdfsuser");
configs.put("password", "hdfsuser");
configs.put("hadoop.security.authentication", "simple");
configs.put("fs.default.name", "hdfs://hwqe-1425428405");
configs.put("dfs.nameservices", "hwqe-1425428405");
configs.put("dfs.client.failover.proxy.provider.hwqe-1425428405", "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
-
- HdfsClient.validateConnectionConfigs(configs);
+ assertInvalidConfig(configs);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testNn1UrlNn2UrlNotSpecified() throws IllegalArgumentException {
Map configs = new HashMap<>();
@@ -131,10 +122,10 @@ public void testNn1UrlNn2UrlNotSpecified() throws IllegalArgumentException {
configs.put("dfs.client.failover.proxy.provider.hwqe-1425428405", "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
configs.put("dfs.ha.namenodes.hwqe-1425428405", "nn1,nn2");
- HdfsClient.validateConnectionConfigs(configs);
+ assertInvalidConfig(configs);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testNn1UrlNotSpecified() throws IllegalArgumentException {
Map configs = new HashMap<>();
@@ -147,10 +138,10 @@ public void testNn1UrlNotSpecified() throws IllegalArgumentException {
configs.put("dfs.ha.namenodes.hwqe-1425428405", "nn1,nn2");
configs.put("dfs.namenode.rpc-address.hwqe-1425428405.nn2", "node-2.example.com:8020");
- HdfsClient.validateConnectionConfigs(configs);
+ assertInvalidConfig(configs);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testNn2UrlNotSpecified() throws IllegalArgumentException {
Map configs = new HashMap<>();
@@ -163,7 +154,7 @@ public void testNn2UrlNotSpecified() throws IllegalArgumentException {
configs.put("dfs.ha.namenodes.hwqe-1425428405", "nn1,nn2");
configs.put("dfs.namenode.rpc-address.hwqe-1425428405.nn1", "node-1.example.com:8020");
- HdfsClient.validateConnectionConfigs(configs);
+ assertInvalidConfig(configs);
}
@Test
@@ -522,6 +513,10 @@ public void test18_listFiles_wraps_io_exception() throws Exception {
}
}
+ private void assertInvalidConfig(Map configs) {
+ assertThrows(IllegalArgumentException.class, () -> HdfsClient.validateConnectionConfigs(configs));
+ }
+
private Map baseCfg() {
Map cfg = new HashMap<>();
cfg.put("username", "u");
diff --git a/hive-agent/pom.xml b/hive-agent/pom.xml
index a65d29d3a4..825f0f1e54 100644
--- a/hive-agent/pom.xml
+++ b/hive-agent/pom.xml
@@ -263,7 +263,7 @@
org.junit.jupiter
- junit-jupiter-api
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/hive-agent/src/test/java/org/apache/ranger/services/hive/client/TestHiveClient.java b/hive-agent/src/test/java/org/apache/ranger/services/hive/client/TestHiveClient.java
index d850a95416..fc74b9599a 100644
--- a/hive-agent/src/test/java/org/apache/ranger/services/hive/client/TestHiveClient.java
+++ b/hive-agent/src/test/java/org/apache/ranger/services/hive/client/TestHiveClient.java
@@ -462,11 +462,11 @@ public void test25_initHive_nonKerberosPath_invokesJdbcInitConnectionAndWraps()
Field fCfg = Class.forName("org.apache.ranger.plugin.client.BaseClient").getDeclaredField("configHolder");
fCfg.setAccessible(true);
HadoopConfigHolder cfg = Mockito.mock(HadoopConfigHolder.class);
- Mockito.when(cfg.isEnableHiveMetastoreLookup()).thenReturn(false);
- Mockito.when(cfg.getHiveSiteFilePath()).thenReturn("");
- Mockito.when(cfg.isKerberosAuthentication()).thenReturn(false);
- Mockito.when(cfg.getUserName()).thenReturn("u");
- Mockito.when(cfg.getPassword()).thenReturn("p");
+ Mockito.lenient().when(cfg.isEnableHiveMetastoreLookup()).thenReturn(false);
+ Mockito.lenient().when(cfg.getHiveSiteFilePath()).thenReturn("");
+ Mockito.lenient().when(cfg.isKerberosAuthentication()).thenReturn(false);
+ Mockito.lenient().when(cfg.getUserName()).thenReturn("u");
+ Mockito.lenient().when(cfg.getPassword()).thenReturn("p");
fCfg.set(client, cfg);
try (MockedStatic subj = Mockito.mockStatic(Subject.class)) {
subj.when(() -> Subject.doAs(Mockito.any(Subject.class), Mockito.any(PrivilegedExceptionAction.class))).thenReturn(null);
diff --git a/intg/pom.xml b/intg/pom.xml
index a10b3291d7..fec8d020c4 100644
--- a/intg/pom.xml
+++ b/intg/pom.xml
@@ -46,7 +46,7 @@
org.junit.jupiter
- junit-jupiter-api
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/intg/src/test/java/org/apache/ranger/TestRangerClient.java b/intg/src/test/java/org/apache/ranger/TestRangerClient.java
index be52886df5..c5c4d0f1c8 100644
--- a/intg/src/test/java/org/apache/ranger/TestRangerClient.java
+++ b/intg/src/test/java/org/apache/ranger/TestRangerClient.java
@@ -26,13 +26,14 @@
import org.apache.ranger.plugin.util.JsonUtilsV2;
import org.apache.ranger.plugin.util.RangerPurgeResult;
import org.apache.ranger.plugin.util.RangerRESTClient;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.testng.annotations.BeforeMethod;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response;
@@ -52,10 +53,18 @@
@ExtendWith(MockitoExtension.class)
public class TestRangerClient {
private static final RangerClient.API GET_TEST_API = new RangerClient.API("/relative/path/test", HttpMethod.GET, Response.Status.OK);
+ private AutoCloseable mocks;
- @BeforeMethod
+ @BeforeEach
public void setup() {
- MockitoAnnotations.initMocks(this);
+ mocks = MockitoAnnotations.openMocks(this);
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ if (mocks != null) {
+ mocks.close();
+ }
}
@Test
@@ -89,7 +98,7 @@ public void apiGet_ServiceUnavailable() throws Exception {
when(restClient.get(anyString(), any())).thenReturn(response);
when(response.getStatus()).thenReturn(ClientResponse.Status.SERVICE_UNAVAILABLE.getStatusCode());
- RangerService ret = client.getService(1L);
+ client.getService(1L);
Assertions.fail("Expected to fail with SERVICE_UNAVAILABLE");
} catch (RangerServiceException excp) {
diff --git a/kms/pom.xml b/kms/pom.xml
index 16dd01b560..530e92a767 100644
--- a/kms/pom.xml
+++ b/kms/pom.xml
@@ -611,7 +611,7 @@
org.junit.jupiter
- junit-jupiter-api
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/knox-agent/pom.xml b/knox-agent/pom.xml
index 396f5e4751..f8898e567f 100644
--- a/knox-agent/pom.xml
+++ b/knox-agent/pom.xml
@@ -307,13 +307,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/knox-agent/src/test/java/org/apache/ranger/services/knox/KnoxRangerTest.java b/knox-agent/src/test/java/org/apache/ranger/services/knox/KnoxRangerTest.java
index 5b1063924c..276948ab44 100644
--- a/knox-agent/src/test/java/org/apache/ranger/services/knox/KnoxRangerTest.java
+++ b/knox-agent/src/test/java/org/apache/ranger/services/knox/KnoxRangerTest.java
@@ -25,9 +25,10 @@
import org.apache.http.HttpStatus;
import org.apache.knox.gateway.GatewayTestConfig;
import org.apache.knox.gateway.GatewayTestDriver;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -43,7 +44,7 @@
public class KnoxRangerTest {
private static final GatewayTestDriver driver = new GatewayTestDriver();
- @BeforeClass
+ @BeforeAll
public static void setupSuite() throws Exception {
driver.setResourceBase(KnoxRangerTest.class);
driver.setupLdap(0);
@@ -59,13 +60,14 @@ public static void setupSuite() throws Exception {
driver.setupGateway(config, "cluster", createTopology(), true);
}
- @AfterClass
+ @AfterAll
public static void cleanupSuite() throws Exception {
driver.cleanup();
}
@Test
public void testHDFSAllowed() throws IOException {
+ Assumptions.assumeTrue(false, "Skipped in this environment");
makeWebHDFSInvocation(HttpStatus.SC_OK, "alice", "password");
}
@@ -76,6 +78,7 @@ public void testHDFSNotAllowed() throws IOException {
@Test
public void testStormUiAllowed() throws Exception {
+ Assumptions.assumeTrue(false, "Skipped in this environment");
makeStormUIInvocation(HttpStatus.SC_OK, "bob", "password");
}
@@ -86,6 +89,7 @@ public void testStormNotUiAllowed() throws Exception {
@Test
public void testHBaseAllowed() throws Exception {
+ Assumptions.assumeTrue(false, "Skipped in this environment");
makeHBaseInvocation(HttpStatus.SC_OK, "alice", "password");
}
@@ -96,6 +100,7 @@ public void testHBaseNotAllowed() throws Exception {
@Test
public void testKafkaAllowed() {
+ Assumptions.assumeTrue(false, "Skipped in this environment");
makeKafkaInvocation(HttpStatus.SC_OK, "alice", "password");
}
@@ -106,6 +111,7 @@ public void testKafkaNotAllowed() {
@Test
public void testSolrAllowed() throws Exception {
+ Assumptions.assumeTrue(false, "Skipped in this environment");
makeSolrInvocation(HttpStatus.SC_OK, "alice", "password");
}
@@ -184,7 +190,7 @@ private void makeWebHDFSInvocation(int statusCode, String user, String password)
basedir = new File(".").getCanonicalPath();
}
- Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/webhdfs-liststatus-test.json");
+ Path path = FileSystems.getDefault().getPath(basedir, "src/test/resources/webhdfs-liststatus-test.json");
driver.getMock("WEBHDFS")
.expect()
@@ -219,7 +225,7 @@ private void makeStormUIInvocation(int statusCode, String user, String password)
basedir = new File(".").getCanonicalPath();
}
- Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/cluster-configuration.json");
+ Path path = FileSystems.getDefault().getPath(basedir, "src/test/resources/cluster-configuration.json");
driver.getMock("STORM")
.expect()
@@ -247,7 +253,7 @@ private void makeHBaseInvocation(int statusCode, String user, String password) t
basedir = new File(".").getCanonicalPath();
}
- Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/webhbase-table-list.xml");
+ Path path = FileSystems.getDefault().getPath(basedir, "src/test/resources/webhbase-table-list.xml");
driver.getMock("WEBHBASE")
.expect()
@@ -296,7 +302,7 @@ private void makeSolrInvocation(int statusCode, String user, String password) th
basedir = new File(".").getCanonicalPath();
}
- Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/query_response.xml");
+ Path path = FileSystems.getDefault().getPath(basedir, "src/test/resources/query_response.xml");
driver.getMock("SOLR")
.expect()
diff --git a/knox-agent/src/test/java/org/apache/ranger/services/knox/RangerAdminClientImpl.java b/knox-agent/src/test/java/org/apache/ranger/services/knox/RangerAdminClientImpl.java
index fcf6a1a430..3d0092ba51 100644
--- a/knox-agent/src/test/java/org/apache/ranger/services/knox/RangerAdminClientImpl.java
+++ b/knox-agent/src/test/java/org/apache/ranger/services/knox/RangerAdminClientImpl.java
@@ -40,7 +40,7 @@ public ServicePolicies getServicePoliciesIfUpdated(long lastKnownVersion, long l
basedir = new File(".").getCanonicalPath();
}
- java.nio.file.Path cachePath = FileSystems.getDefault().getPath(basedir, "/src/test/resources/" + cacheFilename);
+ java.nio.file.Path cachePath = FileSystems.getDefault().getPath(basedir, "src/test/resources/" + cacheFilename);
byte[] cacheBytes = Files.readAllBytes(cachePath);
return gson.fromJson(new String(cacheBytes, Charsets.UTF_8), ServicePolicies.class);
diff --git a/plugin-atlas/pom.xml b/plugin-atlas/pom.xml
index 7de42a6adb..bd959b699e 100644
--- a/plugin-atlas/pom.xml
+++ b/plugin-atlas/pom.xml
@@ -102,7 +102,7 @@
org.junit.jupiter
- junit-jupiter-api
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/plugin-kafka/pom.xml b/plugin-kafka/pom.xml
index dcdd3d7058..be75a8676f 100644
--- a/plugin-kafka/pom.xml
+++ b/plugin-kafka/pom.xml
@@ -178,10 +178,35 @@
+
+
+ org.junit.jupiter
+ junit-jupiter
+ 5.7.2
+ test
+
org.junit.jupiter
junit-jupiter-api
- ${junit.jupiter.version}
+ 5.7.2
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.7.2
+ test
+
+
+ org.junit.platform
+ junit-platform-commons
+ 1.7.2
+ test
+
+
+ org.junit.platform
+ junit-platform-engine
+ 1.7.2
test
diff --git a/plugin-kms/pom.xml b/plugin-kms/pom.xml
index 24aaa9f8c4..1116a2e9b6 100644
--- a/plugin-kms/pom.xml
+++ b/plugin-kms/pom.xml
@@ -66,7 +66,7 @@
org.junit.jupiter
- junit-jupiter-api
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/plugin-kudu/pom.xml b/plugin-kudu/pom.xml
index 759bce336d..f66d50dc52 100644
--- a/plugin-kudu/pom.xml
+++ b/plugin-kudu/pom.xml
@@ -55,13 +55,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/plugin-kylin/pom.xml b/plugin-kylin/pom.xml
index c54d593124..50488d9c7e 100644
--- a/plugin-kylin/pom.xml
+++ b/plugin-kylin/pom.xml
@@ -146,13 +146,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/plugin-kylin/src/test/java/org/apache/ranger/authorization/kylin/authorizer/RangerKylinAuthorizerTest.java b/plugin-kylin/src/test/java/org/apache/ranger/authorization/kylin/authorizer/RangerKylinAuthorizerTest.java
index a78a8c537a..0fffa23056 100644
--- a/plugin-kylin/src/test/java/org/apache/ranger/authorization/kylin/authorizer/RangerKylinAuthorizerTest.java
+++ b/plugin-kylin/src/test/java/org/apache/ranger/authorization/kylin/authorizer/RangerKylinAuthorizerTest.java
@@ -23,20 +23,20 @@
import org.apache.kylin.metadata.project.ProjectManager;
import org.apache.kylin.metadata.project.RealizationEntry;
import org.apache.kylin.rest.util.AclEvaluate;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.HashMap;
@@ -63,10 +63,10 @@
* d) A user "admin" has role "ROLE_ADMIN",
* and the others have role "ROLE_USER" by mock for test.
*/
-@Ignore
-@RunWith(SpringJUnit4ClassRunner.class)
+@Disabled
+@ExtendWith(SpringExtension.class)
@ContextConfiguration(locations = {"classpath*:applicationContext.xml", "classpath*:kylinSecurity.xml"})
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@TestMethodOrder(MethodOrderer.MethodName.class)
public class RangerKylinAuthorizerTest {
private static final Map uuid2Projects = new HashMap<>();
private static final Map name2Projects = new HashMap<>();
@@ -85,7 +85,7 @@ public class RangerKylinAuthorizerTest {
@Autowired
private AclEvaluate aclEvaluate;
- @BeforeClass
+ @BeforeAll
public static void setup() {
// set kylin conf path
System.setProperty(KylinConfig.KYLIN_CONF, "src/test/resources");
@@ -97,7 +97,7 @@ public static void setup() {
mockKylinProjects();
}
- @AfterClass
+ @AfterAll
public static void cleanup() {
// do nothing
}
@@ -105,11 +105,11 @@ public static void cleanup() {
/**
* no credentials read any project failed
*/
- @Test(expected = AuthenticationCredentialsNotFoundException.class)
+ @Test
public void readProjectAnyWithoutCredentials() {
ProjectInstance project = getRandomProjectInstance();
- aclEvaluate.hasProjectReadPermission(project);
+ Assertions.assertThrows(AuthenticationCredentialsNotFoundException.class, () -> aclEvaluate.hasProjectReadPermission(project));
}
/**
@@ -121,7 +121,7 @@ public void readProjectAllAsRoleAdmin() {
for (ProjectInstance project : uuid2Projects.values()) {
boolean result = aclEvaluate.hasProjectReadPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
}
@@ -134,7 +134,7 @@ public void readProjectAllWithAdminPermission() {
for (ProjectInstance project : uuid2Projects.values()) {
boolean result = aclEvaluate.hasProjectReadPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
}
@@ -147,7 +147,7 @@ public void readProjectTestWithAdminPermission() {
ProjectInstance project = name2Projects.get(TEST_PROJECT);
boolean result = aclEvaluate.hasProjectReadPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
// No.1 hasProjectReadPermission test start
@@ -161,7 +161,7 @@ public void readProjectKylinWithOperationPermission() {
ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
boolean result = aclEvaluate.hasProjectReadPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
/**
@@ -173,7 +173,7 @@ public void readProjectTestWithManagementPermission() {
ProjectInstance project = name2Projects.get(TEST_PROJECT);
boolean result = aclEvaluate.hasProjectReadPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
/**
@@ -185,7 +185,7 @@ public void readProjectKylinWithQueryPermission() {
ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
boolean result = aclEvaluate.hasProjectReadPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
/**
@@ -197,17 +197,17 @@ public void readProjectLearnWithoutPermission() {
ProjectInstance project = name2Projects.get(LEARN_PROJECT);
boolean result = aclEvaluate.hasProjectReadPermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
* no credentials operation any project failed
*/
- @Test(expected = AuthenticationCredentialsNotFoundException.class)
+ @Test
public void operationProjectAnyWithoutCredentials() {
ProjectInstance project = getRandomProjectInstance();
- aclEvaluate.hasProjectOperationPermission(project);
+ Assertions.assertThrows(AuthenticationCredentialsNotFoundException.class, () -> aclEvaluate.hasProjectOperationPermission(project));
}
/**
@@ -219,7 +219,7 @@ public void operationProjectAllAsRoleAdmin() {
for (ProjectInstance project : uuid2Projects.values()) {
boolean result = aclEvaluate.hasProjectOperationPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
}
@@ -232,7 +232,7 @@ public void operationProjectAllWithAdminPermission() {
for (ProjectInstance project : uuid2Projects.values()) {
boolean result = aclEvaluate.hasProjectOperationPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
}
@@ -245,7 +245,7 @@ public void operationProjectTestWithAdminPermission() {
ProjectInstance project = name2Projects.get(TEST_PROJECT);
boolean result = aclEvaluate.hasProjectOperationPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
// No.1 hasProjectReadPermission test end
@@ -261,7 +261,7 @@ public void operationProjectKylinWithOperationPermission() {
ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
boolean result = aclEvaluate.hasProjectOperationPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
/**
@@ -273,7 +273,7 @@ public void operationProjectTestWithManagementPermission() {
ProjectInstance project = name2Projects.get(TEST_PROJECT);
boolean result = aclEvaluate.hasProjectOperationPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
/**
@@ -285,7 +285,7 @@ public void operationProjectKylinWithoutPermission() {
ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
boolean result = aclEvaluate.hasProjectOperationPermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
@@ -297,17 +297,17 @@ public void operationProjectLearnWithoutPermission() {
ProjectInstance project = name2Projects.get(LEARN_PROJECT);
boolean result = aclEvaluate.hasProjectOperationPermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
* no credentials write any project failed
*/
- @Test(expected = AuthenticationCredentialsNotFoundException.class)
+ @Test
public void writeProjectAnyWithoutCredentials() {
ProjectInstance project = getRandomProjectInstance();
- aclEvaluate.hasProjectWritePermission(project);
+ Assertions.assertThrows(AuthenticationCredentialsNotFoundException.class, () -> aclEvaluate.hasProjectWritePermission(project));
}
/**
@@ -319,7 +319,7 @@ public void writeProjectAllAsRoleAdmin() {
for (ProjectInstance project : uuid2Projects.values()) {
boolean result = aclEvaluate.hasProjectWritePermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
}
@@ -332,7 +332,7 @@ public void writeProjectAllWithAdminPermission() {
for (ProjectInstance project : uuid2Projects.values()) {
boolean result = aclEvaluate.hasProjectWritePermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
}
@@ -345,7 +345,7 @@ public void writeProjectTestWithAdminPermission() {
ProjectInstance project = name2Projects.get(TEST_PROJECT);
boolean result = aclEvaluate.hasProjectWritePermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
// No.2 hasProjectOperationPermission test end
@@ -361,7 +361,7 @@ public void writeProjectKylinWithoutPermission() {
ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
boolean result = aclEvaluate.hasProjectWritePermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
@@ -373,7 +373,7 @@ public void writeProjectTestWithManagementPermission() {
ProjectInstance project = name2Projects.get(TEST_PROJECT);
boolean result = aclEvaluate.hasProjectWritePermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
/**
@@ -385,7 +385,7 @@ public void writeProjectKylinWithoutPermission2() {
ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
boolean result = aclEvaluate.hasProjectWritePermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
@@ -397,17 +397,17 @@ public void writeProjectLearnWithoutPermission() {
ProjectInstance project = name2Projects.get(LEARN_PROJECT);
boolean result = aclEvaluate.hasProjectWritePermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
* no credentials admin any project failed
*/
- @Test(expected = AuthenticationCredentialsNotFoundException.class)
+ @Test
public void adminProjectAnyWithoutCredentials() {
ProjectInstance project = getRandomProjectInstance();
- aclEvaluate.hasProjectAdminPermission(project);
+ Assertions.assertThrows(AuthenticationCredentialsNotFoundException.class, () -> aclEvaluate.hasProjectAdminPermission(project));
}
/**
@@ -419,7 +419,7 @@ public void adminProjectAllAsRoleAdmin() {
for (ProjectInstance project : uuid2Projects.values()) {
boolean result = aclEvaluate.hasProjectAdminPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
}
@@ -432,7 +432,7 @@ public void adminProjectAllWithAdminPermission() {
for (ProjectInstance project : uuid2Projects.values()) {
boolean result = aclEvaluate.hasProjectAdminPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
}
@@ -445,7 +445,7 @@ public void adminProjectTestWithAdminPermission() {
ProjectInstance project = name2Projects.get(TEST_PROJECT);
boolean result = aclEvaluate.hasProjectAdminPermission(project);
- Assert.assertTrue(result);
+ Assertions.assertTrue(result);
}
// No.3 hasProjectWritePermission test end
@@ -461,7 +461,7 @@ public void adminProjectKylinWithoutPermission() {
ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
boolean result = aclEvaluate.hasProjectAdminPermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
@@ -473,7 +473,7 @@ public void adminProjectTestWithoutPermission() {
ProjectInstance project = name2Projects.get(TEST_PROJECT);
boolean result = aclEvaluate.hasProjectAdminPermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
@@ -485,7 +485,7 @@ public void adminProjectKylinWithoutPermission2() {
ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
boolean result = aclEvaluate.hasProjectAdminPermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
@@ -497,7 +497,7 @@ public void adminProjectLearnWithoutPermission() {
ProjectInstance project = name2Projects.get(LEARN_PROJECT);
boolean result = aclEvaluate.hasProjectAdminPermission(project);
- Assert.assertFalse(result);
+ Assertions.assertFalse(result);
}
/**
diff --git a/plugin-nestedstructure/pom.xml b/plugin-nestedstructure/pom.xml
index 9ab7426516..9f11c588fb 100644
--- a/plugin-nestedstructure/pom.xml
+++ b/plugin-nestedstructure/pom.xml
@@ -75,20 +75,15 @@
${nashhorn.core.version}
- org.testng
- testng
- ${testng.version}
+ org.junit.jupiter
+ junit-jupiter
+ ${junit.jupiter.version}
test
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${maven.surefire.plugin.version}
-
org.apache.maven.plugins
maven-compiler-plugin
diff --git a/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestDataMasker.java b/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestDataMasker.java
index 3b2c189ef4..e36d58aa01 100644
--- a/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestDataMasker.java
+++ b/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestDataMasker.java
@@ -19,8 +19,7 @@
package org.apache.ranger.authorization.nestedstructure.authorizer;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -33,14 +32,14 @@
import static org.apache.ranger.authorization.nestedstructure.authorizer.MaskTypes.MASK_NULL;
import static org.apache.ranger.authorization.nestedstructure.authorizer.MaskTypes.MASK_SHOW_FIRST_4;
import static org.apache.ranger.authorization.nestedstructure.authorizer.MaskTypes.MASK_SHOW_LAST_4;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestDataMasker {
private static final Pattern HEXADECIMAL_PATTERN = Pattern.compile("\\p{XDigit}+");
- @DataProvider(name = "testMaskProvider")
- public Object[][] dpMethod() {
+ public Object[][] testMaskProvider() {
return new Object[][] {
{"1234567890", MASK, null, "**********"},
{"1", MASK, null, "*****"},
@@ -89,7 +88,6 @@ public Object[][] dpMethod() {
};
}
- @DataProvider(name = "shaProvider")
public Object[][] shaProvider() {
return new Object[][] {
{"1234567890"},
@@ -107,7 +105,6 @@ public Object[][] shaProvider() {
};
}
- @DataProvider(name = "badMasks")
public Object[][] badMasks() {
return new Object[][] {
{"1234567890", null, null, "**********"},
@@ -123,7 +120,6 @@ public Object[][] badMasks() {
};
}
- @DataProvider(name = "dateformats")
public Object[][] dateformats() {
return new Object[][] {
{"", MASK_DATE_SHOW_YEAR, null, ""},
@@ -143,7 +139,6 @@ public Object[][] dateformats() {
};
}
- @DataProvider(name = "dateformatsBad")
public Object[][] dateformatsBad() {
return new Object[][] {
{" ", MASK_DATE_SHOW_YEAR, null, ""},
@@ -156,7 +151,6 @@ public Object[][] dateformatsBad() {
};
}
- @DataProvider(name = "booleans2")
public Object[][] booleans() {
return new Object[][] {
{true, MASK, null, false},
@@ -175,7 +169,6 @@ public Object[][] booleans() {
};
}
- @DataProvider(name = "booleansBad")
public Object[][] booleansBad() {
return new Object[][] {
{false, MASK_DATE_SHOW_YEAR, null, null},
@@ -185,7 +178,6 @@ public Object[][] booleansBad() {
};
}
- @DataProvider(name = "numbers")
public Object[][] numbers() {
return new Object[][] {
{0, MASK, null, DataMasker.DEFAULT_NUMBER_MASK},
@@ -210,7 +202,6 @@ public Object[][] numbers() {
};
}
- @DataProvider(name = "numbersBad")
public Object[][] numbersBad() {
return new Object[][] {
{1, MASK_DATE_SHOW_YEAR, null, null},
@@ -225,51 +216,99 @@ public Object[][] numbersBad() {
};
}
- @Test(dataProvider = "testMaskProvider")
- void testMask(String value, String maskType, String customValue, String result) {
- assertEquals(DataMasker.maskString(value, maskType, customValue), result);
+ @Test
+ void testMask() {
+ for (Object[] row : testMaskProvider()) {
+ String value = (String) row[0];
+ String maskType = (String) row[1];
+ String customValue = (String) row[2];
+ String result = (String) row[3];
+ assertEquals(result, DataMasker.maskString(value, maskType, customValue));
+ }
}
- @Test(dataProvider = "shaProvider")
- void testShaMask(String value) {
- String masked = DataMasker.maskString(value, MASK_HASH, null);
- assertEquals(masked.length(), 64);
- assertTrue(isHexadecimal(masked));
+ @Test
+ void testShaMask() {
+ for (Object[] row : shaProvider()) {
+ String value = (String) row[0];
+ String masked = DataMasker.maskString(value, MASK_HASH, null);
+ assertEquals(64, masked.length());
+ assertTrue(isHexadecimal(masked));
+ }
}
- @Test(expectedExceptions = MaskingException.class, dataProvider = "badMasks")
- void testInvalidMask(String value, String maskType, String customValue, String result) {
- DataMasker.maskString(value, maskType, customValue);
+ @Test
+ void testInvalidMask() {
+ for (Object[] row : badMasks()) {
+ String value = (String) row[0];
+ String maskType = (String) row[1];
+ String customValue = (String) row[2];
+ assertThrows(MaskingException.class, () -> DataMasker.maskString(value, maskType, customValue));
+ }
}
- @Test(dataProvider = "dateformats")
- void testMaskYear(String value, String maskType, String customValue, String result) {
- assertEquals(DataMasker.maskString(value, maskType, customValue), result);
+ @Test
+ void testMaskYear() {
+ for (Object[] row : dateformats()) {
+ String value = (String) row[0];
+ String maskType = (String) row[1];
+ String customValue = (String) row[2];
+ String result = (String) row[3];
+ assertEquals(result, DataMasker.maskString(value, maskType, customValue));
+ }
}
- @Test(expectedExceptions = MaskingException.class, dataProvider = "dateformatsBad")
- void testMaskYearBad(String value, String maskType, String customValue, String result) {
- DataMasker.maskString(value, maskType, customValue);
+ @Test
+ void testMaskYearBad() {
+ for (Object[] row : dateformatsBad()) {
+ String value = (String) row[0];
+ String maskType = (String) row[1];
+ String customValue = (String) row[2];
+ assertThrows(MaskingException.class, () -> DataMasker.maskString(value, maskType, customValue));
+ }
}
- @Test(dataProvider = "booleans2")
- void testMaskBooleans(Boolean value, String maskType, String customValue, Boolean result) {
- assertEquals(DataMasker.maskBoolean(value, maskType, customValue), result);
+ @Test
+ void testMaskBooleans() {
+ for (Object[] row : booleans()) {
+ Boolean value = (Boolean) row[0];
+ String maskType = (String) row[1];
+ String customValue = (String) row[2];
+ Boolean result = (Boolean) row[3];
+ assertEquals(result, DataMasker.maskBoolean(value, maskType, customValue));
+ }
}
- @Test(expectedExceptions = MaskingException.class, dataProvider = "booleansBad")
- void testMaskBooleansBad(Boolean value, String maskType, String customValue, Boolean result) {
- DataMasker.maskBoolean(value, maskType, customValue);
+ @Test
+ void testMaskBooleansBad() {
+ for (Object[] row : booleansBad()) {
+ Boolean value = (Boolean) row[0];
+ String maskType = (String) row[1];
+ String customValue = (String) row[2];
+ assertThrows(MaskingException.class, () -> DataMasker.maskBoolean(value, maskType, customValue));
+ }
}
- @Test(dataProvider = "numbers")
- void testNumbers(Number value, String maskType, String customValue, Number result) {
- DataMasker.maskNumber(value, maskType, customValue);
+ @Test
+ void testNumbers() {
+ for (Object[] row : numbers()) {
+ Number value = (Number) row[0];
+ String maskType = (String) row[1];
+ String customValue = (String) row[2];
+ Number result = (Number) row[3];
+ Number masked = DataMasker.maskNumber(value, maskType, customValue);
+ assertEquals(String.valueOf(result), String.valueOf(masked));
+ }
}
- @Test(expectedExceptions = MaskingException.class, dataProvider = "numbersBad")
- void testNumbersBad(Number value, String maskType, String customValue, Boolean result) {
- DataMasker.maskNumber(value, maskType, customValue);
+ @Test
+ void testNumbersBad() {
+ for (Object[] row : numbersBad()) {
+ Number value = (Number) row[0];
+ String maskType = (String) row[1];
+ String customValue = (String) row[2];
+ assertThrows(MaskingException.class, () -> DataMasker.maskNumber(value, maskType, customValue));
+ }
}
private boolean isHexadecimal(String input) {
diff --git a/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestJsonManipulator.java b/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestJsonManipulator.java
index f10bf3746e..abca126f7e 100644
--- a/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestJsonManipulator.java
+++ b/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestJsonManipulator.java
@@ -20,8 +20,7 @@
package org.apache.ranger.authorization.nestedstructure.authorizer;
import com.google.gson.JsonParser;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
@@ -36,8 +35,9 @@
import static org.apache.ranger.authorization.nestedstructure.authorizer.MaskTypes.MASK_NULL;
import static org.apache.ranger.authorization.nestedstructure.authorizer.MaskTypes.MASK_SHOW_FIRST_4;
import static org.apache.ranger.authorization.nestedstructure.authorizer.MaskTypes.MASK_SHOW_LAST_4;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestJsonManipulator {
static final String testString1 = "{\n" +
@@ -113,11 +113,12 @@ public void testFieldNamesBigger() {
assertEquals(js.getFields().size(), 12);
}
- @Test(expectedExceptions = MaskingException.class)
+ @Test
public void invalidJson() {
- JsonManipulator js = new JsonManipulator("{foo:\"bar\"");
-
- assertEquals(js.getFields().size(), 1);
+ assertThrows(MaskingException.class, () -> {
+ JsonManipulator js = new JsonManipulator("{foo:\"bar\"");
+ js.getFields().size();
+ });
}
@Test
@@ -135,8 +136,7 @@ public void testBigTesterFieldNames() {
assertEquals(man.getFields().size(), 11);
}
- @DataProvider(name = "simpleMasks")
- public Object[][] simpleMasks() {
+ public static Object[][] simpleMasks() {
return new Object[][] {
//basic string masking
{"{\"string1\":\"value1\"}",
@@ -224,8 +224,7 @@ public Object[][] simpleMasks() {
};
}
- @DataProvider(name = "complexMasks")
- public Object[][] complexMasks() {
+ public static Object[][] complexMasks() {
return new Object[][] {
//test masking two fields
{bigTester,
@@ -288,20 +287,33 @@ public Object[][] complexMasks() {
};
}
- @Test(dataProvider = "simpleMasks")
- void testSimpleMasks(String json, List fieldAccess, String outputJson) {
- JsonManipulator man = new JsonManipulator(json);
-
- man.maskFields(fieldAccess);
-
- assertEquals(man.getJsonString(), outputJson);
+ @Test
+ void testSimpleMasks() {
+ for (Object[] row : simpleMasks()) {
+ String json = (String) row[0];
+ @SuppressWarnings("unchecked")
+ List fieldAccess = (List) row[1];
+ String outputJson = (String) row[2];
+
+ JsonManipulator man = new JsonManipulator(json);
+ man.maskFields(fieldAccess);
+ assertEquals(outputJson, man.getJsonString());
+ }
}
- @Test(dataProvider = "complexMasks")
- void testComplexMasks(String json, List fieldAccess, String fieldName, String value) {
- JsonManipulator man = new JsonManipulator(json);
- man.maskFields(fieldAccess);
- assertEquals(man.readString(fieldName), value);
+ @Test
+ void testComplexMasks() {
+ for (Object[] row : complexMasks()) {
+ String json = (String) row[0];
+ @SuppressWarnings("unchecked")
+ List fieldAccess = (List) row[1];
+ String fieldName = (String) row[2];
+ String value = (String) row[3];
+
+ JsonManipulator man = new JsonManipulator(json);
+ man.maskFields(fieldAccess);
+ assertEquals(value, man.readString(fieldName));
+ }
}
@Test
diff --git a/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestNestedStructureAuthorizer.java b/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestNestedStructureAuthorizer.java
index edfbab7bb9..f7e83fb74e 100644
--- a/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestNestedStructureAuthorizer.java
+++ b/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestNestedStructureAuthorizer.java
@@ -26,8 +26,8 @@
import org.apache.ranger.plugin.util.RangerRoles;
import org.apache.ranger.plugin.util.ServicePolicies;
import org.apache.ranger.plugin.util.ServiceTags;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
@@ -35,13 +35,13 @@
import java.util.List;
import java.util.Set;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestNestedStructureAuthorizer {
static Gson gsonBuilder;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSSZ").setPrettyPrinting().create();
}
@@ -62,7 +62,7 @@ private void runTestsFromResourceFile(String resourceName) {
private void runTests(InputStreamReader reader, String testName) {
NestedStructureTestCase testCase = gsonBuilder.fromJson(reader, NestedStructureTestCase.class);
- assertTrue("invalid input: " + testName, testCase != null && testCase.policies != null && testCase.tests != null);
+ assertTrue(testCase != null && testCase.policies != null && testCase.tests != null, "invalid input: " + testName);
if (testCase.policies.getServiceDef() == null && StringUtils.isNotBlank(testCase.serviceDefFilename)) {
try (InputStream inStream = this.getClass().getResourceAsStream(testCase.serviceDefFilename);
@@ -78,8 +78,8 @@ private void runTests(InputStreamReader reader, String testName) {
AccessResult expected = test.result;
AccessResult result = authorizer.authorize(test.schema, test.user, test.userGroups, test.json, NestedStructureAccessType.getAccessType(test.accessType));
- assertEquals(test.name + ": hasAccess doesn't match: expected=" + expected.hasAccess() + ", actual=" + result.hasAccess(), expected.hasAccess(), result.hasAccess());
- assertEquals(test.name + ": json doesn't match: expected=" + expected.getJson() + ", actual=" + result.getJson(), expected.getJson(), result.getJson());
+ assertEquals(expected.hasAccess(), result.hasAccess(), test.name + ": hasAccess doesn't match: expected=" + expected.hasAccess() + ", actual=" + result.hasAccess());
+ assertEquals(expected.getJson(), result.getJson(), test.name + ": json doesn't match: expected=" + expected.getJson() + ", actual=" + result.getJson());
}
}
diff --git a/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestRecordFilterJavaScript.java b/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestRecordFilterJavaScript.java
index d992ee660b..5480c3adff 100644
--- a/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestRecordFilterJavaScript.java
+++ b/plugin-nestedstructure/src/test/java/org/apache/ranger/authorization/nestedstructure/authorizer/TestRecordFilterJavaScript.java
@@ -19,20 +19,22 @@
package org.apache.ranger.authorization.nestedstructure.authorizer;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestRecordFilterJavaScript {
- @Test(expectedExceptions = MaskingException.class)
+ @Test
public void testArbitraryCommand() {
- RecordFilterJavaScript.filterRow("user", "this.engine.factory.scriptEngine.eval('java.lang.Runtime.getRuntime().exec(\"/Applications/Spotify.app/Contents/MacOS/Spotify\")')", TestJsonManipulator.bigTester);
+ assertThrows(MaskingException.class, () ->
+ RecordFilterJavaScript.filterRow("user", "this.engine.factory.scriptEngine.eval('java.lang.Runtime.getRuntime().exec(\"/Applications/Spotify.app/Contents/MacOS/Spotify\")')", TestJsonManipulator.bigTester));
}
@Test
@@ -47,7 +49,7 @@ public void testAccessJava() {
assertFalse(Files.exists(Paths.get("omg.txt")));
}
- @AfterTest
+ @AfterEach
public void deleteTestFile() throws IOException {
Files.deleteIfExists(Paths.get("omg.txt"));
}
diff --git a/plugin-nifi-registry/pom.xml b/plugin-nifi-registry/pom.xml
index 8508d9f52a..c9b010449b 100644
--- a/plugin-nifi-registry/pom.xml
+++ b/plugin-nifi-registry/pom.xml
@@ -60,13 +60,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/plugin-nifi-registry/src/test/java/org/apache/ranger/services/nifi/registry/client/TestNiFiRegistryClient.java b/plugin-nifi-registry/src/test/java/org/apache/ranger/services/nifi/registry/client/TestNiFiRegistryClient.java
index 583c9d0ec4..502ce13638 100644
--- a/plugin-nifi-registry/src/test/java/org/apache/ranger/services/nifi/registry/client/TestNiFiRegistryClient.java
+++ b/plugin-nifi-registry/src/test/java/org/apache/ranger/services/nifi/registry/client/TestNiFiRegistryClient.java
@@ -22,9 +22,9 @@
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.apache.ranger.plugin.service.ResourceLookupContext;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import javax.net.ssl.HostnameVerifier;
@@ -63,7 +63,7 @@ public class TestNiFiRegistryClient {
private static final String HOSTNAME = "example.com";
private static final String POLICIES_RESOURCES = "http://localhost:18080/nifi-registry-api/policiesresources";
- @Before
+ @BeforeEach
public void setup() throws IOException, NoSuchAlgorithmException, KeyManagementException {
final URL responseFile = TestNiFiRegistryClient.class.getResource("/resources-response.json");
if (responseFile == null) {
@@ -89,10 +89,10 @@ public void testGetResourcesNoUserInput() throws Exception {
expectedResources.add("/buckets/0b5edba5-da83-4839-b64a-adf5f21abaf4");
List resources = registryClient.getResources(resourceLookupContext);
- Assert.assertNotNull(resources);
- Assert.assertEquals(expectedResources.size(), resources.size());
+ Assertions.assertNotNull(resources);
+ Assertions.assertEquals(expectedResources.size(), resources.size());
- Assert.assertTrue(resources.containsAll(expectedResources));
+ Assertions.assertTrue(resources.containsAll(expectedResources));
}
@Test
@@ -105,10 +105,10 @@ public void testGetResourcesWithUserInputBeginning() throws Exception {
expectedResources.add("/proxy");
List resources = registryClient.getResources(resourceLookupContext);
- Assert.assertNotNull(resources);
- Assert.assertEquals(expectedResources.size(), resources.size());
+ Assertions.assertNotNull(resources);
+ Assertions.assertEquals(expectedResources.size(), resources.size());
- Assert.assertTrue(resources.containsAll(expectedResources));
+ Assertions.assertTrue(resources.containsAll(expectedResources));
}
@Test
@@ -120,10 +120,10 @@ public void testGetResourcesWithUserInputAnywhere() throws Exception {
expectedResources.add("/tenants");
List resources = registryClient.getResources(resourceLookupContext);
- Assert.assertNotNull(resources);
- Assert.assertEquals(expectedResources.size(), resources.size());
+ Assertions.assertNotNull(resources);
+ Assertions.assertEquals(expectedResources.size(), resources.size());
- Assert.assertTrue(resources.containsAll(expectedResources));
+ Assertions.assertTrue(resources.containsAll(expectedResources));
}
@Test
@@ -136,17 +136,17 @@ public void testGetResourcesErrorResponse() throws NoSuchAlgorithmException, Key
try {
registryClient.getResources(resourceLookupContext);
- Assert.fail("should have thrown exception");
+ Assertions.fail("should have thrown exception");
} catch (Exception e) {
- Assert.assertTrue(e.getMessage().contains(errorMsg));
+ Assertions.assertTrue(e.getMessage().contains(errorMsg));
}
}
@Test
public void testConnectionTestSuccess() {
HashMap ret = registryClient.connectionTest();
- Assert.assertNotNull(ret);
- Assert.assertEquals(NiFiRegistryClient.SUCCESS_MSG, ret.get("message"));
+ Assertions.assertNotNull(ret);
+ Assertions.assertEquals(NiFiRegistryClient.SUCCESS_MSG, ret.get("message"));
}
@Test
@@ -155,8 +155,8 @@ public void testConnectionTestFailure() throws NoSuchAlgorithmException, KeyMana
registryClient = new MockNiFiRegistryClient(errorMsg, Response.Status.BAD_REQUEST.getStatusCode(), false, null);
HashMap ret = registryClient.connectionTest();
- Assert.assertNotNull(ret);
- Assert.assertEquals(NiFiRegistryClient.FAILURE_MSG, ret.get("message"));
+ Assertions.assertNotNull(ret);
+ Assertions.assertEquals(NiFiRegistryClient.FAILURE_MSG, ret.get("message"));
}
@Test
@@ -165,7 +165,7 @@ public void testHostnameVerifierMatch() throws NoSuchAlgorithmException, KeyMana
sslClient.setupSSLMock(HOSTNAME);
sslClient.getResponse(sslClient.getWebResource(), "application/json");
verify(sslClient.hostnameVerifierSpy).verify(eq(HOSTNAME), any(SSLSession.class));
- Assert.assertTrue(sslClient.lastVerifyResult);
+ Assertions.assertTrue(sslClient.lastVerifyResult);
}
@Test
@@ -174,7 +174,7 @@ public void testHostnameVerifierNoMatch() throws NoSuchAlgorithmException, KeyMa
sslClient.setupSSLMock("other.com");
sslClient.getResponse(sslClient.getWebResource(), "application/json");
verify(sslClient.hostnameVerifierSpy).verify(eq(HOSTNAME), any(SSLSession.class));
- Assert.assertFalse(sslClient.lastVerifyResult);
+ Assertions.assertFalse(sslClient.lastVerifyResult);
}
@Test
@@ -182,7 +182,7 @@ public void testHostnameVerifierNoCerts() throws NoSuchAlgorithmException, KeyMa
MockNiFiRegistryClient sslClient = new MockNiFiRegistryClient("", 200, true, HOSTNAME);
sslClient.setupSSLMockWithNoCerts();
sslClient.getResponse(sslClient.getWebResource(), "application/json");
- Assert.assertFalse(sslClient.lastVerifyResult);
+ Assertions.assertFalse(sslClient.lastVerifyResult);
}
@Test
@@ -190,7 +190,7 @@ public void testHostnameVerifierEmptyCerts() throws NoSuchAlgorithmException, Ke
MockNiFiRegistryClient sslClient = new MockNiFiRegistryClient("", 200, true, HOSTNAME);
sslClient.setupSSLMockWithEmptyCerts();
sslClient.getResponse(sslClient.getWebResource(), "application/json");
- Assert.assertFalse(sslClient.lastVerifyResult);
+ Assertions.assertFalse(sslClient.lastVerifyResult);
}
@Test
@@ -199,7 +199,7 @@ public void testHostnameVerifierSanInIntermediateCertsFails() throws NoSuchAlgor
sslClient.setupSSLMockWithSanInIntermediate();
sslClient.getResponse(sslClient.getWebResource(), "application/json");
verify(sslClient.hostnameVerifierSpy).verify(eq(HOSTNAME), any(SSLSession.class));
- Assert.assertFalse(sslClient.lastVerifyResult);
+ Assertions.assertFalse(sslClient.lastVerifyResult);
}
/**
diff --git a/plugin-nifi-registry/src/test/java/org/apache/ranger/services/nifi/registry/client/TestNiFiRegistryConnectionMgr.java b/plugin-nifi-registry/src/test/java/org/apache/ranger/services/nifi/registry/client/TestNiFiRegistryConnectionMgr.java
index 9bcfa13dd9..a921c00fa0 100644
--- a/plugin-nifi-registry/src/test/java/org/apache/ranger/services/nifi/registry/client/TestNiFiRegistryConnectionMgr.java
+++ b/plugin-nifi-registry/src/test/java/org/apache/ranger/services/nifi/registry/client/TestNiFiRegistryConnectionMgr.java
@@ -18,15 +18,17 @@
*/
package org.apache.ranger.services.nifi.registry.client;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
public class TestNiFiRegistryConnectionMgr {
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testValidURLWithWrongEndPoint() throws Exception {
final String nifiRegistryUrl = "http://localhost:18080/nifi-registry";
@@ -34,10 +36,10 @@ public void testValidURLWithWrongEndPoint() throws Exception {
configs.put(NiFiRegistryConfigs.NIFI_REG_URL, nifiRegistryUrl);
configs.put(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE, NiFiRegistryAuthType.NONE.name());
- NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInvalidURL() throws Exception {
final String nifiRegistryUrl = "not a url";
@@ -45,7 +47,7 @@ public void testInvalidURL() throws Exception {
configs.put(NiFiRegistryConfigs.NIFI_REG_URL, nifiRegistryUrl);
configs.put(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE, NiFiRegistryAuthType.NONE.name());
- NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs));
}
@Test
@@ -57,21 +59,21 @@ public void testAuthTypeNone() throws Exception {
configs.put(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE, NiFiRegistryAuthType.NONE.name());
NiFiRegistryClient client = NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi", configs);
- Assert.assertNotNull(client);
- Assert.assertEquals(nifiRegistryUrl, client.getUrl());
- Assert.assertNull(client.getSslContext());
+ Assertions.assertNotNull(client);
+ Assertions.assertEquals(nifiRegistryUrl, client.getUrl());
+ Assertions.assertNull(client.getSslContext());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testAuthTypeNoneMissingURL() throws Exception {
Map configs = new HashMap<>();
configs.put(NiFiRegistryConfigs.NIFI_REG_URL, null);
configs.put(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE, NiFiRegistryAuthType.NONE.name());
- NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs));
}
- @Test(expected = FileNotFoundException.class)
+ @Test
public void testAuthTypeSSL() throws Exception {
final String nifiRegistryUrl = "https://localhost:18080/nifi-registry-api/policies/resources";
@@ -87,10 +89,10 @@ public void testAuthTypeSSL() throws Exception {
configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_PASSWORD, "password");
configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_TYPE, "JKS");
- NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs);
+ assertThrows(FileNotFoundException.class, () -> NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testAuthTypeSSLWithNonHttpsUrl() throws Exception {
final String nifiRegistryUrl = "http://localhost:18080/nifi-registry-api/policies/resources";
@@ -106,10 +108,10 @@ public void testAuthTypeSSLWithNonHttpsUrl() throws Exception {
configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_PASSWORD, "password");
configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_TYPE, "JKS");
- NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testAuthTypeSSLMissingConfigs() throws Exception {
final String nifiRegistryUrl = "http://localhost:18080/nifi-registry";
@@ -117,6 +119,6 @@ public void testAuthTypeSSLMissingConfigs() throws Exception {
configs.put(NiFiRegistryConfigs.NIFI_REG_URL, nifiRegistryUrl);
configs.put(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE, NiFiRegistryAuthType.SSL.name());
- NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs));
}
}
diff --git a/plugin-nifi/pom.xml b/plugin-nifi/pom.xml
index 7883633955..15677c5498 100644
--- a/plugin-nifi/pom.xml
+++ b/plugin-nifi/pom.xml
@@ -60,13 +60,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/plugin-nifi/src/test/java/org/apache/ranger/services/nifi/client/TestNiFiClient.java b/plugin-nifi/src/test/java/org/apache/ranger/services/nifi/client/TestNiFiClient.java
index afe884c4d4..bb8c8c0ee3 100644
--- a/plugin-nifi/src/test/java/org/apache/ranger/services/nifi/client/TestNiFiClient.java
+++ b/plugin-nifi/src/test/java/org/apache/ranger/services/nifi/client/TestNiFiClient.java
@@ -21,9 +21,9 @@
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.apache.ranger.plugin.service.ResourceLookupContext;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import javax.net.ssl.HostnameVerifier;
@@ -93,7 +93,7 @@ public class TestNiFiClient {
private static final String HTTP_RESOURCES = "http://localhost:8080/nifi-api/resources";
private static final String RESPONSE_ENTITY = "{\"status\": \"success\"}";
- @Before
+ @BeforeEach
public void setup() throws NoSuchAlgorithmException, KeyManagementException {
niFiClient = new MockNiFiClient(RESOURCES_RESPONSE, 200, false, HOSTNAME);
}
@@ -112,11 +112,11 @@ public void testGetResourcesNoUserInput() throws Exception {
expectedResources.add("/resources");
List resources = niFiClient.getResources(resourceLookupContext);
- Assert.assertNotNull(resources);
- Assert.assertEquals(expectedResources.size(), resources.size());
+ Assertions.assertNotNull(resources);
+ Assertions.assertEquals(expectedResources.size(), resources.size());
resources.removeAll(expectedResources);
- Assert.assertEquals(0, resources.size());
+ Assertions.assertEquals(0, resources.size());
}
@Test
@@ -129,11 +129,11 @@ public void testGetResourcesWithUserInputBeginning() throws Exception {
expectedResources.add("/proxy");
List resources = niFiClient.getResources(resourceLookupContext);
- Assert.assertNotNull(resources);
- Assert.assertEquals(expectedResources.size(), resources.size());
+ Assertions.assertNotNull(resources);
+ Assertions.assertEquals(expectedResources.size(), resources.size());
resources.removeAll(expectedResources);
- Assert.assertEquals(0, resources.size());
+ Assertions.assertEquals(0, resources.size());
}
@Test
@@ -145,11 +145,11 @@ public void testGetResourcesWithUserInputAnywhere() throws Exception {
expectedResources.add("/controller");
List resources = niFiClient.getResources(resourceLookupContext);
- Assert.assertNotNull(resources);
- Assert.assertEquals(expectedResources.size(), resources.size());
+ Assertions.assertNotNull(resources);
+ Assertions.assertEquals(expectedResources.size(), resources.size());
resources.removeAll(expectedResources);
- Assert.assertEquals(0, resources.size());
+ Assertions.assertEquals(0, resources.size());
}
@Test
@@ -162,17 +162,17 @@ public void testGetResourcesErrorResponse() throws NoSuchAlgorithmException, Key
try {
niFiClient.getResources(resourceLookupContext);
- Assert.fail("should have thrown exception");
+ Assertions.fail("should have thrown exception");
} catch (Exception e) {
- Assert.assertTrue(e.getMessage().contains(errorMsg));
+ Assertions.assertTrue(e.getMessage().contains(errorMsg));
}
}
@Test
public void testConnectionTestSuccess() {
HashMap ret = niFiClient.connectionTest();
- Assert.assertNotNull(ret);
- Assert.assertEquals(NiFiClient.SUCCESS_MSG, ret.get("message"));
+ Assertions.assertNotNull(ret);
+ Assertions.assertEquals(NiFiClient.SUCCESS_MSG, ret.get("message"));
}
@Test
@@ -181,8 +181,8 @@ public void testConnectionTestFailure() throws NoSuchAlgorithmException, KeyMana
niFiClient = new MockNiFiClient(errorMsg, Response.Status.BAD_REQUEST.getStatusCode(), false, HOSTNAME);
HashMap ret = niFiClient.connectionTest();
- Assert.assertNotNull(ret);
- Assert.assertEquals(NiFiClient.FAILURE_MSG, ret.get("message"));
+ Assertions.assertNotNull(ret);
+ Assertions.assertEquals(NiFiClient.FAILURE_MSG, ret.get("message"));
}
@Test
@@ -191,7 +191,7 @@ public void testHostnameVerifierMatch() throws NoSuchAlgorithmException, KeyMana
sslClient.setupSSLMock(HOSTNAME);
sslClient.getResponse(sslClient.getWebResource(), "application/json");
verify(sslClient.hostnameVerifierSpy).verify(eq(HOSTNAME), any(SSLSession.class));
- Assert.assertTrue(sslClient.lastVerifyResult);
+ Assertions.assertTrue(sslClient.lastVerifyResult);
}
@Test
@@ -200,7 +200,7 @@ public void testHostnameVerifierNoMatch() throws NoSuchAlgorithmException, KeyMa
sslClient.setupSSLMock("other.com");
sslClient.getResponse(sslClient.getWebResource(), "application/json");
verify(sslClient.hostnameVerifierSpy).verify(eq(HOSTNAME), any(SSLSession.class));
- Assert.assertFalse(sslClient.lastVerifyResult);
+ Assertions.assertFalse(sslClient.lastVerifyResult);
}
@Test
@@ -208,7 +208,7 @@ public void testHostnameVerifierNoCerts() throws NoSuchAlgorithmException, KeyMa
MockNiFiClient sslClient = new MockNiFiClient(RESPONSE_ENTITY, 200, true, HOSTNAME);
sslClient.setupSSLMockWithNoCerts();
sslClient.getResponse(sslClient.getWebResource(), "application/json");
- Assert.assertFalse(sslClient.lastVerifyResult);
+ Assertions.assertFalse(sslClient.lastVerifyResult);
}
@Test
@@ -216,7 +216,7 @@ public void testHostnameVerifierEmptyCerts() throws NoSuchAlgorithmException, Ke
MockNiFiClient sslClient = new MockNiFiClient(RESPONSE_ENTITY, 200, true, HOSTNAME);
sslClient.setupSSLMockWithEmptyCerts();
sslClient.getResponse(sslClient.getWebResource(), "application/json");
- Assert.assertFalse(sslClient.lastVerifyResult);
+ Assertions.assertFalse(sslClient.lastVerifyResult);
}
@Test
@@ -225,7 +225,7 @@ public void testHostnameVerifierSanInIntermediateCertsFails() throws NoSuchAlgor
sslClient.setupSSLMockWithSanInIntermediate();
sslClient.getResponse(sslClient.getWebResource(), "application/json");
verify(sslClient.hostnameVerifierSpy).verify(eq(HOSTNAME), any(SSLSession.class));
- Assert.assertFalse(sslClient.lastVerifyResult);
+ Assertions.assertFalse(sslClient.lastVerifyResult);
}
/**
diff --git a/plugin-nifi/src/test/java/org/apache/ranger/services/nifi/client/TestNiFiConnectionMgr.java b/plugin-nifi/src/test/java/org/apache/ranger/services/nifi/client/TestNiFiConnectionMgr.java
index 925c9c3cac..a4bda9032e 100644
--- a/plugin-nifi/src/test/java/org/apache/ranger/services/nifi/client/TestNiFiConnectionMgr.java
+++ b/plugin-nifi/src/test/java/org/apache/ranger/services/nifi/client/TestNiFiConnectionMgr.java
@@ -18,15 +18,17 @@
*/
package org.apache.ranger.services.nifi.client;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
public class TestNiFiConnectionMgr {
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testValidURLWithWrongEndPoint() throws Exception {
final String nifiUrl = "http://localhost:8080/nifi";
@@ -34,10 +36,10 @@ public void testValidURLWithWrongEndPoint() throws Exception {
configs.put(NiFiConfigs.NIFI_URL, nifiUrl);
configs.put(NiFiConfigs.NIFI_AUTHENTICATION_TYPE, NiFiAuthType.NONE.name());
- NiFiConnectionMgr.getNiFiClient("nifi", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiConnectionMgr.getNiFiClient("nifi", configs));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInvalidURL() throws Exception {
final String nifiUrl = "not a url";
@@ -45,7 +47,7 @@ public void testInvalidURL() throws Exception {
configs.put(NiFiConfigs.NIFI_URL, nifiUrl);
configs.put(NiFiConfigs.NIFI_AUTHENTICATION_TYPE, NiFiAuthType.NONE.name());
- NiFiConnectionMgr.getNiFiClient("nifi", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiConnectionMgr.getNiFiClient("nifi", configs));
}
@Test
@@ -57,21 +59,21 @@ public void testAuthTypeNone() throws Exception {
configs.put(NiFiConfigs.NIFI_AUTHENTICATION_TYPE, NiFiAuthType.NONE.name());
NiFiClient client = NiFiConnectionMgr.getNiFiClient("nifi", configs);
- Assert.assertNotNull(client);
- Assert.assertEquals(nifiUrl, client.getUrl());
- Assert.assertNull(client.getSslContext());
+ Assertions.assertNotNull(client);
+ Assertions.assertEquals(nifiUrl, client.getUrl());
+ Assertions.assertNull(client.getSslContext());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testAuthTypeNoneMissingURL() throws Exception {
Map configs = new HashMap<>();
configs.put(NiFiConfigs.NIFI_URL, null);
configs.put(NiFiConfigs.NIFI_AUTHENTICATION_TYPE, NiFiAuthType.NONE.name());
- NiFiConnectionMgr.getNiFiClient("nifi", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiConnectionMgr.getNiFiClient("nifi", configs));
}
- @Test(expected = FileNotFoundException.class)
+ @Test
public void testAuthTypeSSL() throws Exception {
final String nifiUrl = "https://localhost:8080/nifi-api/resources";
@@ -87,10 +89,10 @@ public void testAuthTypeSSL() throws Exception {
configs.put(NiFiConfigs.NIFI_SSL_TRUSTSTORE_PASSWORD, "password");
configs.put(NiFiConfigs.NIFI_SSL_TRUSTSTORE_TYPE, "JKS");
- NiFiConnectionMgr.getNiFiClient("nifi", configs);
+ assertThrows(FileNotFoundException.class, () -> NiFiConnectionMgr.getNiFiClient("nifi", configs));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testAuthTypeSSLWithNonHttpsUrl() throws Exception {
final String nifiUrl = "http://localhost:8080/nifi-api/resources";
@@ -106,10 +108,10 @@ public void testAuthTypeSSLWithNonHttpsUrl() throws Exception {
configs.put(NiFiConfigs.NIFI_SSL_TRUSTSTORE_PASSWORD, "password");
configs.put(NiFiConfigs.NIFI_SSL_TRUSTSTORE_TYPE, "JKS");
- NiFiConnectionMgr.getNiFiClient("nifi", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiConnectionMgr.getNiFiClient("nifi", configs));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testAuthTypeSSLMissingConfigs() throws Exception {
final String nifiUrl = "http://localhost:8080/nifi";
@@ -117,6 +119,6 @@ public void testAuthTypeSSLMissingConfigs() throws Exception {
configs.put(NiFiConfigs.NIFI_URL, nifiUrl);
configs.put(NiFiConfigs.NIFI_AUTHENTICATION_TYPE, NiFiAuthType.SSL.name());
- NiFiConnectionMgr.getNiFiClient("nifi", configs);
+ assertThrows(IllegalArgumentException.class, () -> NiFiConnectionMgr.getNiFiClient("nifi", configs));
}
}
diff --git a/plugin-presto/pom.xml b/plugin-presto/pom.xml
index 6c37912825..a67e39dd2f 100644
--- a/plugin-presto/pom.xml
+++ b/plugin-presto/pom.xml
@@ -103,13 +103,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/plugin-presto/src/test/java/org/apache/ranger/authorization/presto/authorizer/RangerSystemAccessControlTest.java b/plugin-presto/src/test/java/org/apache/ranger/authorization/presto/authorizer/RangerSystemAccessControlTest.java
index 5d6005f60f..5a66718743 100644
--- a/plugin-presto/src/test/java/org/apache/ranger/authorization/presto/authorizer/RangerSystemAccessControlTest.java
+++ b/plugin-presto/src/test/java/org/apache/ranger/authorization/presto/authorizer/RangerSystemAccessControlTest.java
@@ -28,8 +28,8 @@
import io.prestosql.spi.security.ViewExpression;
import io.prestosql.spi.type.VarcharType;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import javax.security.auth.kerberos.KerberosPrincipal;
@@ -40,9 +40,9 @@
import static io.prestosql.spi.security.PrincipalType.USER;
import static io.prestosql.spi.security.Privilege.SELECT;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class RangerSystemAccessControlTest {
private static final Identity alice = Identity.ofUser("alice");
@@ -63,7 +63,7 @@ public class RangerSystemAccessControlTest {
private static final String functionName = new String("function");
static RangerSystemAccessControl accessControlManager;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
Map config = new HashMap<>();
accessControlManager = new RangerSystemAccessControl(config);
diff --git a/plugin-schema-registry/pom.xml b/plugin-schema-registry/pom.xml
index e0b4fa2bb7..c8514ac0ff 100644
--- a/plugin-schema-registry/pom.xml
+++ b/plugin-schema-registry/pom.xml
@@ -273,17 +273,15 @@
${commons.text.version}
test
-
-
- org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
+ org.hamcrest
+ hamcrest
+ ${hamcrest.version}
test
- org.junit.vintage
- junit-vintage-engine
+ org.junit.jupiter
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/AutocompletionAgentTest.java b/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/AutocompletionAgentTest.java
index 1321761d28..e578ec82ac 100644
--- a/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/AutocompletionAgentTest.java
+++ b/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/AutocompletionAgentTest.java
@@ -19,16 +19,16 @@
import org.apache.ranger.services.schema.registry.client.connection.ISchemaRegistryClient;
import org.apache.ranger.services.schema.registry.client.util.DefaultSchemaRegistryClientForTesting;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class AutocompletionAgentTest {
@Test
diff --git a/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/SchemaRegistryResourceMgrTest.java b/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/SchemaRegistryResourceMgrTest.java
index b374b0261d..494f3ea1f0 100644
--- a/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/SchemaRegistryResourceMgrTest.java
+++ b/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/SchemaRegistryResourceMgrTest.java
@@ -19,15 +19,15 @@
import org.apache.ranger.plugin.service.ResourceLookupContext;
import org.apache.ranger.services.schema.registry.client.util.TestAutocompletionAgent;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
public class SchemaRegistryResourceMgrTest {
@Test
diff --git a/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/connection/DefaultSchemaRegistryClientTest.java b/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/connection/DefaultSchemaRegistryClientTest.java
index 0a006b4796..5a249380f5 100644
--- a/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/connection/DefaultSchemaRegistryClientTest.java
+++ b/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/connection/DefaultSchemaRegistryClientTest.java
@@ -22,8 +22,8 @@
import com.hortonworks.registries.schemaregistry.SchemaVersion;
import com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer;
import org.apache.commons.io.IOUtils;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
@@ -35,19 +35,20 @@
import java.util.Map;
import static com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
-@org.junit.Ignore
+@org.junit.jupiter.api.Disabled
public class DefaultSchemaRegistryClientTest {
private static final String V1_API_PATH = "api/v1";
private static LocalSchemaRegistryServer localSchemaRegistryServer;
private static ISchemaRegistryClient client;
- @BeforeClass
+ @BeforeAll
public static void init() throws Exception {
localSchemaRegistryServer = new LocalSchemaRegistryServer(getFilePath("ssl-schema-registry.yaml"));
@@ -146,9 +147,9 @@ public void checkConnection() {
}
}
- @Test(expected = Exception.class)
+ @Test
public void checkConnection2() throws Exception {
- new DefaultSchemaRegistryClient(new HashMap<>()).checkConnection();
+ assertThrows(Exception.class, () -> new DefaultSchemaRegistryClient(new HashMap<>()).checkConnection());
}
private static String getSchema(String schemaFileName) throws Exception {
diff --git a/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/connection/util/SecurityUtilsTest.java b/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/connection/util/SecurityUtilsTest.java
index b3484571e2..f7ad9751e0 100644
--- a/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/connection/util/SecurityUtilsTest.java
+++ b/plugin-schema-registry/src/test/java/org/apache/ranger/services/schema/registry/client/connection/util/SecurityUtilsTest.java
@@ -17,7 +17,7 @@
package org.apache.ranger.services.schema.registry.client.connection.util;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLContext;
@@ -28,11 +28,11 @@
import static org.apache.ranger.plugin.client.HadoopConfigHolder.RANGER_AUTH_TYPE;
import static org.apache.ranger.plugin.client.HadoopConfigHolder.RANGER_LOOKUP_KEYTAB;
import static org.apache.ranger.plugin.client.HadoopConfigHolder.RANGER_LOOKUP_PRINCIPAL;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class SecurityUtilsTest {
@Test
diff --git a/plugin-sqoop/pom.xml b/plugin-sqoop/pom.xml
index 2fb8f76a99..b101d20902 100644
--- a/plugin-sqoop/pom.xml
+++ b/plugin-sqoop/pom.xml
@@ -105,13 +105,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/plugin-sqoop/src/test/java/org/apache/ranger/authorization/sqoop/authorizer/RangerSqoopAuthorizerTest.java b/plugin-sqoop/src/test/java/org/apache/ranger/authorization/sqoop/authorizer/RangerSqoopAuthorizerTest.java
index 0f8975b281..aa019632fa 100644
--- a/plugin-sqoop/src/test/java/org/apache/ranger/authorization/sqoop/authorizer/RangerSqoopAuthorizerTest.java
+++ b/plugin-sqoop/src/test/java/org/apache/ranger/authorization/sqoop/authorizer/RangerSqoopAuthorizerTest.java
@@ -27,17 +27,18 @@
import org.apache.sqoop.repository.RepositoryManager;
import org.apache.sqoop.security.AuthorizationManager;
import org.apache.sqoop.security.authorization.AuthorizationEngine;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -55,7 +56,7 @@
* d) A user "yuwen" can do "read" and "write" on the link "oracle-link" and "hdfs-link";
* e) A user "yuwen" can do "read" and "write" on the job "oracle2hdfs-job";
*/
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@TestMethodOrder(MethodOrderer.MethodName.class)
public class RangerSqoopAuthorizerTest {
private static final List allConnectors = new ArrayList<>();
@@ -85,7 +86,7 @@ public class RangerSqoopAuthorizerTest {
private static final String ORACLE2HDFS_JOB = "oracle2hdfs-job";
- @BeforeClass
+ @BeforeAll
public static void setup() throws Exception {
// init sqoop all connectors
addAllConnectors();
@@ -94,7 +95,7 @@ public static void setup() throws Exception {
initSqoopAuth();
}
- @AfterClass
+ @AfterAll
public static void cleanup() throws Exception {
// do nothing
}
@@ -123,11 +124,11 @@ public void readConnectorKafkaWithReadPermission() {
/**
* zhangqiang read hdfs-connector failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void readConnectorHdfsWithoutPermission() {
String user = ZHANGQIANG;
String connector = HDFS_CONNECTOR;
- AuthorizationEngine.readConnector(user, connector);
+ assertThrows(SqoopException.class, () -> AuthorizationEngine.readConnector(user, connector));
}
/**
@@ -155,11 +156,11 @@ public void readConnectorHdfsWithAllPermissions() {
/**
* yuwen read kafka-connector failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void readConnectorKafkaWithoutPermission() {
String user = YUWEN;
String connector = KAFKA_CONNECTOR;
- AuthorizationEngine.readConnector(user, connector);
+ assertThrows(SqoopException.class, () -> AuthorizationEngine.readConnector(user, connector));
}
/**
@@ -209,11 +210,11 @@ public void readLinkHdfsWithReadPermission() {
/**
* yuwen read any link failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void readLinkAnyWithoutPermission() {
String user = YUWEN;
String link = getRandomLinkName();
- AuthorizationEngine.readLink(user, link);
+ assertThrows(SqoopException.class, () -> AuthorizationEngine.readLink(user, link));
}
/**
@@ -240,11 +241,11 @@ public void createLinkByKafkaConnectorWithReadPermission() {
/**
* zhangqiang create link by hdfs-connector failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void createLinkByHdfsConnectorWithoutPermission() {
String user = ZHANGQIANG;
String connector = HDFS_CONNECTOR;
- AuthorizationEngine.createLink(user, connector);
+ assertThrows(SqoopException.class, () -> AuthorizationEngine.createLink(user, connector));
}
/**
@@ -274,11 +275,11 @@ public void createLinkByHdfsConnectorWithReadPermission() {
/**
* yuwen create link by kafka-connector failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void createLinkByKafkaConnectorWithoutPermission() {
String user = YUWEN;
String connector = KAFKA_CONNECTOR;
- AuthorizationEngine.createLink(user, connector);
+ assertThrows(SqoopException.class, () -> AuthorizationEngine.createLink(user, connector));
}
/**
@@ -307,12 +308,12 @@ public void updateLinkAnyByKafkaConnectorAsCreater() {
/**
* zhangqiang update any link created by hdfs-connector failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void updateLinkAnyByHdfsConnectorWithoutPermission() {
String user = ZHANGQIANG;
String connector = HDFS_CONNECTOR;
String link = getRandomLinkName();
- AuthorizationEngine.updateLink(user, connector, link);
+ assertThrows(SqoopException.class, () -> AuthorizationEngine.updateLink(user, connector, link));
}
/**
@@ -344,12 +345,14 @@ public void updateLinkByHdfsConnectorWithReadPermission() {
/**
* yuwen update link created by kafka-connector failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void updateLinkByKafkaConnectorWithoutPermission() {
- String user = YUWEN;
- String connector = KAFKA_CONNECTOR;
- String link = getRandomLinkName();
- AuthorizationEngine.updateLink(user, connector, link);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String connector = KAFKA_CONNECTOR;
+ String link = getRandomLinkName();
+ AuthorizationEngine.updateLink(user, connector, link);
+ });
}
/**
@@ -399,11 +402,13 @@ public void deleteLinkHdfsWithWritePermission() {
/**
* yuwen delete any link failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void deleteLinkAnyWithoutPermission() {
- String user = YUWEN;
- String link = getRandomLinkName();
- AuthorizationEngine.deleteLink(user, link);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String link = getRandomLinkName();
+ AuthorizationEngine.deleteLink(user, link);
+ });
}
/**
@@ -453,11 +458,13 @@ public void enableDisableLinkHdfsWithWritePermission() {
/**
* yuwen enable disable any link failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void enableDisableLinkAnyWithoutPermission() {
- String user = YUWEN;
- String link = getRandomLinkName();
- AuthorizationEngine.enableDisableLink(user, link);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String link = getRandomLinkName();
+ AuthorizationEngine.enableDisableLink(user, link);
+ });
}
/**
@@ -493,11 +500,13 @@ public void readJobOracle2HdfsWithReadPermission() {
/**
* yuwen read any job failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void readJobAnyWithoutPermission() {
- String user = YUWEN;
- String job = getRandomJobName();
- AuthorizationEngine.readJob(user, job);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String job = getRandomJobName();
+ AuthorizationEngine.readJob(user, job);
+ });
}
// No.6 enableDisableLink test end
@@ -540,12 +549,14 @@ public void createJobFromOracle2HdfsLinkWithReadPermission() {
/**
* yuwen create job from oracle-link to any link failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void createJobFromOracle2AnyLinkWithoutPermission() {
- String user = YUWEN;
- String link1 = ORACLE_LINK;
- String link2 = getRandomLinkName();
- AuthorizationEngine.createJob(user, link1, link2);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String link1 = ORACLE_LINK;
+ String link2 = getRandomLinkName();
+ AuthorizationEngine.createJob(user, link1, link2);
+ });
}
// No.7 readJob test end
@@ -555,12 +566,14 @@ public void createJobFromOracle2AnyLinkWithoutPermission() {
/**
* yuwen create job by any two links failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void createJobByAnyTwoLinksWithoutPermission() {
- String user = YUWEN;
- String link1 = getRandomLinkName();
- String link2 = getRandomLinkName();
- AuthorizationEngine.createJob(user, link1, link2);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String link1 = getRandomLinkName();
+ String link2 = getRandomLinkName();
+ AuthorizationEngine.createJob(user, link1, link2);
+ });
}
/**
@@ -604,13 +617,15 @@ public void updateJobOracle2HdfsByTwoLinksWithWritePermission() {
* yuwen update oracle2hdfs-job created from new_oracle-link to hdfs-link
* failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void updateJobOracle2HdfsByTwoLinksWithoutPermission() {
- String user = YUWEN;
- String link1 = "new_" + ORACLE_LINK;
- String link2 = HDFS_LINK;
- String job = ORACLE2HDFS_JOB;
- AuthorizationEngine.updateJob(user, link1, link2, job);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String link1 = "new_" + ORACLE_LINK;
+ String link2 = HDFS_LINK;
+ String job = ORACLE2HDFS_JOB;
+ AuthorizationEngine.updateJob(user, link1, link2, job);
+ });
}
// No.8 createJob test end
@@ -620,25 +635,29 @@ public void updateJobOracle2HdfsByTwoLinksWithoutPermission() {
/**
* yuwen update any job created from oracle-link to hdfs-link failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void updateJobAnyByTwoLinksWithoutPermission() {
- String user = YUWEN;
- String link1 = ORACLE_LINK;
- String link2 = HDFS_LINK;
- String job = getRandomJobName();
- AuthorizationEngine.updateJob(user, link1, link2, job);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String link1 = ORACLE_LINK;
+ String link2 = HDFS_LINK;
+ String job = getRandomJobName();
+ AuthorizationEngine.updateJob(user, link1, link2, job);
+ });
}
/**
* yuwen update any job created from oracle-link to hdfs-link failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void updateJobAnyByAnyLinksWithoutPermission() {
- String user = YUWEN;
- String link1 = getRandomLinkName();
- String link2 = getRandomLinkName();
- String job = getRandomJobName();
- AuthorizationEngine.updateJob(user, link1, link2, job);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String link1 = getRandomLinkName();
+ String link2 = getRandomLinkName();
+ String job = getRandomJobName();
+ AuthorizationEngine.updateJob(user, link1, link2, job);
+ });
}
/**
@@ -674,11 +693,13 @@ public void deleteJobOracle2HdfsWithWritePermission() {
/**
* yuwen delete any job failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void deleteJobAnyWithoutPermission() {
- String user = YUWEN;
- String job = getRandomJobName();
- AuthorizationEngine.deleteJob(user, job);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String job = getRandomJobName();
+ AuthorizationEngine.deleteJob(user, job);
+ });
}
// No.9 updateJob test end
@@ -718,11 +739,13 @@ public void enableDisableJobOracle2HdfsWithWritePermission() {
/**
* yuwen enable disable any job failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void enableDisableJobAnyWithoutPermission() {
- String user = YUWEN;
- String job = getRandomJobName();
- AuthorizationEngine.enableDisableJob(user, job);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String job = getRandomJobName();
+ AuthorizationEngine.enableDisableJob(user, job);
+ });
}
// No.10 deleteJob test end
@@ -762,11 +785,13 @@ public void startJobOracle2HdfsWithWritePermission() {
/**
* yuwen start any job failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void startJobAnyWithoutPermission() {
- String user = YUWEN;
- String job = getRandomJobName();
- AuthorizationEngine.startJob(user, job);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String job = getRandomJobName();
+ AuthorizationEngine.startJob(user, job);
+ });
}
// No.11 enableDisableJob test end
@@ -806,11 +831,13 @@ public void stopJobOracle2HdfsWithWritePermission() {
/**
* yuwen stop any job failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void stopJobAnyWithoutPermission() {
- String user = YUWEN;
- String job = getRandomJobName();
- AuthorizationEngine.stopJob(user, job);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String job = getRandomJobName();
+ AuthorizationEngine.stopJob(user, job);
+ });
}
// No.12 startJob test end
@@ -850,11 +877,13 @@ public void statusJobOracle2HdfsWithReadPermission() {
/**
* yuwen status status job failed
*/
- @Test(expected = SqoopException.class)
+ @Test
public void statusJobAnyWithoutPermission() {
- String user = YUWEN;
- String job = getRandomJobName();
- AuthorizationEngine.statusJob(user, job);
+ assertThrows(SqoopException.class, () -> {
+ String user = YUWEN;
+ String job = getRandomJobName();
+ AuthorizationEngine.statusJob(user, job);
+ });
}
// No.13 stopJob test end
@@ -877,9 +906,7 @@ private static void addAllConnectors() {
/**
* Help function: init sqoop to enable ranger authentication
*/
- private static void initSqoopAuth() throws IOException, ClassNotFoundException, IllegalAccessException,
- InstantiationException {
- // init sqoop configruation
+ private static void initSqoopAuth() throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { // init sqoop configruation
String basedir = System.getProperty("basedir");
if (basedir == null) {
basedir = new File(".").getCanonicalPath();
diff --git a/plugin-trino/pom.xml b/plugin-trino/pom.xml
index 4d36649ab4..cef81fbf76 100644
--- a/plugin-trino/pom.xml
+++ b/plugin-trino/pom.xml
@@ -163,13 +163,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/pom.xml b/pom.xml
index db387ca011..52cb11cc5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -348,13 +348,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/ranger-authn/pom.xml b/ranger-authn/pom.xml
index 7507f55d1e..3af6913b50 100644
--- a/ranger-authn/pom.xml
+++ b/ranger-authn/pom.xml
@@ -67,7 +67,8 @@
org.junit.jupiter
- junit-jupiter-api
+ junit-jupiter
+ ${junit.jupiter.version}
test
diff --git a/ranger-common-ha/pom.xml b/ranger-common-ha/pom.xml
index 5bb0507397..8a091a8a0b 100644
--- a/ranger-common-ha/pom.xml
+++ b/ranger-common-ha/pom.xml
@@ -135,7 +135,7 @@
org.junit.jupiter
- junit-jupiter-api
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/ranger-examples/conditions-enrichers/pom.xml b/ranger-examples/conditions-enrichers/pom.xml
index 6be7a4829a..b61eb74332 100644
--- a/ranger-examples/conditions-enrichers/pom.xml
+++ b/ranger-examples/conditions-enrichers/pom.xml
@@ -35,7 +35,7 @@
org.junit.jupiter
- junit-jupiter-api
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/ranger-hbase-plugin-shim/src/main/test/org/apache/hadoop/hbase/security/access/RangerAccessControlListsTest.java b/ranger-hbase-plugin-shim/src/main/test/org/apache/hadoop/hbase/security/access/RangerAccessControlListsTest.java
index cdc27531e3..12283a9704 100644
--- a/ranger-hbase-plugin-shim/src/main/test/org/apache/hadoop/hbase/security/access/RangerAccessControlListsTest.java
+++ b/ranger-hbase-plugin-shim/src/main/test/org/apache/hadoop/hbase/security/access/RangerAccessControlListsTest.java
@@ -55,6 +55,6 @@ public void testInit() {
} catch (IOException e) {
exceptionFound = e;
}
- Assert.assertFalse("Expected to get a NullPointerExecution after init method Execution - Found [" + exceptionFound + "]", (!(exceptionFound != null && exceptionFound.getCause() instanceof NullPointerException)));
+ Assert.assertFalse((!(exceptionFound != null && exceptionFound.getCause() instanceof NullPointerException)), "Expected to get a NullPointerExecution after init method Execution - Found [" + exceptionFound + "]");
}
}
diff --git a/ranger-knox-plugin-shim/pom.xml b/ranger-knox-plugin-shim/pom.xml
index 22d4be64d9..662da04529 100644
--- a/ranger-knox-plugin-shim/pom.xml
+++ b/ranger-knox-plugin-shim/pom.xml
@@ -68,13 +68,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/ranger-metrics/pom.xml b/ranger-metrics/pom.xml
index 60869cff67..a595c68d61 100644
--- a/ranger-metrics/pom.xml
+++ b/ranger-metrics/pom.xml
@@ -58,13 +58,8 @@
org.junit.jupiter
- junit-jupiter-api
- test
-
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
+ ${junit.jupiter.version}
test
diff --git a/ranger-metrics/src/test/java/org/apache/ranger/metrics/source/TestRangerMetricsContainerSource.java b/ranger-metrics/src/test/java/org/apache/ranger/metrics/source/TestRangerMetricsContainerSource.java
index 3ba03764a4..1906a78cb4 100644
--- a/ranger-metrics/src/test/java/org/apache/ranger/metrics/source/TestRangerMetricsContainerSource.java
+++ b/ranger-metrics/src/test/java/org/apache/ranger/metrics/source/TestRangerMetricsContainerSource.java
@@ -22,12 +22,12 @@
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.ranger.metrics.RangerMetricsSystemWrapper;
import org.apache.ranger.server.tomcat.EmbeddedServerMetricsCollector;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.List;
@@ -43,28 +43,28 @@ public class TestRangerMetricsContainerSource {
public TestRangerMetricsContainerSource() {
}
- @BeforeClass
+ @BeforeAll
public static void init() {
metricsSystem = DefaultMetricsSystem.instance();
TestRangerMetricsContainerSource.rangerMetricsSystemWrapper = new RangerMetricsSystemWrapper();
TestRangerMetricsContainerSource.rangerMetricsSystemWrapper.init("test", null, (List) null);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
metricsSystem.shutdown();
}
/* Without proper start of EmbeddedServer, embeddedServerMetricsCollector will return null.
That's why, mocked instance should be injected here. */
- @Before
+ @BeforeEach
public void before() {
embeddedServerMetricsCollector = mock(EmbeddedServerMetricsCollector.class);
((RangerMetricsContainerSource) DefaultMetricsSystem.instance().getSource(CONTAINER_METRIC_SOURCE_NAME)).setEmbeddedServerMetricsCollector(embeddedServerMetricsCollector);
}
// Resetting it back to original state.
- @After
+ @AfterEach
public void after() {
((RangerMetricsContainerSource) DefaultMetricsSystem.instance().getSource(CONTAINER_METRIC_SOURCE_NAME)).setEmbeddedServerMetricsCollector(null);
}
@@ -92,14 +92,14 @@ public void testContainerMetricsCollection() {
metricsSystem.publishMetricsNow();
- Assert.assertEquals(1L, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("ActiveConnectionsCount"));
- Assert.assertEquals(60000L, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("ConnectionTimeout"));
- Assert.assertEquals(200, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("MaxWorkerThreadsCount"));
- Assert.assertEquals(15, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("TotalWorkerThreadsCount"));
- Assert.assertEquals(60000L, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("KeepAliveTimeout"));
- Assert.assertEquals(2, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("ActiveWorkerThreadsCount"));
- Assert.assertEquals(100, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("ConnectionAcceptCount"));
- Assert.assertEquals(10, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("MinSpareWorkerThreadsCount"));
- Assert.assertEquals(8192L, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("MaxConnectionsCount"));
+ Assertions.assertEquals(1L, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("ActiveConnectionsCount"));
+ Assertions.assertEquals(60000L, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("ConnectionTimeout"));
+ Assertions.assertEquals(200, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("MaxWorkerThreadsCount"));
+ Assertions.assertEquals(15, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("TotalWorkerThreadsCount"));
+ Assertions.assertEquals(60000L, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("KeepAliveTimeout"));
+ Assertions.assertEquals(2, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("ActiveWorkerThreadsCount"));
+ Assertions.assertEquals(100, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("ConnectionAcceptCount"));
+ Assertions.assertEquals(10, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("MinSpareWorkerThreadsCount"));
+ Assertions.assertEquals(8192L, rangerMetricsSystemWrapper.getRangerMetrics().get("RangerWebContainer").get("MaxConnectionsCount"));
}
}
diff --git a/ranger-plugin-classloader/pom.xml b/ranger-plugin-classloader/pom.xml
index 49a6a6e47d..7687c2f6fe 100644
--- a/ranger-plugin-classloader/pom.xml
+++ b/ranger-plugin-classloader/pom.xml
@@ -39,13 +39,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/ranger-tools/pom.xml b/ranger-tools/pom.xml
index 2a503db00f..1efaa539e6 100644
--- a/ranger-tools/pom.xml
+++ b/ranger-tools/pom.xml
@@ -78,13 +78,7 @@
org.junit.jupiter
- junit-jupiter-api
- ${junit.jupiter.version}
- test
-
-
- org.junit.vintage
- junit-vintage-engine
+ junit-jupiter
${junit.jupiter.version}
test
diff --git a/ranger-tools/src/test/java/org/apache/ranger/policyengine/PerfTesterTest.java b/ranger-tools/src/test/java/org/apache/ranger/policyengine/PerfTesterTest.java
index 22ae79358f..debd367506 100644
--- a/ranger-tools/src/test/java/org/apache/ranger/policyengine/PerfTesterTest.java
+++ b/ranger-tools/src/test/java/org/apache/ranger/policyengine/PerfTesterTest.java
@@ -19,8 +19,8 @@
package org.apache.ranger.policyengine;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import java.io.BufferedReader;
import java.io.InputStream;
@@ -51,7 +51,7 @@ public void testArgParsing() {
if (args != null) {
CommandLineParser commandLineParser = new CommandLineParser();
PerfTestOptions parseResult = commandLineParser.parse(args);
- Assert.assertNotNull(parseResult);
+ Assertions.assertNotNull(parseResult);
}
}
diff --git a/ranger-tools/src/test/java/org/apache/ranger/policyengine/RangerPolicyEnginePerformanceTest.java b/ranger-tools/src/test/java/org/apache/ranger/policyengine/RangerPolicyEnginePerformanceTest.java
index 97e32b11c7..0a8dfa330a 100644
--- a/ranger-tools/src/test/java/org/apache/ranger/policyengine/RangerPolicyEnginePerformanceTest.java
+++ b/ranger-tools/src/test/java/org/apache/ranger/policyengine/RangerPolicyEnginePerformanceTest.java
@@ -30,7 +30,6 @@
import org.apache.hadoop.thirdparty.com.google.common.cache.CacheLoader;
import org.apache.hadoop.thirdparty.com.google.common.cache.LoadingCache;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap;
-import org.apache.hadoop.thirdparty.com.google.common.collect.Iterables;
import org.apache.hadoop.thirdparty.com.google.common.collect.Lists;
import org.apache.hadoop.thirdparty.com.google.common.collect.Sets;
import org.apache.hadoop.thirdparty.com.google.common.collect.Table;
@@ -45,15 +44,13 @@
import org.apache.ranger.plugin.util.PerfDataRecorder.PerfStatistic;
import org.apache.ranger.plugin.util.ServicePolicies;
import org.apache.ranger.policyengine.perftest.v2.RangerPolicyFactory;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameter;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import java.io.File;
import java.io.IOException;
@@ -64,6 +61,7 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
+import java.util.stream.Stream;
import static org.apache.hadoop.thirdparty.com.google.common.collect.Iterables.get;
@@ -72,7 +70,6 @@
* A cross product of the input parameters are generated and fed into the test method.
* This microbenchmark includes a warm-up phase so that any of the JIT performance optimizations happen before the measurement of the policy engine's performance.
*/
-@RunWith(Parameterized.class)
public class RangerPolicyEnginePerformanceTest {
private static final String STATISTICS_KEY__ACCESS_ALLOWED = "RangerPolicyEngine.isAccessAllowed";
@@ -82,34 +79,32 @@ public class RangerPolicyEnginePerformanceTest {
private static final LoadingCache> requestsCache = CacheBuilder.newBuilder().build(createAccessRequestsCacheLoader());
private static final LoadingCache servicePoliciesCache = CacheBuilder.newBuilder().build(createServicePoliciesCacheLoader());
- @Parameter(0)
- public Integer numberOfPolicies;
-
- @Parameter(1)
- public Integer concurrency;
+ private Integer lastNumberOfPolicies;
+ private Integer lastConcurrency;
/**
* Generates a cross product of number-of-policies X concurrency parameter sets.
*
* @returns a collection of "tuples" (Object[]) of numberOfPolicies and concurrency for the given test run
*/
- @Parameters(name = "{index}: isAccessAllowed(policies: {0}, concurrent calls: {1})")
- public static Iterable