forked from eclipse-tractusx/traceability-foss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: eclipse-tractusx#639 adapt integration tests
- Loading branch information
1 parent
30c995a
commit 88b7fd5
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
.../traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
package org.eclipse.tractusx.traceability.integration.notification.investigation; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.restassured.http.ContentType; | ||
import lombok.val; | ||
import notification.request.NotificationSeverityRequest; | ||
import notification.request.NotificationTypeRequest; | ||
import notification.request.StartNotificationRequest; | ||
import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; | ||
import org.eclipse.tractusx.traceability.common.request.OwnPageable; | ||
import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; | ||
import org.eclipse.tractusx.traceability.common.request.SearchCriteriaRequestParam; | ||
import org.eclipse.tractusx.traceability.integration.IntegrationTestSpecification; | ||
import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.DiscoveryFinderSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.EdcSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.IrsApiSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.NotificationApiSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.NotificationMessageSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.NotificationSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.OAuth2ApiSupport; | ||
import org.eclipse.tractusx.traceability.notification.domain.notification.service.NotificationReceiverService; | ||
import org.hamcrest.Matchers; | ||
import org.jose4j.lang.JoseException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.eclipse.tractusx.traceability.common.security.JwtRole.SUPERVISOR; | ||
|
||
@TestPropertySource(properties = "traceability.validUntil=2020-07-04T16:01:05.309Z") | ||
public class InvestigationPolicyExpirationIT extends IntegrationTestSpecification { | ||
@Autowired | ||
NotificationReceiverService notificationReceiverService; | ||
@Autowired | ||
AssetsSupport assetsSupport; | ||
@Autowired | ||
NotificationMessageSupport notificationMessageSupport; | ||
@Autowired | ||
NotificationSupport notificationSupport; | ||
@Autowired | ||
AssetAsBuiltRepository assetAsBuiltRepository; | ||
@Autowired | ||
NotificationApiSupport notificationApiSupport; | ||
@Autowired | ||
EdcSupport edcSupport; | ||
|
||
@Autowired | ||
DiscoveryFinderSupport discoveryFinderSupport; | ||
|
||
@Autowired | ||
OAuth2ApiSupport oauth2ApiSupport; | ||
|
||
@Autowired | ||
IrsApiSupport irsApiSupport; | ||
|
||
ObjectMapper objectMapper; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
objectMapper = new ObjectMapper(); | ||
} | ||
|
||
@Test | ||
void shouldNotApproveInvestigationStatus_whenPolicyIsExpired() throws JoseException, com.fasterxml.jackson.core.JsonProcessingException { | ||
// given | ||
irsApiSupport.irsApiReturnsPolicies(); | ||
discoveryFinderSupport.discoveryFinderWillReturnEndpointAddress(); | ||
discoveryFinderSupport.discoveryFinderWillReturnConnectorEndpoints(); | ||
oauth2ApiSupport.oauth2ApiReturnsDtrToken(); | ||
edcSupport.performSupportActionsForAsyncNotificationMessageExecutor(); | ||
List<String> partIds = List.of( | ||
"urn:uuid:fe99da3d-b0de-4e80-81da-882aebcca978", // BPN: BPNL00000003AYRE | ||
"urn:uuid:0ce83951-bc18-4e8f-892d-48bad4eb67ef" // BPN: BPNL00000003AXS3 | ||
); | ||
String description = "at least 15 characters long investigation description"; | ||
|
||
assetsSupport.defaultAssetsStored(); | ||
val startInvestigationRequest = StartNotificationRequest.builder() | ||
.affectedPartIds(partIds) | ||
.description(description) | ||
.severity(NotificationSeverityRequest.MINOR) | ||
.type(NotificationTypeRequest.INVESTIGATION) | ||
.receiverBpn("BPNL00000003CNKC") | ||
.build(); | ||
|
||
// when | ||
val investigationId = notificationApiSupport.createNotificationRequest_withDefaultAssetsStored(oAuth2Support.jwtAuthorization(SUPERVISOR), startInvestigationRequest, 201); | ||
|
||
|
||
notificationSupport.assertInvestigationsSize(1); | ||
|
||
given() | ||
.contentType(ContentType.JSON) | ||
.header(oAuth2Support.jwtAuthorization(SUPERVISOR)) | ||
.when() | ||
.post("/api/notifications/{investigationId}/approve", investigationId) | ||
.then() | ||
.log().all() | ||
.statusCode(503); | ||
|
||
// then | ||
given() | ||
.header(oAuth2Support.jwtAuthorization(SUPERVISOR)) | ||
.body(new PageableFilterRequest(new OwnPageable(0, 10, Collections.emptyList()), new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND")))) | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.post("/api/notifications/filter") | ||
.then() | ||
.log().all() | ||
.statusCode(200) | ||
.body("page", Matchers.is(0)) | ||
.body("pageSize", Matchers.is(10)) | ||
.body("content", Matchers.hasSize(1)) | ||
.body("content[0].sendTo", Matchers.is(Matchers.not(Matchers.blankOrNullString()))) | ||
.body("content[0].messages[0].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies are expired.")) | ||
.body("content[0].messages[1].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies are expired.")); | ||
|
||
notificationMessageSupport.assertMessageSize(2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters