use of de.fraunhofer.iais.eis.PermissionBuilder in project DataspaceConnector by International-Data-Spaces-Association.
the class RuleUtilsTest method getTimeInterval_inputInvalidNoEndDate_returnCorrectOutput.
@Test
public void getTimeInterval_inputInvalidNoEndDate_returnCorrectOutput() throws ParseException {
/* ARRANGE */
final var startDate = "2021-01-01T00:00:00Z";
final var constraint = new ConstraintBuilder()._leftOperand_(LeftOperand.POLICY_EVALUATION_TIME)._operator_(BinaryOperator.AFTER)._rightOperand_(new RdfResource(startDate, URI.create("xsd:dateTimeStamp"))).build();
final var permission = new PermissionBuilder()._action_(Util.asList(Action.USE))._constraint_(Util.asList(constraint)).build();
/* ACT */
final var result = RuleUtils.getTimeInterval(permission);
/* ASSERT */
assertEquals(ZonedDateTime.parse(startDate), result.getStart());
assertNull(result.getEnd());
}
use of de.fraunhofer.iais.eis.PermissionBuilder in project DataspaceConnector by International-Data-Spaces-Association.
the class RuleUtilsTest method getDate_inputInvalidWrongDateFormat_throwDateTimeParseException.
@Test
public void getDate_inputInvalidWrongDateFormat_throwDateTimeParseException() {
/* ARRANGE */
final var date = "2021-01-01T00:00:00.000";
final var constraint = new ConstraintBuilder()._leftOperand_(LeftOperand.POLICY_EVALUATION_TIME)._operator_(BinaryOperator.AFTER)._rightOperand_(new RdfResource(date, URI.create("xsd:dateTimeStamp"))).build();
final var permission = new PermissionBuilder()._action_(Util.asList(Action.USE))._constraint_(Util.asList(constraint)).build();
/* ACT & ASSERT */
assertThrows(DateTimeParseException.class, () -> RuleUtils.getDate(permission));
}
use of de.fraunhofer.iais.eis.PermissionBuilder in project DataspaceConnector by International-Data-Spaces-Association.
the class RuleUtilsTest method getTimeInterval_inputInvalidNoStartDate_returnCorrectOutput.
@Test
public void getTimeInterval_inputInvalidNoStartDate_returnCorrectOutput() throws ParseException {
/* ARRANGE */
final var endDate = "2022-01-01T00:00:00Z";
final var constraint = new ConstraintBuilder()._leftOperand_(LeftOperand.POLICY_EVALUATION_TIME)._operator_(BinaryOperator.BEFORE)._rightOperand_(new RdfResource(endDate, URI.create("xsd:dateTimeStamp"))).build();
final var permission = new PermissionBuilder()._action_(Util.asList(Action.USE))._constraint_(Util.asList(constraint)).build();
/* ACT */
final var result = RuleUtils.getTimeInterval(permission);
/* ASSERT */
assertNull(result.getStart());
assertEquals(ZonedDateTime.parse(endDate), result.getEnd());
}
use of de.fraunhofer.iais.eis.PermissionBuilder in project DataspaceConnector by International-Data-Spaces-Association.
the class RuleUtilsTest method getMaxAccess_inputCorrectOperatorEquals_returnAccessInteger.
@Test
public void getMaxAccess_inputCorrectOperatorEquals_returnAccessInteger() {
/* ARRANGE */
final var maxAccess = 2;
final var constraint = new ConstraintBuilder()._leftOperand_(LeftOperand.COUNT)._operator_(BinaryOperator.EQ)._rightOperand_(new RdfResource(String.valueOf(maxAccess), URI.create("xsd:decimal"))).build();
final var permission = new PermissionBuilder()._action_(Util.asList(Action.USE))._constraint_(Util.asList(constraint)).build();
/* ACT */
final var result = RuleUtils.getMaxAccess(permission);
/* ASSERT */
assertEquals(maxAccess, result);
}
use of de.fraunhofer.iais.eis.PermissionBuilder in project DataspaceConnector by International-Data-Spaces-Association.
the class RuleUtilsTest method getMaxAccess_inputInvalidAccessBiggerThanMaxInteger_returnSomething.
@Test
public void getMaxAccess_inputInvalidAccessBiggerThanMaxInteger_returnSomething() {
/* ARRANGE */
final var maxAccess = Integer.MAX_VALUE + 1;
final var constraint = new ConstraintBuilder()._leftOperand_(LeftOperand.COUNT)._operator_(BinaryOperator.EQ)._rightOperand_(new RdfResource(String.valueOf(maxAccess), URI.create("xsd:decimal"))).build();
final var permission = new PermissionBuilder()._action_(Util.asList(Action.USE))._constraint_(Util.asList(constraint)).build();
/* ACT */
final var result = RuleUtils.getMaxAccess(permission);
/* ASSERT */
assertTrue(result >= 0);
}
Aggregations