use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ContractOfferServiceImplTest method shouldNotGetContractOfferIfPolicyIsNotFound.
@Test
void shouldNotGetContractOfferIfPolicyIsNotFound() {
var contractDefinition = ContractDefinition.Builder.newInstance().id("1").accessPolicyId("access").contractPolicyId("contract").selectorExpression(AssetSelectorExpression.SELECT_ALL).build();
when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
when(contractDefinitionService.definitionsFor(isA(ParticipantAgent.class))).thenReturn(Stream.of(contractDefinition));
when(assetIndex.queryAssets(isA(AssetSelectorExpression.class))).thenReturn(Stream.of(Asset.Builder.newInstance().build()));
when(policyStore.findById(any())).thenReturn(null);
var query = ContractOfferQuery.builder().claimToken(ClaimToken.Builder.newInstance().build()).build();
var result = contractOfferService.queryContractOffers(query);
assertThat(result).hasSize(0);
}
use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ContractValidationServiceImplTest method verifyPolicyNotFound.
@Test
void verifyPolicyNotFound() {
var originalPolicy = Policy.Builder.newInstance().build();
var asset = Asset.Builder.newInstance().id("1").build();
var contractDefinition = ContractDefinition.Builder.newInstance().id("1").accessPolicyId("access").contractPolicyId("contract").selectorExpression(AssetSelectorExpression.SELECT_ALL).build();
when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
when(definitionService.definitionFor(isA(ParticipantAgent.class), eq("1"))).thenReturn(contractDefinition);
when(policyStore.findById(any())).thenReturn(null);
when(assetIndex.queryAssets(isA(QuerySpec.class))).thenReturn(Stream.of(asset));
var claimToken = ClaimToken.Builder.newInstance().build();
var offer = ContractOffer.Builder.newInstance().id("1:2").asset(asset).policy(originalPolicy).provider(URI.create("provider")).consumer(URI.create("consumer")).build();
var result = validationService.validate(claimToken, offer);
assertThat(result.failed()).isTrue();
}
use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ContractValidationServiceImplTest method verifyContractOfferValidation.
@Test
void verifyContractOfferValidation() {
var originalPolicy = Policy.Builder.newInstance().build();
var newPolicy = Policy.Builder.newInstance().build();
var asset = Asset.Builder.newInstance().id("1").build();
var contractDefinition = ContractDefinition.Builder.newInstance().id("1").accessPolicyId("access").contractPolicyId("contract").selectorExpression(AssetSelectorExpression.SELECT_ALL).build();
when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
when(definitionService.definitionFor(isA(ParticipantAgent.class), eq("1"))).thenReturn(contractDefinition);
when(policyStore.findById("access")).thenReturn(Policy.Builder.newInstance().build());
when(policyStore.findById("contract")).thenReturn(newPolicy);
when(assetIndex.queryAssets(isA(QuerySpec.class))).thenReturn(Stream.of(asset));
var claimToken = ClaimToken.Builder.newInstance().build();
var offer = ContractOffer.Builder.newInstance().id("1:2").asset(asset).policy(originalPolicy).provider(URI.create("provider")).consumer(URI.create("consumer")).build();
var result = validationService.validate(claimToken, offer);
assertThat(result.getContent()).isNotNull();
// verify the returned policy is the sanitized one
assertThat(result.getContent().getPolicy()).isNotSameAs(originalPolicy);
verify(agentService).createFor(isA(ClaimToken.class));
verify(definitionService).definitionFor(isA(ParticipantAgent.class), eq("1"));
verify(assetIndex).queryAssets(isA(QuerySpec.class));
}
use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ContractValidationServiceImplTest method validateAgreementDate.
private boolean validateAgreementDate(long signingDate, long startDate, long endDate) {
when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
var claimToken = ClaimToken.Builder.newInstance().build();
var agreement = ContractAgreement.Builder.newInstance().id("1").providerAgentId("provider").consumerAgentId("consumer").policyId("policy").assetId(UUID.randomUUID().toString()).contractSigningDate(signingDate).contractStartDate(startDate).contractEndDate(endDate).id("1:2").build();
return validationService.validate(claimToken, agreement);
}
use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ContractValidationServiceImplTest method verifyContractAgreementValidation.
@Test
void verifyContractAgreementValidation() {
var newPolicy = Policy.Builder.newInstance().build();
var contractDefinition = ContractDefinition.Builder.newInstance().id("1").accessPolicyId("access").contractPolicyId("contract").selectorExpression(AssetSelectorExpression.SELECT_ALL).build();
when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
when(definitionService.definitionFor(isA(ParticipantAgent.class), eq("1"))).thenReturn(contractDefinition);
when(policyStore.findById("access")).thenReturn(Policy.Builder.newInstance().build());
when(policyStore.findById("contract")).thenReturn(newPolicy);
var claimToken = ClaimToken.Builder.newInstance().build();
var agreement = ContractAgreement.Builder.newInstance().id("1").providerAgentId("provider").consumerAgentId("consumer").policyId("policy").assetId(UUID.randomUUID().toString()).contractStartDate(Instant.now().getEpochSecond()).contractEndDate(Instant.now().plus(1, ChronoUnit.DAYS).getEpochSecond()).contractSigningDate(Instant.now().getEpochSecond()).id("1:2").build();
assertThat(validationService.validate(claimToken, agreement)).isTrue();
verify(agentService).createFor(isA(ClaimToken.class));
verify(definitionService).definitionFor(isA(ParticipantAgent.class), eq("1"));
}
Aggregations