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")));
}
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));
}
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());
}
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));
}
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();
}
Aggregations