Search in sources :

Example 1 with ContractRequestBuilder

use of de.fraunhofer.iais.eis.ContractRequestBuilder in project IDS-Messaging-Services by International-Data-Spaces-Association.

the class MultipartResponseConverterTest method testConvertResponse.

@Test
void testConvertResponse() throws IOException, MultipartParseException, UnknownResponseException, DeserializeException {
    // setup converter
    final var serializer = new Serializer();
    final var converter = new MultipartResponseConverter();
    // check messages with parsed payloads
    // ContractResponseMessage
    final var contractResponseMessage = buildContractResponseMessage();
    final var offer = new ContractOfferBuilder().build();
    var multipartMap = buildMultipart(contractResponseMessage, offer);
    var convertedMAP = converter.convertResponse(multipartMap);
    assertEquals(ContractResponseMAP.class, convertedMAP.getClass());
    assertEquals(contractResponseMessage, convertedMAP.getMessage());
    assertEquals(offer, convertedMAP.getPayload().get());
    // ContractOfferMessage
    final var contractOfferMessage = buildContractOfferMessage();
    multipartMap = buildMultipart(contractOfferMessage, offer);
    convertedMAP = converter.convertResponse(multipartMap);
    assertEquals(ContractOfferMAP.class, convertedMAP.getClass());
    assertEquals(contractOfferMessage, convertedMAP.getMessage());
    assertEquals(offer, convertedMAP.getPayload().get());
    // ContractAgreementMessage
    final var contractAgreementMessage = buildContractAgreementMessage();
    final var agreement = new ContractAgreementBuilder()._contractStart_(IdsMessageUtils.getGregorianNow()).build();
    multipartMap = buildMultipart(contractAgreementMessage, agreement);
    convertedMAP = converter.convertResponse(multipartMap);
    assertEquals(contractAgreementMessage, convertedMAP.getMessage());
    assertEquals(agreement, convertedMAP.getPayload().get());
    // ContractRequestMessage
    final var contractRequestMessage = buildContractRequestMessage();
    final var request = new ContractRequestBuilder().build();
    multipartMap = buildMultipart(contractRequestMessage, request);
    convertedMAP = converter.convertResponse(multipartMap);
    assertEquals(contractRequestMessage, convertedMAP.getMessage());
    assertEquals(request, convertedMAP.getPayload().get());
    // ParticipantUpdateMessage
    final var participantUpdateMessage = buildParticipantUpdateMessage();
    final var participant = new ParticipantBuilder()._legalForm_("form").build();
    multipartMap = buildMultipart(participantUpdateMessage, participant);
    convertedMAP = converter.convertResponse(multipartMap);
    assertEquals(participantUpdateMessage, convertedMAP.getMessage());
    assertEquals(participant, convertedMAP.getPayload().get());
    // ResourceUpdateMessage
    final var resourceUpdateMessage = buildResourceUpdateMessage();
    final var resource = new ResourceBuilder().build();
    multipartMap = buildMultipart(resourceUpdateMessage, resource);
    convertedMAP = converter.convertResponse(multipartMap);
    assertEquals(resourceUpdateMessage, convertedMAP.getMessage());
    assertEquals(resource, convertedMAP.getPayload().get());
    // ConnectorUpdateMessage
    final var connUpdateMessage = buildConnUpdateMessage();
    final var component = new BaseConnectorBuilder()._securityProfile_(SecurityProfile.BASE_SECURITY_PROFILE)._inboundModelVersion_(List.of("1.0.0"))._outboundModelVersion_("1.0.0")._hasDefaultEndpoint_(new ConnectorEndpointBuilder()._accessURL_(URI.create("http://example.com")).build())._maintainer_(URI.create("http://example.com"))._curator_(URI.create("http://example.com")).build();
    multipartMap = buildMultipart(connUpdateMessage, component);
    convertedMAP = converter.convertResponse(multipartMap);
    assertEquals(connUpdateMessage, convertedMAP.getMessage());
    assertEquals(component, convertedMAP.getPayload().get());
    // messages where payload does not matter for MAP
    final var messages = List.of(buildDescriptionRequestMessage(), buildDescriptionResponseMessage(), buildContractRejectionMessage(), buildRejectionMessage(), buildArtifactRequestMessage(), buildArtifactResponseMessage(), buildConnUnavailableMessage(), buildQueryMessage(), buildResourceUnavailableMessage(), buildParticipantUnavailableMessage(), buildParticipantRequestMessage());
    for (final var msg : messages) {
        final var multiMap = buildMultipart(msg, "payload");
        final var convMap = converter.convertResponse(multiMap);
        assertEquals(msg, convMap.getMessage());
    }
    // check unsupported message (should throw UnknownResponseException)
    final var noteMsg = buildNotificationMessage();
    assertThrows(UnknownResponseException.class, () -> converter.convertResponse(Map.of("header", serializer.serialize(noteMsg), "payload", "a")));
}
Also used : ResourceBuilder(de.fraunhofer.iais.eis.ResourceBuilder) BaseConnectorBuilder(de.fraunhofer.iais.eis.BaseConnectorBuilder) ConnectorEndpointBuilder(de.fraunhofer.iais.eis.ConnectorEndpointBuilder) ContractOfferBuilder(de.fraunhofer.iais.eis.ContractOfferBuilder) ContractAgreementBuilder(de.fraunhofer.iais.eis.ContractAgreementBuilder) ParticipantBuilder(de.fraunhofer.iais.eis.ParticipantBuilder) Serializer(de.fraunhofer.iais.eis.ids.jsonld.Serializer) ContractRequestBuilder(de.fraunhofer.iais.eis.ContractRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with ContractRequestBuilder

use of de.fraunhofer.iais.eis.ContractRequestBuilder in project DataspaceConnector by International-Data-Spaces-Association.

the class RuleUtilsTest method getRulesForTargetId_matchingTargetIdForMultipleRules_returnRuleList.

@Test
public void getRulesForTargetId_matchingTargetIdForMultipleRules_returnRuleList() {
    /* ARRANGE */
    final var target = URI.create("https://target");
    final var permission = getPermissionWithTarget(target);
    final var prohibition = getProhibitionWithTarget(null);
    final var prohibition2 = getProhibitionWithTarget(target);
    final var obligation = getDutyWithTarget(target);
    final var contract = new ContractRequestBuilder()._contractStart_(getGregorianNow())._permission_(Util.asList(permission))._prohibition_(Util.asList(prohibition, prohibition2))._obligation_(Util.asList(obligation)).build();
    /* ACT */
    final var result = ContractUtils.getRulesForTargetId(contract, target);
    /* ASSERT */
    assertEquals(3, result.size());
    assertTrue(result.contains(permission));
    assertTrue(result.contains(prohibition2));
    assertTrue(result.contains(obligation));
}
Also used : ContractRequestBuilder(de.fraunhofer.iais.eis.ContractRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with ContractRequestBuilder

use of de.fraunhofer.iais.eis.ContractRequestBuilder in project DataspaceConnector by International-Data-Spaces-Association.

the class RuleUtilsTest method getRulesForTargetId_noMatchingTargetId_returnRuleList.

@Test
public void getRulesForTargetId_noMatchingTargetId_returnRuleList() {
    /* ARRANGE */
    final var target = URI.create("https://target");
    final var permission = getPermissionWithTarget(null);
    final var prohibition = getProhibitionWithTarget(null);
    final var obligation = getDutyWithTarget(null);
    final var contract = new ContractRequestBuilder()._contractStart_(getGregorianNow())._permission_(Util.asList(permission))._prohibition_(Util.asList(prohibition))._obligation_(Util.asList(obligation)).build();
    /* ACT */
    final var result = ContractUtils.getRulesForTargetId(contract, target);
    /* ASSERT */
    assertEquals(0, result.size());
}
Also used : ContractRequestBuilder(de.fraunhofer.iais.eis.ContractRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with ContractRequestBuilder

use of de.fraunhofer.iais.eis.ContractRequestBuilder in project DataspaceConnector by International-Data-Spaces-Association.

the class RuleUtilsTest method extractRulesFromContract_contractWithThreeRules_returnRuleList.

@Test
public void extractRulesFromContract_contractWithThreeRules_returnRuleList() {
    /* ARRANGE */
    final var permission = (Permission) getRuleThree();
    final var prohibition = (Prohibition) getRuleTwo();
    final var obligation = (Duty) getRuleOne();
    final var contract = new ContractRequestBuilder()._contractStart_(getGregorianNow())._permission_(Util.asList(permission))._prohibition_(Util.asList(prohibition))._obligation_(Util.asList(obligation)).build();
    /* ACT */
    final var result = ContractUtils.extractRulesFromContract(contract);
    /* ASSERT */
    assertEquals(3, result.size());
    assertTrue(result.contains(permission));
    assertTrue(result.contains(prohibition));
    assertTrue(result.contains(obligation));
}
Also used : Prohibition(de.fraunhofer.iais.eis.Prohibition) Duty(de.fraunhofer.iais.eis.Duty) Permission(de.fraunhofer.iais.eis.Permission) ContractRequestBuilder(de.fraunhofer.iais.eis.ContractRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with ContractRequestBuilder

use of de.fraunhofer.iais.eis.ContractRequestBuilder in project DataspaceConnector by International-Data-Spaces-Association.

the class RdfConverterTest method getContractRequest.

private ContractRequest getContractRequest() {
    final var permissions = new ArrayList<Permission>();
    final var prohibitions = new ArrayList<Prohibition>();
    final var obligations = new ArrayList<Duty>();
    permissions.add((Permission) getRule());
    return new ContractRequestBuilder(URI.create("https://w3id" + ".org/idsa/autogen/contractRequest/591467af-9633-4a4e-8bcf-47ba4e6679ea"))._consumer_(URI.create("https://w3id.org/idsa/autogen/baseConnector/591467af-9633" + "-4a4e-8bcf-47ba4e6679ea"))._contractDate_(getDateAsXMLGregorianCalendar())._contractStart_(getDateAsXMLGregorianCalendar())._obligation_(obligations)._permission_(permissions)._prohibition_(prohibitions).build();
}
Also used : ArrayList(java.util.ArrayList) ContractRequestBuilder(de.fraunhofer.iais.eis.ContractRequestBuilder)

Aggregations

ContractRequestBuilder (de.fraunhofer.iais.eis.ContractRequestBuilder)18 Test (org.junit.jupiter.api.Test)16 PermissionBuilder (de.fraunhofer.iais.eis.PermissionBuilder)9 Serializer (de.fraunhofer.iais.eis.ids.jsonld.Serializer)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ContractRequestMessageImpl (de.fraunhofer.iais.eis.ContractRequestMessageImpl)8 MessagePayloadInputstream (ids.messaging.handler.message.MessagePayloadInputstream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 SneakyThrows (lombok.SneakyThrows)8 ErrorResponse (ids.messaging.response.ErrorResponse)7 ContractDesc (io.dataspaceconnector.model.contract.ContractDesc)4 ContractFactory (io.dataspaceconnector.model.contract.ContractFactory)4 ContractAgreementBuilder (de.fraunhofer.iais.eis.ContractAgreementBuilder)3 Duty (de.fraunhofer.iais.eis.Duty)3 Permission (de.fraunhofer.iais.eis.Permission)3 Prohibition (de.fraunhofer.iais.eis.Prohibition)3 ContractOfferBuilder (de.fraunhofer.iais.eis.ContractOfferBuilder)2 ContractRuleDesc (io.dataspaceconnector.model.rule.ContractRuleDesc)2 ContractRuleFactory (io.dataspaceconnector.model.rule.ContractRuleFactory)2