Skip to content

Commit

Permalink
Throw UninitilizedClientException when trying to call a directory ope…
Browse files Browse the repository at this point in the history
…ration with an uninitialised client.

Bump artefact version to 0.21.0
Add new constructor to DirectoryClient.
  • Loading branch information
BogdanIrimie committed Dec 29, 2023
1 parent 19d2365 commit 97ca7b8
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 109 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.aserto</groupId>
<artifactId>aserto-java</artifactId>
<version>0.20.11</version>
<version>0.21.00</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Java SDK to interact with aserto services</description>
Expand Down
187 changes: 135 additions & 52 deletions src/main/java/com/aserto/directory/v3/DirectoryClient.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
import java.util.Iterator;

public interface DirectoryClientExporter {
Iterator<ExportResponse> exportData(Option options);
Iterator<ExportResponse> exportData(Option options, Timestamp startFrom);
Iterator<ExportResponse> exportData(Option options) throws UninitilizedClientException;
Iterator<ExportResponse> exportData(Option options, Timestamp startFrom) throws UninitilizedClientException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import java.util.stream.Stream;

public interface DirectoryClientImporter {
void importData(Stream<ImportElement> importStream) throws InterruptedException;
void importData(Stream<ImportElement> importStream) throws InterruptedException, UninitilizedClientException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.aserto.directory.model.v3.GetManifestResponse;

public interface DirectoryClientModel {
GetManifestResponse getManifest();
void setManifest(String manifest) throws InterruptedException;
DeleteManifestResponse deleteManifest();
GetManifestResponse getManifest() throws UninitilizedClientException;
void setManifest(String manifest) throws InterruptedException, UninitilizedClientException;
DeleteManifestResponse deleteManifest() throws UninitilizedClientException;
}
30 changes: 15 additions & 15 deletions src/main/java/com/aserto/directory/v3/DirectoryClientReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
import java.util.List;

public interface DirectoryClientReader {
GetObjectResponse getObject(String type, String id);
GetObjectResponse getObject(String type, String id, boolean withRelations);
GetObjectsResponse getObjects(String type);
GetObjectsResponse getObjects(String type, int pageSize, String pageToken);
GetObjectManyResponse getObjectManyRequest(List<ObjectIdentifier> objectIdentifiers);
GetObjectResponse getObject(String type, String id) throws UninitilizedClientException;
GetObjectResponse getObject(String type, String id, boolean withRelations) throws UninitilizedClientException;
GetObjectsResponse getObjects(String type) throws UninitilizedClientException;
GetObjectsResponse getObjects(String type, int pageSize, String pageToken) throws UninitilizedClientException;
GetObjectManyResponse getObjectManyRequest(List<ObjectIdentifier> objectIdentifiers) throws UninitilizedClientException;
GetRelationResponse getRelation(String objectType, String objectId, String relationName,
String subjectType, String subjectId);
String subjectType, String subjectId) throws UninitilizedClientException;
GetRelationResponse getRelation(String objectType, String objectId, String relationName, String subjectType,
String subjectId, String subjectRelation);
String subjectId, String subjectRelation) throws UninitilizedClientException;
GetRelationResponse getRelation(String objectType, String objectId, String relationName, String subjectType,
String subjectId, String subjectRelation, boolean withObjects);
GetRelationsResponse getRelations(GetRelationsRequest relationsRequest);
String subjectId, String subjectRelation, boolean withObjects) throws UninitilizedClientException;
GetRelationsResponse getRelations(GetRelationsRequest relationsRequest) throws UninitilizedClientException;

CheckPermissionResponse checkPermission(String objectType, String objectId, String subjectType,
String subjectId, String permissionName);
String subjectId, String permissionName) throws UninitilizedClientException;
CheckPermissionResponse checkPermission(String objectType, String objectId,
String subjectType, String subjectId, String permissionName, boolean trace);
CheckRelationResponse checkRelation(String objectType, String objectId, String relationName, String subjectType, String subjectId);
String subjectType, String subjectId, String permissionName, boolean trace) throws UninitilizedClientException;
CheckRelationResponse checkRelation(String objectType, String objectId, String relationName, String subjectType, String subjectId) throws UninitilizedClientException;
CheckRelationResponse checkRelation(String objectType, String objectId, String relationName,
String subjectType, String subjectId, boolean trace);
CheckResponse check(String objectType, String objectId, String relationName, String subjectType, String subjectId);
String subjectType, String subjectId, boolean trace) throws UninitilizedClientException;
CheckResponse check(String objectType, String objectId, String relationName, String subjectType, String subjectId) throws UninitilizedClientException;
CheckResponse check(String objectType, String objectId, String relationName,
String subjectType, String subjectId, boolean trace);
String subjectType, String subjectId, boolean trace) throws UninitilizedClientException;
GetGraphResponse getGraph(GetGraphRequest getGraphRequest);
}
18 changes: 9 additions & 9 deletions src/main/java/com/aserto/directory/v3/DirectoryClientWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
import com.google.protobuf.Struct;

