Skip to content

Commit

Permalink
Add more unit tests for the directory reader api.
Browse files Browse the repository at this point in the history
Use assertj to improve assertions in tests.
  • Loading branch information
BogdanIrimie committed Nov 22, 2023
1 parent c29a2b0 commit 2a66e9d
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-testing</artifactId>
Expand Down
101 changes: 99 additions & 2 deletions src/test/java/DirectoryClientTest.java
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;
Expand All @@ -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})
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2a66e9d

Please sign in to comment.