-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more unit tests for the directory reader api.
Use assertj to improve assertions in tests.
- Loading branch information
1 parent
c29a2b0
commit ddea6fb
Showing
2 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import com.aserto.ChannelBuilder; | ||
import com.aserto.directory.common.v3.ObjectDependency; | ||
import com.aserto.directory.v3.DirectoryClient; | ||
import com.aserto.directory.common.v3.Object; | ||
import com.aserto.directory.common.v3.ObjectIdentifier; | ||
|
@@ -13,12 +14,13 @@ | |
|
||
import javax.net.ssl.SSLException; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@Tag("IntegrationTest") | ||
@ExtendWith({IntegrationTestsExtenion.class}) | ||
|
@@ -140,4 +142,99 @@ void testGetRelations() { | |
// Assert | ||
assertEquals(10, getRelationsResponse.getResultsList().size()); | ||
} | ||
|
||
@Test | ||
@Tag("IntegrationTest") | ||
void testCheckRelationAdmin() { | ||
// Arrange & Act | ||
CheckRelationResponse checkRelationResponse = directoryClient.checkRelation( | ||
"group", | ||
"admin", | ||
"member", | ||
"user", | ||
"[email protected]"); | ||
|
||
// Assert | ||
assertTrue(checkRelationResponse.getCheck()); | ||
} | ||
|
||
@Test | ||
@Tag("IntegrationTest") | ||
void testCheckRelationViewer() { | ||
// Arrange & Act | ||
CheckRelationResponse checkRelationResponse = directoryClient.checkRelation( | ||
"group", | ||
"viewer", | ||
"member", | ||
"user", | ||
"[email protected]"); | ||
|
||
// Assert | ||
assertFalse(checkRelationResponse.getCheck()); | ||
} | ||
|
||
@Test | ||
@Tag("IntegrationTest") | ||
void testCheckAdmin() { | ||
// Arrange & Act | ||
CheckResponse checkResponse = directoryClient.check( | ||
"group", | ||
"admin", | ||
"member", | ||
"user", | ||
"[email protected]"); | ||
|
||
// Assert | ||
assertTrue(checkResponse.getCheck()); | ||
} | ||
|
||
@Test | ||
@Tag("IntegrationTest") | ||
void testGetGraph() { | ||
// Arrange | ||
GetGraphRequest getGraphRequest = GetGraphRequest.newBuilder() | ||
.setAnchorType("user") | ||
.setAnchorId("[email protected]") | ||
.setObjectType("user") | ||
.setObjectId("[email protected]") | ||
.build(); | ||
|
||
List<ObjectDependency> objectDependencyList = Arrays.asList( | ||
ObjectDependency.newBuilder() | ||
.setObjectType("user") | ||
.setObjectId("[email protected]") | ||
.setRelation("manager") | ||
.setSubjectType("user") | ||
.setSubjectId("[email protected]") | ||
.build(), | ||
ObjectDependency.newBuilder() | ||
.setObjectType("user") | ||
.setObjectId("[email protected]") | ||
.setRelation("manager") | ||
.setSubjectType("user") | ||
.setSubjectId("[email protected]") | ||
.build(), | ||
ObjectDependency.newBuilder() | ||
.setObjectType("user") | ||
.setObjectId("[email protected]") | ||
.setRelation("manager") | ||
.setSubjectType("user") | ||
.setSubjectId("[email protected]") | ||
.build(), | ||
ObjectDependency.newBuilder() | ||
.setObjectType("user") | ||
.setObjectId("[email protected]") | ||
.setRelation("manager") | ||
.setSubjectType("user") | ||
.setSubjectId("[email protected]") | ||
.build()); | ||
|
||
// Act | ||
GetGraphResponse getGraphResponse = directoryClient.getGraph(getGraphRequest); | ||
|
||
// Assert | ||
assertThat(getGraphResponse.getResultsList()) | ||
.usingRecursiveFieldByFieldElementComparatorOnFields("objectId_", "objectType_", "relation_", "subjectId_", "subjectType_") | ||
.containsExactlyInAnyOrderElementsOf(objectDependencyList); | ||
} | ||
} |