public interface DirectoryClientWriter {
public SetObjectResponse setObject(String type, String id);
public SetObjectResponse setObject(String type, String id, String displayName, Struct properties, String hash);
public DeleteObjectResponse deleteObject(String type, String id);
public DeleteObjectResponse deleteObject(String type, String id, boolean withRelations);
public SetObjectResponse setObject(String type, String id) throws UninitilizedClientException;
public SetObjectResponse setObject(String type, String id, String displayName, Struct properties, String hash) throws UninitilizedClientException;
public DeleteObjectResponse deleteObject(String type, String id) throws UninitilizedClientException;
public DeleteObjectResponse deleteObject(String type, String id, boolean withRelations) throws UninitilizedClientException;
public SetRelationResponse setRelation(String objectType, String objectId, String relationName,
String subjectType, String subjectId);
String subjectType, String subjectId) throws UninitilizedClientException;
public SetRelationResponse setRelation(String objectType, String objectId, String relationName,
String subjectType, String subjectId, String subjectRelation);
String subjectType, String subjectId, String subjectRelation) throws UninitilizedClientException;
public SetRelationResponse setRelation(String objectType, String objectId, String relationName,
String subjectType, String subjectId, String subjectRelation, String hash);
String subjectType, String subjectId, String subjectRelation, String hash) throws UninitilizedClientException;
public DeleteRelationResponse deleteRelation(String objectType, String objectId, String relationName,
String subjectType, String subjectId);
String subjectType, String subjectId) throws UninitilizedClientException;
public DeleteRelationResponse deleteRelation(String objectType, String objectId, String relationName,
String subjectType, String subjectId, String subjectRelation);
String subjectType, String subjectId, String subjectRelation) throws UninitilizedClientException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.aserto.directory.v3;

public class UninitilizedClientException extends Exception {
public UninitilizedClientException(String message) {
super(message);
}
}
51 changes: 25 additions & 26 deletions src/test/java/DirectoryClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.aserto.directory.common.v3.ObjectIdentifier;
import com.aserto.directory.common.v3.Relation;
import com.aserto.directory.reader.v3.*;
import com.aserto.directory.v3.UninitilizedClientException;
import com.aserto.directory.writer.v3.DeleteRelationResponse;
import com.aserto.directory.writer.v3.SetObjectResponse;
import com.aserto.directory.writer.v3.SetRelationResponse;
Expand Down Expand Up @@ -84,14 +85,14 @@ static void setDirectoryClient() throws SSLException {
}

