-
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
bdb217e
commit 78b940b
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...ding/src/test/java/com/oviva/spicegen/spicedbbinding/internal/PreconditionMapperTest.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,93 @@ | ||
package com.oviva.spicegen.spicedbbinding.internal; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.oviva.spicegen.api.Precondition; | ||
import com.oviva.spicegen.api.RelationshipFilter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class PreconditionMapperTest { | ||
|
||
@Test | ||
void map_objectExists() { | ||
|
||
var sut = new PreconditionMapper(); | ||
|
||
var relation = "user"; | ||
var userId = "17"; | ||
|
||
var precondition = | ||
Precondition.mustMatch( | ||
RelationshipFilter.newBuilder().resourceKind(relation).resourceId(userId).build()); | ||
|
||
// when | ||
var mapped = sut.map(precondition); | ||
|
||
// then | ||
assertEquals(relation, mapped.getFilter().getResourceType()); | ||
assertEquals(userId, mapped.getFilter().getOptionalResourceId()); | ||
assertEquals( | ||
com.authzed.api.v1.Precondition.Operation.OPERATION_MUST_MATCH, mapped.getOperation()); | ||
} | ||
|
||
@Test | ||
void map_objectNotExists() { | ||
|
||
var sut = new PreconditionMapper(); | ||
|
||
var relation = "user"; | ||
var userId = "77"; | ||
|
||
var precondition = | ||
Precondition.mustNotMatch( | ||
RelationshipFilter.newBuilder().resourceKind(relation).resourceId(userId).build()); | ||
|
||
// when | ||
var mapped = sut.map(precondition); | ||
|
||
// then | ||
assertEquals(relation, mapped.getFilter().getResourceType()); | ||
assertEquals(userId, mapped.getFilter().getOptionalResourceId()); | ||
assertEquals( | ||
com.authzed.api.v1.Precondition.Operation.OPERATION_MUST_NOT_MATCH, mapped.getOperation()); | ||
} | ||
|
||
@Test | ||
void map_subject() { | ||
|
||
var sut = new PreconditionMapper(); | ||
|
||
var relation = "file"; | ||
var fileId = "17"; | ||
|
||
var subject = "user"; | ||
var userId = "42"; | ||
|
||
var precondition = | ||
Precondition.mustMatch( | ||
RelationshipFilter.newBuilder() | ||
.resourceKind(relation) | ||
.resourceId(fileId) | ||
.subjectFilter( | ||
RelationshipFilter.SubjectFilter.newBuilder() | ||
.subjectKind(subject) | ||
.subjectId(userId) | ||
.build()) | ||
.build()); | ||
|
||
// when | ||
var mapped = sut.map(precondition); | ||
|
||
// then | ||
assertEquals( | ||
com.authzed.api.v1.Precondition.Operation.OPERATION_MUST_MATCH, mapped.getOperation()); | ||
|
||
var filter = mapped.getFilter(); | ||
assertEquals(relation, filter.getResourceType()); | ||
assertEquals(fileId, filter.getOptionalResourceId()); | ||
|
||
var subFilter = filter.getOptionalSubjectFilter(); | ||
assertEquals(subject, subFilter.getSubjectType()); | ||
assertEquals(userId, subFilter.getOptionalSubjectId()); | ||
} | ||
} |