Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update incorrect seeding data and not supported policies #202

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/database/PolicyHub.Migrations/Seeder/Data/policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"kind_id": 5,
"technical_key": "Dismantler.allowedBrands",
"description": "Company role defining a dismantler. Companies holding the credential are dismantler certified companies.",
"is_active": true,
"is_active": false,
"attribute_key_id": 4
},
{
Expand All @@ -45,7 +45,7 @@
"kind_id": 5,
"technical_key": "Dismantler",
"description": "Companies holding the credential are dismantler certified companies.",
"is_active": true,
"is_active": false,
"attribute_key_id": 4
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,21 @@
"policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1",
"key": 4,
"attribute_value": "BMW",
"is_active": true
"is_active": false
},
{
"id": "01a0fba3-9b6e-435a-b045-e0e890c300d7",
"policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1",
"key": 4,
"attribute_value": "Audi",
"is_active": true
"is_active": false
},
{
"id": "01a0fba3-9b6e-435a-b045-e0e890c300d8",
"policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1",
"key": 4,
"attribute_value": "VW",
"is_active": true
"is_active": false
},
{
"id": "d72611ad-b6e4-47cc-94d2-d3efdc02db17",
Expand All @@ -235,7 +235,7 @@
"policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1",
"key": 4,
"attribute_value": "active",
"is_active": true
"is_active": false
},
{
"id": "01a0fba3-9b6e-435a-b045-e0e890c30030",
Expand Down
16 changes: 5 additions & 11 deletions tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ public async Task GetPolicyTypes_ReturnsExpectedResult()
var result = await sut.GetPolicyTypes(null, null).ToListAsync();

// Assert
result.Should().NotBeEmpty().And.HaveCount(7).And.Satisfy(
result.Should().NotBeEmpty().And.HaveCount(5).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber",
x => x.TechnicalKey == "Membership",
x => x.TechnicalKey == "FrameworkAgreement",
x => x.TechnicalKey == "Dismantler.allowedBrands",
x => x.TechnicalKey == "UsagePurpose",
x => x.TechnicalKey == "Dismantler",
x => x.TechnicalKey == "ContractReference"
);
}
Expand All @@ -93,11 +91,9 @@ public async Task GetPolicyTypes_WithTypeFilter_ReturnsExpectedResult()
var result = await sut.GetPolicyTypes(PolicyTypeId.Access, null).ToListAsync();

// Assert
result.Should().NotBeEmpty().And.HaveCount(4).And.Satisfy(
result.Should().NotBeEmpty().And.HaveCount(2).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Membership" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Dismantler.allowedBrands" && x.Attribute.Count() == 3 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Dismantler" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5
x => x.TechnicalKey == "Membership" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5
);
}

Expand All @@ -111,12 +107,10 @@ public async Task GetPolicyTypes_WithUseCase_ReturnsExpectedResult()
var result = await sut.GetPolicyTypes(null, UseCaseId.Quality).ToListAsync();

// Assert
result.Should().NotBeEmpty().And.HaveCount(5).And.Satisfy(
result.Should().NotBeEmpty().And.HaveCount(3).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Membership" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Dismantler.allowedBrands" && x.Attribute.Count() == 3 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "FrameworkAgreement" && x.Attribute.Count() == 1 && x.Type.Count() == 1 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Dismantler" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5
x => x.TechnicalKey == "FrameworkAgreement" && x.Attribute.Count() == 1 && x.Type.Count() == 1 && x.UseCase.Count() == 5
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ public async Task GetPolicyTypes_WithoutFilter_ReturnsExpected()

// Assert
policies.Should().NotBeNull()
.And.HaveCount(7).And.Satisfy(
.And.HaveCount(5).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber",
x => x.TechnicalKey == "Membership",
x => x.TechnicalKey == "FrameworkAgreement",
x => x.TechnicalKey == "Dismantler.allowedBrands",
x => x.TechnicalKey == "UsagePurpose",
x => x.TechnicalKey == "Dismantler",
x => x.TechnicalKey == "ContractReference"
);
}
Expand All @@ -97,11 +95,9 @@ public async Task GetPolicyTypes_WithTypeFilter_ReturnsExpected()

// Assert
policies.Should().NotBeNull()
.And.HaveCount(4).And.Satisfy(
.And.HaveCount(2).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber",
x => x.TechnicalKey == "Membership",
x => x.TechnicalKey == "Dismantler.allowedBrands",
x => x.TechnicalKey == "Dismantler"
x => x.TechnicalKey == "Membership"
);
}

Expand All @@ -113,13 +109,11 @@ public async Task GetPolicyTypes_WithUseCaseFilter_ReturnsExpected()

// Assert
policies.Should().NotBeNull()
.And.HaveCount(6).And.Satisfy(
.And.HaveCount(4).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber",
x => x.TechnicalKey == "Membership",
x => x.TechnicalKey == "FrameworkAgreement",
x => x.TechnicalKey == "Dismantler.allowedBrands",
x => x.TechnicalKey == "UsagePurpose",
x => x.TechnicalKey == "Dismantler"
x => x.TechnicalKey == "UsagePurpose"
);
}

