Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 5e05d6a

Browse files
committed
#428 Better error message when roles have circular dependencies
1 parent 26bc350 commit 5e05d6a

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/main/java/com/marklogic/mgmt/api/security/RoleObjectNodesSorter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ else if (index > -1) {
7878
}
7979
}
8080

81-
String[] sortedRoleNames = sorter.sort();
81+
String[] sortedRoleNames;
82+
try {
83+
sortedRoleNames = sorter.sort();
84+
} catch (IllegalStateException ex) {
85+
throw new IllegalArgumentException("Unable to deploy roles due to circular dependencies " +
86+
"between two or more roles; please remove these circular dependencies in order to deploy" +
87+
" your roles");
88+
}
89+
8290
roles = new ArrayList<>();
8391
for (String name : sortedRoleNames) {
8492
roles.add(map.get(name));

src/test/java/com/marklogic/appdeployer/command/security/DeployRolesWithDependenciesTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import java.io.File;
88

9-
import static org.junit.jupiter.api.Assertions.assertTrue;
9+
import static org.junit.jupiter.api.Assertions.*;
1010

1111
/**
1212
* Each of these tests verifies that the roles in the given config dir can be deployed successfully based on their
@@ -73,6 +73,22 @@ public void anotherSortingTest() {
7373
}
7474
}
7575

76+
@Test
77+
void circularDependencies() {
78+
appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/sample-app/roles-with-circular-dependencies"));
79+
initializeAppDeployer(new DeployRolesCommand());
80+
try {
81+
deploySampleApp();
82+
fail("Expected an error due to a circular dependency between the two roles");
83+
} catch (IllegalArgumentException ex) {
84+
assertEquals("Unable to deploy roles due to circular dependencies between two or more roles; " +
85+
"please remove these circular dependencies in order to deploy your roles",
86+
ex.getMessage());
87+
} finally {
88+
undeploySampleApp();
89+
}
90+
}
91+
7692
@Test
7793
public void test() {
7894
appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/sample-app/roles-with-dependencies"));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"role-name": "sample-app-role0",
3+
"role": [
4+
"sample-app-role1"
5+
]
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"role-name": "sample-app-role1",
3+
"role": [
4+
"sample-app-role0"
5+
]
6+
}

0 commit comments

Comments
 (0)