Search in sources :

Example 1 with PermissionBuilder

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());
}
Also used : ConstraintBuilder(de.fraunhofer.iais.eis.ConstraintBuilder) RdfResource(de.fraunhofer.iais.eis.util.RdfResource) PermissionBuilder(de.fraunhofer.iais.eis.PermissionBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with PermissionBuilder

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));
}
Also used : ConstraintBuilder(de.fraunhofer.iais.eis.ConstraintBuilder) RdfResource(de.fraunhofer.iais.eis.util.RdfResource) PermissionBuilder(de.fraunhofer.iais.eis.PermissionBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with PermissionBuilder

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());
}
Also used : ConstraintBuilder(de.fraunhofer.iais.eis.ConstraintBuilder) RdfResource(de.fraunhofer.iais.eis.util.RdfResource) PermissionBuilder(de.fraunhofer.iais.eis.PermissionBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with PermissionBuilder

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);
}
Also used : ConstraintBuilder(de.fraunhofer.iais.eis.ConstraintBuilder) RdfResource(de.fraunhofer.iais.eis.util.RdfResource) PermissionBuilder(de.fraunhofer.iais.eis.PermissionBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with PermissionBuilder

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);
}
Also used : ConstraintBuilder(de.fraunhofer.iais.eis.ConstraintBuilder) RdfResource(de.fraunhofer.iais.eis.util.RdfResource) PermissionBuilder(de.fraunhofer.iais.eis.PermissionBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

PermissionBuilder (de.fraunhofer.iais.eis.PermissionBuilder)46 Test (org.junit.jupiter.api.Test)42 ConstraintBuilder (de.fraunhofer.iais.eis.ConstraintBuilder)35 RdfResource (de.fraunhofer.iais.eis.util.RdfResource)35 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 ContractRequestBuilder (de.fraunhofer.iais.eis.ContractRequestBuilder)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 ContractRequestMessageImpl (de.fraunhofer.iais.eis.ContractRequestMessageImpl)7 Serializer (de.fraunhofer.iais.eis.ids.jsonld.Serializer)7 MessagePayloadInputstream (ids.messaging.handler.message.MessagePayloadInputstream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 SneakyThrows (lombok.SneakyThrows)7 ErrorResponse (ids.messaging.response.ErrorResponse)6 TypedLiteral (de.fraunhofer.iais.eis.util.TypedLiteral)4 ContractDesc (io.dataspaceconnector.model.contract.ContractDesc)4 ContractFactory (io.dataspaceconnector.model.contract.ContractFactory)4 ContractAgreementBuilder (de.fraunhofer.iais.eis.ContractAgreementBuilder)2 ContractRuleDesc (io.dataspaceconnector.model.rule.ContractRuleDesc)2 ContractRuleFactory (io.dataspaceconnector.model.rule.ContractRuleFactory)2 URI (java.net.URI)2