@BeforeEach
void beforeEach() throws InterruptedException {
void beforeEach() throws InterruptedException, UninitilizedClientException {
directoryClient.setManifest(originalManifest);
List<ImportElement> list = importCitadelDataList();
directoryClient.importData(list.stream());
}

@AfterEach
void afterEach() {
void afterEach() throws UninitilizedClientException {
directoryClient.deleteManifest();
}

Expand All @@ -104,8 +105,7 @@ static void closeChannel() {
@Test
void testDirectoryClientWithReaderCanRead() {
// Arrange
DirectoryClient directoryClient = new DirectoryClient();
directoryClient.withReaderChannel(channel);
DirectoryClient directoryClient = new DirectoryClient(channel, null, null, null, null);

// Act & Assert
assertDoesNotThrow(() -> {
Expand All @@ -116,18 +116,17 @@ void testDirectoryClientWithReaderCanRead() {
@Test
void testDirectoryClientWithReaderCannotWrite() {
// Arrange
DirectoryClient directoryClient = new DirectoryClient();
directoryClient.withReaderChannel(channel);
DirectoryClient directoryClient = new DirectoryClient(channel, null, null, null, null);


// Act & Assert
assertThrows(NullPointerException.class, () -> {
assertThrows(UninitilizedClientException.class, () -> {
directoryClient.setObject("test_type", "test_id");
});
}

@Test
void testGetUserWithNoRelations() {
void testGetUserWithNoRelations() throws UninitilizedClientException {
// Arrange
Object managerObject = Directory.buildObject("user", "[email protected]");

Expand All @@ -143,7 +142,7 @@ void testGetUserWithNoRelations() {
}

@Test
void testGetUserWithRelations() {
void testGetUserWithRelations() throws UninitilizedClientException {
// Arrange
Object managerObject = Directory.buildObject("user", "[email protected]");
Relation managerRelation = Directory.buildRelation("user", "[email protected]", "manager", "user", "[email protected]");
Expand All @@ -163,7 +162,7 @@ void testGetUserWithRelations() {
}

@Test
void testGetUsers() {
void testGetUsers() throws UninitilizedClientException {
// Arrange & Act
GetObjectsResponse getObjectsResponse = directoryClient.getObjects("user");

Expand All @@ -172,7 +171,7 @@ void testGetUsers() {
}

@Test
void testGetUsersWithLimit() {
void testGetUsersWithLimit() throws UninitilizedClientException {
// Arrange & Act
GetObjectsResponse getObjectsResponse = directoryClient.getObjects("user", 1, "");

Expand All @@ -184,7 +183,7 @@ void testGetUsersWithLimit() {
}

@Test
void testGetUserManyRequest() {
void testGetUserManyRequest() throws UninitilizedClientException {
// Arrange
List<ObjectIdentifier> objects = List.of(
Directory.buildObjectIdentifier("user", "[email protected]"),
Expand All @@ -200,7 +199,7 @@ void testGetUserManyRequest() {
}

@Test
void testGetRelation() {
void testGetRelation() throws UninitilizedClientException {
// Arrange
Relation expectedRelation = Directory.buildRelation("user", "[email protected]", "manager", "user", "[email protected]");

Expand All @@ -221,7 +220,7 @@ void testGetRelation() {
}

@Test
void testGetRelations() {
void testGetRelations() throws UninitilizedClientException {
// Arrange
Relation expectedManagerRelation = Directory.buildRelation("user", "[email protected]", "manager", "user", "[email protected]");
Relation expectedFriendRelation = Directory.buildRelation("user", "[email protected]", "friend", "user", "[email protected]");
Expand All @@ -246,7 +245,7 @@ void testGetRelations() {
}

@Test
void testCheckRelationManager() {
void testCheckRelationManager() throws UninitilizedClientException {
// Arrange & Act
CheckRelationResponse checkRelationResponse = directoryClient.checkRelation(
"user",
Expand All @@ -260,7 +259,7 @@ void testCheckRelationManager() {
}

@Test
void testCheckRelationFriend() {
void testCheckRelationFriend() throws UninitilizedClientException {
// Arrange & Act
CheckRelationResponse checkRelationResponse = directoryClient.checkRelation(
"user",
Expand All @@ -274,7 +273,7 @@ void testCheckRelationFriend() {
}

@Test
void testCheckManager() {
void testCheckManager() throws UninitilizedClientException {
// Arrange & Act
CheckResponse checkResponse = directoryClient.check(
"user",
Expand Down Expand Up @@ -317,7 +316,7 @@ void testGetGraph() {
}

@Test
void setObjectTest() {
void setObjectTest() throws UninitilizedClientException {
// Arrange
Object object = Directory.buildObject("test_type", "test_id");

Expand All @@ -332,7 +331,7 @@ void setObjectTest() {
}

@Test
void deleteObjectTest() {
void deleteObjectTest() throws UninitilizedClientException {
// Arrange
directoryClient.setObject("test_type", "test_id");
assertEquals(1, directoryClient.getObjects("test_type").getResultsList().size());
Expand All @@ -345,7 +344,7 @@ void deleteObjectTest() {
}

@Test
void setRelationTest() {
void setRelationTest() throws UninitilizedClientException {
// Arrange
Relation relation = Directory.buildRelation("user", "[email protected]", "friend", "user", "[email protected]");

Expand All @@ -365,7 +364,7 @@ void setRelationTest() {
}

@Test
void deleteRelationTest() {
void deleteRelationTest() throws UninitilizedClientException {
// Arrange & Act
DeleteRelationResponse deleteRelationResponse = directoryClient.deleteRelation(
"user",
Expand All @@ -388,7 +387,7 @@ void deleteRelationTest() {
}

@Test
void testGetManifest() {
void testGetManifest() throws UninitilizedClientException {
// Arrange & Act
GetManifestResponse getManifestResponse = directoryClient.getManifest();

Expand All @@ -397,7 +396,7 @@ void testGetManifest() {
}

@Test
void testSetManifest() throws InterruptedException {
void testSetManifest() throws InterruptedException, UninitilizedClientException {
// Arrange & Act
directoryClient.setManifest(modifiedManifest);
GetManifestResponse getManifestResponse = directoryClient.getManifest();
Expand All @@ -407,7 +406,7 @@ void testSetManifest() throws InterruptedException {
}

@Test
void testDeleteManifest() {
void testDeleteManifest() throws UninitilizedClientException {
// Arrange & Act
directoryClient.deleteManifest();
GetManifestResponse getManifestResponse = directoryClient.getManifest();
Expand All @@ -417,7 +416,7 @@ void testDeleteManifest() {
}

@Test
void importDataTest() throws InterruptedException {
void importDataTest() throws InterruptedException, UninitilizedClientException {
// Arrange
List<ImportElement> list = importCitadelDataList();
List<Object> users = list.stream()
Expand All @@ -437,7 +436,7 @@ void importDataTest() throws InterruptedException {
}

@Test
void exportDataTest() {
void exportDataTest() throws UninitilizedClientException {
// Arrange & Act
Iterator<ExportResponse> exportedData = directoryClient.exportData(Option.OPTION_DATA);

Expand Down

0 comments on commit 97ca7b8

Please sign in to comment.