-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0ffeed
commit a690802
Showing
24 changed files
with
496 additions
and
80 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
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
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
74 changes: 74 additions & 0 deletions
74
api/src/test/java/com/oviva/spicegen/api/CheckPermissionTest.java
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.oviva.spicegen.api; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class CheckPermissionTest { | ||
|
||
@Test | ||
public void test_build_success() { | ||
|
||
var namespace = "tenant"; | ||
var id = "9392"; | ||
var consistencyToken = "t0ken"; | ||
var permission = "write"; | ||
|
||
var objectRef = ObjectRef.of(namespace, id); | ||
var subjectRef = SubjectRef.ofObject(ObjectRef.of(namespace, id)); | ||
|
||
var checkPermission = | ||
CheckPermission.newBuilder() | ||
.consistency(Consistency.atLeastAsFreshAs(consistencyToken)) | ||
.permission(permission) | ||
.resource(objectRef) | ||
.subject(subjectRef) | ||
.build(); | ||
|
||
assertEquals(checkPermission.consistency().consistencyToken(), consistencyToken); | ||
assertEquals(checkPermission.permission(), permission); | ||
assertEquals(checkPermission.resource(), objectRef); | ||
assertEquals(checkPermission.subject(), subjectRef); | ||
} | ||
|
||
@Test | ||
void of_hashCode() { | ||
var h1 = createCheck("17").hashCode(); | ||
var h2 = createCheck("17").hashCode(); | ||
|
||
assertEquals(h1, h2); | ||
} | ||
|
||
private CheckPermission createCheck(String subjectId) { | ||
|
||
return CheckPermission.newBuilder() | ||
.permission("test") | ||
.resource(ObjectRef.of("tenant", "1")) | ||
.subject(SubjectRef.ofObject(ObjectRef.of("user", subjectId))) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void of_equals_same() { | ||
var c1 = createCheck("1"); | ||
|
||
assertEquals(c1, c1); | ||
} | ||
|
||
@Test | ||
void of_equals() { | ||
var c1 = createCheck("1"); | ||
var c2 = createCheck("1"); | ||
|
||
assertEquals(c1, c2); | ||
} | ||
|
||
@Test | ||
void of_equals_notEqual() { | ||
var c1 = createCheck("3"); | ||
var c2 = createCheck("4"); | ||
|
||
assertNotEquals(c1, c2); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
api/src/test/java/com/oviva/spicegen/api/SubjectRefTest.java
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.oviva.spicegen.api; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.UUID; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class SubjectRefTest { | ||
|
||
@Test | ||
void ofUser() { | ||
var uuid = UUID.fromString("20162b05-fbc5-4567-853f-7ad90fc29d25"); | ||
var user = SubjectRef.ofObject(ObjectRef.of("user", uuid.toString())); | ||
|
||
assertEquals(user.id(), uuid.toString()); | ||
assertEquals(user.kind(), "user"); | ||
} | ||
|
||
@Test | ||
void ofUuid() { | ||
var namespace = "tenant"; | ||
var uuid = UUID.fromString("c0fe2b05-fbc5-4567-853f-7ad90fc29d25"); | ||
var user = SubjectRef.ofObject(ObjectRef.of(namespace, uuid.toString())); | ||
|
||
assertEquals(user.id(), uuid.toString()); | ||
assertEquals(user.kind(), namespace); | ||
} | ||
|
||
@Test | ||
void ofUuid_nullId() { | ||
assertThrows( | ||
IllegalArgumentException.class, () -> SubjectRef.ofObject(ObjectRef.of("anotherns", null))); | ||
} | ||
|
||
@Test | ||
void of() { | ||
var namespace = "tenant"; | ||
var id = "9392"; | ||
var user = SubjectRef.ofObject(ObjectRef.of(namespace, id)); | ||
|
||
assertEquals(user.id(), id); | ||
assertEquals(user.kind(), namespace); | ||
} | ||
|
||
@Test | ||
void of_nullId() { | ||
assertThrows( | ||
IllegalArgumentException.class, () -> SubjectRef.ofObject(ObjectRef.of("somens", null))); | ||
} | ||
|
||
@Test | ||
void of_nullNamespace() { | ||
assertThrows( | ||
IllegalArgumentException.class, () -> SubjectRef.ofObject(ObjectRef.of(null, "32"))); | ||
} | ||
|
||
@Test | ||
void equals() { | ||
var a = SubjectRef.ofObject(ObjectRef.of("a", "1")); | ||
var b = SubjectRef.ofObject(ObjectRef.of("a", "1")); | ||
|
||
assertEquals(a, b); | ||
} | ||
} |
Oops, something went wrong.