Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
Expand Down Expand Up @@ -180,9 +185,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/casbin/jcasbin/main/AbacAPIUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.casbin.jcasbin.main;

import org.casbin.jcasbin.util.Util;
import org.junit.Test;
import org.testng.annotations.Test;
import java.util.Map;
import java.util.HashMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.googlecode.aviator.AviatorEvaluatorInstance;
import org.casbin.jcasbin.util.BuiltInFunctions;
import org.casbin.jcasbin.util.Util;
import org.junit.Test;
import org.testng.annotations.Test;
import org.mockito.BDDMockito;
import org.mockito.MockedStatic;

Expand Down
24 changes: 12 additions & 12 deletions src/test/java/org/casbin/jcasbin/main/CachedEnforcerUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import org.casbin.jcasbin.persist.cache.Cache;
import org.casbin.jcasbin.persist.cache.CacheableParam;
import org.casbin.jcasbin.persist.cache.DefaultCache;
import org.junit.Test;
import org.testng.annotations.Test;

import java.time.Duration;

import static org.junit.Assert.*;
import static org.testng.Assert.*;

public class CachedEnforcerUnitTest {
private CachedEnforcer cachedEnforcer;
Expand All @@ -30,7 +30,7 @@ public class CachedEnforcerUnitTest {

private void testEnforceCache(String sub, String obj, String act, boolean expectedRes) throws Exception {
Boolean actualRes = cachedEnforcer.enforce(sub, obj, act);
assertEquals(String.format("%s, %s, %s: %s, supposed to be %s", sub, obj, act, actualRes, expectedRes), expectedRes, actualRes);
assertEquals(actualRes.booleanValue(), expectedRes, String.format("%s, %s, %s: %s, supposed to be %s", sub, obj, act, actualRes, expectedRes));
}

@Test
Expand Down Expand Up @@ -88,16 +88,16 @@ public void testInvalidateCache() throws Exception {
cachedEnforcer = new CachedEnforcer("examples/basic_model.conf", "examples/basic_policy.csv", false);

Boolean cacheKey = cachedEnforcer.getCache().get(cachedEnforcer.getCacheKey("alice", "data1", "read"));
assertNull(String.format("alice, data1, read: %s, supposed to be %s", cacheKey, null), cacheKey);
assertNull(cacheKey, String.format("alice, data1, read: %s, supposed to be %s", cacheKey, null));

Boolean actualRes = cachedEnforcer.enforce("alice", "data1", "read");
cacheKey = cachedEnforcer.getCache().get(cachedEnforcer.getCacheKey("alice", "data1", "read"));
assertTrue(String.format("alice, data1, read: %s, supposed to be %s", actualRes, true), actualRes);
assertTrue(String.format("alice, data1, read: %s, supposed to be %s", cacheKey, true), cacheKey);
assertTrue(actualRes, String.format("alice, data1, read: %s, supposed to be %s", actualRes, true));
assertTrue(cacheKey, String.format("alice, data1, read: %s, supposed to be %s", cacheKey, true));

cachedEnforcer.invalidateCache();
cacheKey = cachedEnforcer.getCache().get(cachedEnforcer.getCacheKey("alice", "data1", "read"));
assertNull(String.format("alice, data1, read: %s, supposed to be %s", cacheKey, null), cacheKey);
assertNull(cacheKey, String.format("alice, data1, read: %s, supposed to be %s", cacheKey, null));

}

Expand Down Expand Up @@ -133,28 +133,28 @@ public void testCacheExpiration() throws Exception {
cache.set(getKey("alice", "data1", "read"),true,Duration.ofMillis(10));
cachedEnforcer.setCache(cache);
Boolean cacheKey = cachedEnforcer.getCache().get(cachedEnforcer.getCacheKey("alice", "data1", "read"));
assertTrue(String.format("alice, data1, read: %s, supposed to be %s", cacheKey, true), cacheKey);
assertTrue(cacheKey, String.format("alice, data1, read: %s, supposed to be %s", cacheKey, true));

// Wait for the cache to expire
Thread.sleep(15);

cacheKey = cachedEnforcer.getCache().get(cachedEnforcer.getCacheKey("alice", "data1", "read"));
assertNull(String.format("alice, data1, read: %s, supposed to be %s", cacheKey, null), cacheKey);
assertNull(cacheKey, String.format("alice, data1, read: %s, supposed to be %s", cacheKey, null));

// Replace cache during test run
cache.clear();
cache.set(getKey("bob", "data1", "read"),true,Duration.ofMillis(1000));
cachedEnforcer.setCache(cache);
cacheKey = cachedEnforcer.getCache().get(cachedEnforcer.getCacheKey("bob", "data1", "read"));
assertTrue(String.format("bob, data1, read: %s, supposed to be %s", cacheKey, true), cacheKey);
assertTrue(cacheKey, String.format("bob, data1, read: %s, supposed to be %s", cacheKey, true));

cache.clear();
cache.set(getKey("jack", "data1", "write"),true,Duration.ofMillis(1000));
cachedEnforcer.setCache(cache);
cacheKey = cachedEnforcer.getCache().get(cachedEnforcer.getCacheKey("bob", "data1", "read"));
assertNull(String.format("bob, data1, read: %s, supposed to be %s", cacheKey, null), cacheKey);
assertNull(cacheKey, String.format("bob, data1, read: %s, supposed to be %s", cacheKey, null));

cacheKey = cachedEnforcer.getCache().get(cachedEnforcer.getCacheKey("jack", "data1", "write"));
assertTrue(String.format("jack, data1, write: %s, supposed to be %s", cacheKey, true), cacheKey);
assertTrue(cacheKey, String.format("jack, data1, write: %s, supposed to be %s", cacheKey, true));
}
}
6 changes: 3 additions & 3 deletions src/test/java/org/casbin/jcasbin/main/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import org.casbin.jcasbin.config.Config;

import org.junit.Test;
import static org.junit.Assert.*;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class ConfigTest {

Expand All @@ -31,7 +31,7 @@ public void testGet() {

// redis::key test
String[] redisKeys = config.getStrings("redis::redis.key");
assertArrayEquals(new String[]{"push1", "push2"}, redisKeys);
assertEquals(new String[]{"push1", "push2"}, redisKeys);
assertEquals("127.0.0.1", config.getString("mysql::mysql.dev.host"));
assertEquals("10.0.0.1", config.getString("mysql::mysql.master.host"));
assertEquals("root", config.getString("mysql::mysql.master.user"));
Expand Down
58 changes: 29 additions & 29 deletions src/test/java/org/casbin/jcasbin/main/DefaultDetectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import org.casbin.jcasbin.detector.Detector;
import org.casbin.jcasbin.rbac.DefaultRoleManager;
import org.casbin.jcasbin.rbac.RoleManager;
import org.junit.Test;
import org.testng.annotations.Test;

import static org.junit.Assert.*;
import static org.testng.Assert.*;

/**
* Unit tests for DefaultDetector
Expand All @@ -40,7 +40,7 @@ public void testNoCycle() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNull("Expected no cycle to be detected", result);
assertNull(result, "Expected no cycle to be detected");
}

@Test
Expand All @@ -54,11 +54,11 @@ public void testSimpleCycle() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNotNull("Expected a cycle to be detected", result);
assertTrue("Result should contain 'Cycle detected'", result.contains("Cycle detected:"));
assertTrue("Result should contain role A", result.contains("A"));
assertTrue("Result should contain role B", result.contains("B"));
assertTrue("Result should contain role C", result.contains("C"));
assertNotNull(result, "Expected a cycle to be detected");
assertTrue(result.contains("Cycle detected:"), "Result should contain 'Cycle detected'");
assertTrue(result.contains("A"), "Result should contain role A");
assertTrue(result.contains("B"), "Result should contain role B");
assertTrue(result.contains("C"), "Result should contain role C");
}

@Test
Expand All @@ -70,9 +70,9 @@ public void testSelfLoop() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNotNull("Expected a cycle to be detected", result);
assertTrue("Result should contain 'Cycle detected'", result.contains("Cycle detected:"));
assertTrue("Result should contain role A", result.contains("A"));
assertNotNull(result, "Expected a cycle to be detected");
assertTrue(result.contains("Cycle detected:"), "Result should contain 'Cycle detected'");
assertTrue(result.contains("A"), "Result should contain role A");
}

@Test
Expand All @@ -85,8 +85,8 @@ public void testTwoNodeCycle() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNotNull("Expected a cycle to be detected", result);
assertTrue("Result should contain 'Cycle detected'", result.contains("Cycle detected:"));
assertNotNull(result, "Expected a cycle to be detected");
assertTrue(result.contains("Cycle detected:"), "Result should contain 'Cycle detected'");
}

@Test
Expand All @@ -103,7 +103,7 @@ public void testMultipleDisconnectedComponents() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNull("Expected no cycle to be detected", result);
assertNull(result, "Expected no cycle to be detected");
}

@Test
Expand All @@ -121,8 +121,8 @@ public void testCycleInOneComponent() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNotNull("Expected a cycle to be detected", result);
assertTrue("Result should contain 'Cycle detected'", result.contains("Cycle detected:"));
assertNotNull(result, "Expected a cycle to be detected");
assertTrue(result.contains("Cycle detected:"), "Result should contain 'Cycle detected'");
}

@Test
Expand All @@ -146,8 +146,8 @@ public void testComplexGraph() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNotNull("Expected a cycle to be detected", result);
assertTrue("Result should contain 'Cycle detected'", result.contains("Cycle detected:"));
assertNotNull(result, "Expected a cycle to be detected");
assertTrue(result.contains("Cycle detected:"), "Result should contain 'Cycle detected'");
}

@Test
Expand All @@ -158,7 +158,7 @@ public void testEmptyRoleManager() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNull("Expected no cycle in empty graph", result);
assertNull(result, "Expected no cycle in empty graph");
}

@Test
Expand All @@ -171,7 +171,7 @@ public void testSingleNode() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNull("Expected no cycle with single isolated node", result);
assertNull(result, "Expected no cycle with single isolated node");
}

@Test
Expand All @@ -192,8 +192,8 @@ public void testLargeGraph() {
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;

assertNull("Expected no cycle in large chain", result);
assertTrue("Detection should complete in reasonable time (< 5 seconds)", duration < 5000);
assertNull(result, "Expected no cycle in large chain");
assertTrue(duration < 5000, "Detection should complete in reasonable time (< 5 seconds)");
}

@Test
Expand All @@ -210,8 +210,8 @@ public void testLargeGraphWithCycle() {
Detector detector = new DefaultDetector();
String result = detector.check(rm);

assertNotNull("Expected a cycle to be detected in large graph", result);
assertTrue("Result should contain 'Cycle detected'", result.contains("Cycle detected:"));
assertNotNull(result, "Expected a cycle to be detected in large graph");
assertTrue(result.contains("Cycle detected:"), "Result should contain 'Cycle detected'");
}

@Test
Expand Down Expand Up @@ -249,7 +249,7 @@ public void printRoles() {}

Detector detector = new DefaultDetector();
String result = detector.check(rm);
assertNull("Expected no cycle with default getRoleGraph() implementation", result);
assertNull(result, "Expected no cycle with default getRoleGraph() implementation");
}

@Test
Expand All @@ -262,11 +262,11 @@ public void testCycleAfterClear() {

Detector detector = new DefaultDetector();
String result = detector.check(rm);
assertNotNull("Expected a cycle before clear", result);
assertNotNull(result, "Expected a cycle before clear");

rm.clear();
result = detector.check(rm);
assertNull("Expected no cycle after clear", result);
assertNull(result, "Expected no cycle after clear");
}

@Test
Expand All @@ -279,10 +279,10 @@ public void testCycleDetectionAfterDelete() {

Detector detector = new DefaultDetector();
String result = detector.check(rm);
assertNotNull("Expected a cycle before delete", result);
assertNotNull(result, "Expected a cycle before delete");

rm.deleteLink("C", "A");
result = detector.check(rm);
assertNull("Expected no cycle after breaking the cycle", result);
assertNull(result, "Expected no cycle after breaking the cycle");
}
}
15 changes: 8 additions & 7 deletions src/test/java/org/casbin/jcasbin/main/EnforcerUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.casbin.jcasbin.util.BuiltInFunctions;
import org.casbin.jcasbin.util.EnforceContext;
import org.casbin.jcasbin.util.Util;
import org.junit.Assert;
import org.junit.Test;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -34,8 +34,9 @@
import static java.util.Arrays.asList;
import static org.casbin.jcasbin.main.CoreEnforcer.newModel;
import static org.casbin.jcasbin.main.TestUtil.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class EnforcerUnitTest {
@Test
Expand Down Expand Up @@ -668,7 +669,7 @@ public void testBatchEnforce() {
List<Boolean> results = asList(true, true, false);
List<Boolean> myResults = e.batchEnforce(asList(asList("alice", "data1", "read"),
asList("bob", "data2", "write"), asList("jack", "data3", "read")));
Assert.assertArrayEquals(myResults.toArray(new Boolean[0]), results.toArray(new Boolean[0]));
assertEquals(myResults, results);
}

@Test
Expand All @@ -684,7 +685,7 @@ public void testDomainBatchEnforce() {
)
);

Assert.assertArrayEquals(myResults.toArray(new Boolean[0]), results.toArray(new Boolean[0]));
assertEquals(myResults, results);
}

@Test
Expand All @@ -698,7 +699,7 @@ public void testBatchEnforceWithMatcher() {
List<Boolean> myResults = e.batchEnforceWithMatcher(matcher, asList(asList("alice", "data1", "read"),
asList("bob", "data2", "write"), asList("root", "data2", "read"),
asList("root", "data3", "read"), asList("jack", "data3", "read")));
Assert.assertArrayEquals(myResults.toArray(new Boolean[0]), results.toArray(new Boolean[0]));
assertEquals(myResults, results);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.casbin.jcasbin.persist.Adapter;
import org.casbin.jcasbin.persist.file_adapter.FilteredAdapter;
import org.casbin.jcasbin.util.Util;
import org.junit.Test;
import org.testng.annotations.Test;

import static java.util.Arrays.asList;
import static org.casbin.jcasbin.main.TestUtil.testHasPolicy;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/casbin/jcasbin/main/FrontendUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.casbin.jcasbin.main;

import com.google.gson.Gson;
import org.junit.Test;
import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -24,7 +24,7 @@
import java.util.List;
import java.util.regex.Pattern;

import static org.junit.Assert.assertEquals;
import static org.testng.Assert.assertEquals;

public class FrontendUnitTest {

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/casbin/jcasbin/main/FunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.googlecode.aviator.runtime.type.AviatorBoolean;
import com.googlecode.aviator.runtime.type.AviatorObject;
import org.casbin.jcasbin.util.function.CustomFunction;
import org.junit.Test;
import org.testng.annotations.Test;

import java.util.Map;
import java.util.regex.Pattern;
Expand Down
Loading