Expand Down Expand Up @@ -184,17 +178,14 @@ public async Task GetPolicyContent_UsageFrameworkEquals_ReturnsExpected()
}

[Fact]
public async Task GetPolicyContent_UsageDismantlerIn_ReturnsExpected()
public async Task GetPolicyContent_UsageDismantlerIn_ExceptionExpected()
{
// Act
var response = await _client.GetAsync($"{BaseUrl}/policy-content?type={PolicyTypeId.Usage}&policyName=Dismantler.allowedBrands&operatorType={OperatorId.In}");

// Assert
response.Should().NotBeNull();
response.StatusCode.Should().Be(HttpStatusCode.OK);
(await response.Content.ReadAsStringAsync())
.Should()
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"cx-policy:Dismantler.allowedBrands\",\"operator\":\"in\",\"rightOperand\":[\"BMW\",\"Audi\",\"VW\"]}}}}");
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
}

[Fact]
Expand Down Expand Up @@ -225,7 +216,7 @@ public async Task GetPolicyContentWithFiltersAsync_TwoEqualsConstraintsAndOperan
new[]
{
new Constraints("FrameworkAgreement", OperatorId.Equals, "DataExchangeGovernance:1.0"),
new Constraints("Dismantler.allowedBrands", OperatorId.In, "Audi")
new Constraints("UsagePurpose", OperatorId.In, "cx.bpdm.pool:1")
});

// Act
Expand All @@ -236,7 +227,7 @@ public async Task GetPolicyContentWithFiltersAsync_TwoEqualsConstraintsAndOperan
response.StatusCode.Should().Be(HttpStatusCode.OK);
(await response.Content.ReadAsStringAsync())
.Should()
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:Dismantler.allowedBrands\",\"operator\":\"in\",\"rightOperand\":[\"BMW\",\"Audi\",\"VW\"]},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"DataExchangeGovernance:1.0\"}]}}}}");
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:UsagePurpose\",\"operator\":\"in\",\"rightOperand\":[\"cx.circular.dpp:1\",\"cx.circular.smc:1\",\"cx.circular.marketplace:1\",\"cx.circular.materialaccounting:1\",\"cx.bpdm.gate.upload:1\",\"cx.bpdm.gate.download:1\",\"cx.bpdm.pool:1\",\"cx.bpdm.vas.dataquality.upload:1\",\"cx.bpdm.vas.dataquality.download:1\",\"cx.bpdm.vas.bdv.upload:1\",\"cx.bpdm.vas.bdv.download:1\",\"cx.bpdm.vas.fpd.upload:1\",\"cx.bpdm.vas.fpd.download:1\",\"cx.bpdm.vas.swd.upload:1\",\"cx.bpdm.vas.swd.download:1\",\"cx.bpdm.vas.nps.upload:1\",\"cx.bpdm.vas.nps.download:1\",\"cx.bpdm.vas.countryrisk:1\",\"cx.behaviortwin.base:1\",\"cx.core.digitalTwinRegistry:1\",\"cx.core.tractionbattery:1\",\"cx.core.industrycore:1\",\"cx.core.qualityNotifications:1\",\"cx.pcf.base:1\",\"cx.quality.base:1\",\"cx.dcm.base:1\",\"cx.puris.base:1\"]},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"DataExchangeGovernance:1.0\"}]}}}}");
}

[Fact]
Expand Down Expand Up @@ -270,7 +261,6 @@ public async Task GetPolicyContentWithFiltersAsync_MultipleConstraintsEqualsAndO
new[]
{
new Constraints("FrameworkAgreement", OperatorId.Equals, "DataExchangeGovernance:1.0"),
new Constraints("Dismantler.allowedBrands", OperatorId.In, "Audi"),
new Constraints("BusinessPartnerNumber", OperatorId.Equals, "BPNL00000003CRHK")
});

Expand All @@ -282,7 +272,7 @@ public async Task GetPolicyContentWithFiltersAsync_MultipleConstraintsEqualsAndO
response.StatusCode.Should().Be(HttpStatusCode.OK);
(await response.Content.ReadAsStringAsync())
.Should()
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:BusinessPartnerNumber\",\"operator\":\"eq\",\"rightOperand\":\"BPNL00000003CRHK\"},{\"leftOperand\":\"cx-policy:Dismantler.allowedBrands\",\"operator\":\"in\",\"rightOperand\":[\"BMW\",\"Audi\",\"VW\"]},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"DataExchangeGovernance:1.0\"}]}}}}");
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:BusinessPartnerNumber\",\"operator\":\"eq\",\"rightOperand\":\"BPNL00000003CRHK\"},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"DataExchangeGovernance:1.0\"}]}}}}");
}

#endregion
Expand Down
Loading