diff --git a/CHANGELOG.md b/CHANGELOG.md index 270a5981d5..28903a4831 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,8 @@ _**For better traceability add the corresponding GitHub issue number in each cha ### Added - Added api key authentication for edc notification requests - +- Added integration tests for /irs/orders API https://github.com/eclipse-tractusx/sig-release/issues/933 +- ## [5.4.1] - 2024-08-19 ### Fixed diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClientImpl.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClientImpl.java index fd8286dc10..8adb40f35e 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClientImpl.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClientImpl.java @@ -154,7 +154,7 @@ private Optional> readAllFromSemanticHub() { log.info("Got response from semantic hub '{}'", semanticHubPage.toString()); aspectModelsCollection.addAll( semanticHubPage.orElseThrow().toPageImpl(config.getPageSize()).getContent()); - } while (semanticHubPage.isPresent() && semanticHubPage.get().toPageImpl(config.getPageSize()).hasNext()); + } while (semanticHubPage.get().toPageImpl(config.getPageSize()).hasNext()); return Optional.of(aspectModelsCollection); } diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/services/BatchOrderEventListener.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/services/BatchOrderEventListener.java index 9184386cef..e05e5499bf 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/services/BatchOrderEventListener.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/services/BatchOrderEventListener.java @@ -174,15 +174,17 @@ private RegisterBpnInvestigationJob createRegisterBpnInvestigationBatchOrder(fin private ProcessingState calculateBatchOrderState(final List stateList) { if (stateList.stream().anyMatch(ProcessingState.PROCESSING::equals)) { return ProcessingState.PROCESSING; - } else if (stateList.stream().anyMatch(ProcessingState.ERROR::equals)) { + } + if (stateList.stream().anyMatch(ProcessingState.ERROR::equals)) { return ProcessingState.ERROR; - } else if (stateList.stream().anyMatch(ProcessingState.PARTIAL::equals)) { + } + if (stateList.stream().anyMatch(ProcessingState.PARTIAL::equals)) { return ProcessingState.PARTIAL; - } else if (stateList.stream().allMatch(ProcessingState.COMPLETED::equals)) { + } + if (stateList.stream().allMatch(ProcessingState.COMPLETED::equals)) { return ProcessingState.COMPLETED; - } else { - return ProcessingState.PARTIAL; } + return ProcessingState.PARTIAL; } } diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/services/CreationBatchService.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/services/CreationBatchService.java index 2ecd755fa8..72bb014a09 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/services/CreationBatchService.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/services/CreationBatchService.java @@ -32,7 +32,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.IrsApplication; -import org.eclipse.tractusx.irs.common.auth.SecurityHelperService; import org.eclipse.tractusx.irs.component.PartChainIdentificationKey; import org.eclipse.tractusx.irs.component.RegisterBatchOrder; import org.eclipse.tractusx.irs.component.RegisterBpnInvestigationBatchOrder; @@ -60,7 +59,6 @@ public class CreationBatchService { private final BatchStore batchStore; private final ApplicationEventPublisher applicationEventPublisher; private final JobEventLinkedQueueListener jobEventLinkedQueueListener; - private final SecurityHelperService securityHelperService; private final IrsConfiguration irsConfiguration; public UUID create(final RegisterBatchOrder request) { diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java index bea3976bc9..9d6e899327 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java @@ -32,6 +32,7 @@ import static org.eclipse.tractusx.irs.WiremockSupport.randomUUID; import static org.eclipse.tractusx.irs.component.enums.AspectType.AspectTypesConstants.BATCH; import static org.eclipse.tractusx.irs.component.enums.AspectType.AspectTypesConstants.SINGLE_LEVEL_BOM_AS_BUILT; +import static org.eclipse.tractusx.irs.configuration.JobConfiguration.JOB_BLOB_PERSISTENCE; import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL; import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.DISCOVERY_FINDER_PATH; import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.DISCOVERY_FINDER_URL; @@ -55,17 +56,26 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Set; +import java.util.UUID; import com.github.tomakehurst.wiremock.junit5.WireMockTest; import org.awaitility.Awaitility; +import org.eclipse.tractusx.irs.common.persistence.BlobPersistence; +import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException; import org.eclipse.tractusx.irs.component.JobHandle; import org.eclipse.tractusx.irs.component.Jobs; +import org.eclipse.tractusx.irs.component.PartChainIdentificationKey; import org.eclipse.tractusx.irs.component.RegisterJob; import org.eclipse.tractusx.irs.component.Tombstone; import org.eclipse.tractusx.irs.component.enums.JobState; +import org.eclipse.tractusx.irs.connector.batch.Batch; +import org.eclipse.tractusx.irs.connector.batch.JobProgress; +import org.eclipse.tractusx.irs.connector.batch.PersistentBatchStore; import org.eclipse.tractusx.irs.edc.client.EndpointDataReferenceStorage; import org.eclipse.tractusx.irs.semanticshub.AspectModels; import org.eclipse.tractusx.irs.semanticshub.SemanticHubWireMockSupport; +import org.eclipse.tractusx.irs.services.CreationBatchService; import org.eclipse.tractusx.irs.services.IrsItemGraphQueryService; import org.eclipse.tractusx.irs.services.SemanticHubService; import org.eclipse.tractusx.irs.services.validation.SchemaNotFoundException; @@ -76,6 +86,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cache.CacheManager; import org.springframework.context.ApplicationContextInitializer; @@ -94,6 +105,8 @@ @ActiveProfiles("integrationtest") class IrsWireMockIntegrationTest { + private static final String BATCH_PREFIX = "batch:"; + public static final String SEMANTIC_HUB_URL = "http://semantic.hub/models"; public static final String EDC_URL = "http://edc.test"; @@ -105,6 +118,9 @@ class IrsWireMockIntegrationTest { @Autowired private IrsItemGraphQueryService irsService; + @Autowired + private CreationBatchService batchService; + @Autowired private SemanticHubService semanticHubService; @@ -114,6 +130,13 @@ class IrsWireMockIntegrationTest { @Autowired private CacheManager cacheManager; + @Autowired + private PersistentBatchStore persistentBatchStore; + + @Autowired + @Qualifier(JOB_BLOB_PERSISTENCE) + private BlobPersistence blobStore; + @BeforeAll static void startContainer() { minioContainer.start(); @@ -134,6 +157,7 @@ static void configureProperties(DynamicPropertyRegistry registry) { registry.add("semanticshub.url", () -> SEMANTIC_HUB_URL); registry.add("semanticshub.modelJsonSchemaEndpoint", () -> SemanticHubWireMockSupport.SEMANTIC_HUB_SCHEMA_URL); registry.add("semanticshub.defaultUrns", () -> ""); + registry.add("semanticshub.pageSize", () -> 101); registry.add("irs-edc-client.controlplane.endpoint.data", () -> EDC_URL); registry.add("irs-edc-client.controlplane.endpoint.catalog", () -> PATH_CATALOG); registry.add("irs-edc-client.controlplane.endpoint.contract-negotiation", () -> PATH_NEGOTIATE); @@ -159,7 +183,7 @@ void shouldStartApplicationAndCollectSemanticModels() throws SchemaNotFoundExcep final AspectModels allAspectModels = semanticHubService.getAllAspectModels(); // Assert - assertThat(allAspectModels.models()).hasSize(99); + assertThat(allAspectModels.models()).hasSize(101); } @Test @@ -182,7 +206,7 @@ void shouldStopJobAfterDepthIsReached() { // Act final JobHandle jobHandle = irsService.registerItemJob(request); assertThat(jobHandle.getId()).isNotNull(); - waitForCompletion(jobHandle); + waitForCompletion(jobHandle.getId()); Jobs jobForJobId = irsService.getJobForJobId(jobHandle.getId(), true); @@ -226,7 +250,7 @@ void shouldSendOneCallbackAfterJobCompletion() { for (JobHandle jobHandle : startedJobs) { assertThat(jobHandle.getId()).isNotNull(); - waitForCompletion(jobHandle); + waitForCompletion(jobHandle.getId()); } // Assert @@ -248,7 +272,7 @@ void shouldCreateTombstoneWhenDiscoveryServiceNotAvailable() { // Assert assertThat(jobHandle.getId()).isNotNull(); - waitForCompletion(jobHandle); + waitForCompletion(jobHandle.getId()); final Jobs jobForJobId = irsService.getJobForJobId(jobHandle.getId(), true); verify(1, postRequestedFor(urlPathEqualTo(DISCOVERY_FINDER_PATH))); @@ -280,7 +304,7 @@ void shouldCreateTombstoneWhenEdcDiscoveryIsEmpty() { // Assert assertThat(jobHandle.getId()).isNotNull(); - waitForCompletion(jobHandle); + waitForCompletion(jobHandle.getId()); final Jobs jobForJobId = irsService.getJobForJobId(jobHandle.getId(), true); WiremockSupport.verifyDiscoveryCalls(1); @@ -322,7 +346,7 @@ void shouldStartRecursiveProcesses() { // Assert assertThat(jobHandle.getId()).isNotNull(); - waitForCompletion(jobHandle); + waitForCompletion(jobHandle.getId()); final Jobs jobForJobId = irsService.getJobForJobId(jobHandle.getId(), false); assertThat(jobForJobId.getJob().getState()).isEqualTo(JobState.COMPLETED); @@ -344,7 +368,7 @@ void shouldCreateDetailedTombstoneForMismatchPolicy() { WiremockSupport.successfulSemanticHubRequests(); WiremockSupport.successfulDiscovery(); - failedRegistryRequestMissmatchPolicy(); + failedRegistryRequestMismatchPolicy(); final RegisterJob request = WiremockSupport.jobRequest(globalAssetId, TEST_BPN, 4); @@ -353,7 +377,7 @@ void shouldCreateDetailedTombstoneForMismatchPolicy() { // Assert assertThat(jobHandle.getId()).isNotNull(); - waitForCompletion(jobHandle); + waitForCompletion(jobHandle.getId()); final Jobs jobForJobId = irsService.getJobForJobId(jobHandle.getId(), false); assertThat(jobForJobId.getJob().getState()).isEqualTo(JobState.COMPLETED); @@ -393,7 +417,7 @@ void shouldCreateDetailedTombstoneForEdcErrors() { // Assert assertThat(jobHandle.getId()).isNotNull(); - waitForCompletion(jobHandle); + waitForCompletion(jobHandle.getId()); final Jobs jobForJobId = irsService.getJobForJobId(jobHandle.getId(), false); assertThat(jobForJobId.getJob().getState()).isEqualTo(JobState.COMPLETED); @@ -430,7 +454,7 @@ void whenEmptyCatalogIsReturnedFromAllEndpoints() { final RegisterJob request = WiremockSupport.jobRequest(globalAssetId, TEST_BPN, 4); final JobHandle jobHandle = irsService.registerItemJob(request); assertThat(jobHandle.getId()).isNotNull(); - waitForCompletion(jobHandle); + waitForCompletion(jobHandle.getId()); final Jobs jobForJobId = irsService.getJobForJobId(jobHandle.getId(), false); // Assert @@ -469,7 +493,7 @@ void shouldCreateDetailedTombstoneForDiscoveryErrors() { // Assert assertThat(jobHandle.getId()).isNotNull(); - waitForCompletion(jobHandle); + waitForCompletion(jobHandle.getId()); final Jobs jobForJobId = irsService.getJobForJobId(jobHandle.getId(), false); assertThat(jobForJobId.getJob().getState()).isEqualTo(JobState.COMPLETED); @@ -490,6 +514,162 @@ void shouldCreateDetailedTombstoneForDiscoveryErrors() { assertThat(rootCauses.get(0)).contains("No EDC Endpoints could be discovered for BPN '%s'".formatted(TEST_BPN)); } + @Test + void shouldDoABatchRequestAndFinishAllJobs_regularJob() { + // Arrange + final String globalAssetIdLevel1 = "globalAssetId"; + final String globalAssetIdLevel2 = "urn:uuid:7e4541ea-bb0f-464c-8cb3-021abccbfaf5"; + + WiremockSupport.successfulSemanticModelRequest(); + WiremockSupport.successfulSemanticHubRequests(); + WiremockSupport.successfulDiscovery(); + + successfulRegistryAndDataRequest(globalAssetIdLevel1, "Cathode", TEST_BPN, "integrationtesting/batch-1.json", + "integrationtesting/singleLevelBomAsBuilt-1.json"); + successfulRegistryAndDataRequest(globalAssetIdLevel2, "Polyamid", TEST_BPN, "integrationtesting/batch-2.json", + "integrationtesting/singleLevelBomAsBuilt-2.json"); + + Set keys = Set.of( + PartChainIdentificationKey.builder().bpn(TEST_BPN).globalAssetId(globalAssetIdLevel1).build(), + PartChainIdentificationKey.builder().bpn(TEST_BPN).globalAssetId(globalAssetIdLevel2).build()); + + // Act + final UUID batchOrderId = batchService + .create(WiremockSupport.batchOrderRequest(keys,1, WiremockSupport.CALLBACK_URL)); + + assertThat(batchOrderId).isNotNull(); + + waitForBatchOrderEventListenerFired(); + + List allBatches = persistentBatchStore.findAll(); + + allBatches.stream().map(Batch::getJobProgressList) + .flatMap(List::stream) + .forEach(jobProgress -> waitForCompletion(jobProgress.getJobId())); + + // Assert + WiremockSupport.verifyDiscoveryCalls(1); + WiremockSupport.verifyNegotiationCalls(6); + + List jobIds = allBatches.stream() + .flatMap(batch -> batch.getJobProgressList().stream()) + .map(JobProgress::getJobId) + .toList(); + + assertThat(jobIds).hasSize(2); + + List jobs = jobIds.stream().map(jobId -> irsService.getJobForJobId(jobId, true)).toList(); + + Jobs job1 = jobs.stream().filter(job -> job.getJob().getGlobalAssetId().getGlobalAssetId().equals(globalAssetIdLevel1)).findFirst().get(); + + assertThat(job1.getJob().getState()).isEqualTo(JobState.COMPLETED); + assertThat(job1.getShells()).hasSize(2); + assertThat(job1.getRelationships()).hasSize(1); + assertThat(job1.getTombstones()).isEmpty(); + assertThat(job1.getSubmodels()).hasSize(2); + + WiremockSupport.verifyCallbackCall(job1.getJob().getId().toString(), JobState.COMPLETED, 1); + + Jobs job2 = jobs.stream().filter(job -> job.getJob().getGlobalAssetId().getGlobalAssetId().equals(globalAssetIdLevel2)).findFirst().get(); + + assertThat(job2.getJob().getState()).isEqualTo(JobState.COMPLETED); + assertThat(job2.getShells()).hasSize(1); + assertThat(job2.getRelationships()).hasSize(1); + assertThat(job2.getTombstones()).hasSize(1); + assertThat(job2.getSubmodels()).hasSize(2); + + WiremockSupport.verifyCallbackCall(job2.getJob().getId().toString(), JobState.COMPLETED, 1); + + //cleanup + allBatches.forEach(batch -> { + try { + blobStore.delete(toBlobId(batch.getBatchId().toString()), new ArrayList<>()); + } catch (BlobPersistenceException e) { + // ignoring + } + }); + } + + @Test + void shouldDoABatchRequestAndFinishAllJobs_essJob() { + // Arrange + final String globalAssetIdLevel1 = "globalAssetId"; + final String globalAssetIdLevel2 = "urn:uuid:7e4541ea-bb0f-464c-8cb3-021abccbfaf5"; + + WiremockSupport.successfulSemanticModelRequest(); + WiremockSupport.successfulSemanticHubRequests(); + WiremockSupport.successfulDiscovery(); + + successfulRegistryAndDataRequest(globalAssetIdLevel1, "Cathode", TEST_BPN, "integrationtesting/batch-1.json", + "integrationtesting/singleLevelBomAsBuilt-1.json"); + successfulRegistryAndDataRequest(globalAssetIdLevel2, "Polyamid", TEST_BPN, "integrationtesting/batch-2.json", + "integrationtesting/singleLevelBomAsBuilt-2.json"); + + Set keys = Set.of( + PartChainIdentificationKey.builder().bpn(TEST_BPN).globalAssetId(globalAssetIdLevel1).build(), + PartChainIdentificationKey.builder().bpn(TEST_BPN).globalAssetId(globalAssetIdLevel2).build()); + + // Act + final UUID batchOrderId = batchService + .create(WiremockSupport.bpnInvestigationBatchOrderRequest(keys, WiremockSupport.CALLBACK_BATCH_URL)); + + assertThat(batchOrderId).isNotNull(); + + waitForBatchOrderEventListenerFired(); + + List allBatches = persistentBatchStore.findAll(); + + allBatches.stream().map(Batch::getJobProgressList) + .flatMap(List::stream) + .forEach(jobProgress -> waitForCompletion(jobProgress.getJobId())); + + // Assert + WiremockSupport.verifyDiscoveryCalls(1); + WiremockSupport.verifyNegotiationCalls(2); + + List jobIds = allBatches.stream() + .flatMap(batch -> batch.getJobProgressList().stream()) + .map(JobProgress::getJobId) + .toList(); + + assertThat(jobIds).hasSize(2); + + List jobs = jobIds.stream().map(jobId -> irsService.getJobForJobId(jobId, true)).toList(); + + Jobs job1 = jobs.stream().filter(job -> job.getJob().getGlobalAssetId().getGlobalAssetId().equals(globalAssetIdLevel1)).findFirst().get(); + + assertThat(job1.getJob().getState()).isEqualTo(JobState.COMPLETED); + assertThat(job1.getShells()).hasSize(1); + assertThat(job1.getRelationships()).hasSize(0); + assertThat(job1.getTombstones()).isEmpty(); + assertThat(job1.getSubmodels()).hasSize(0); + + Jobs job2 = jobs.stream().filter(job -> job.getJob().getGlobalAssetId().getGlobalAssetId().equals(globalAssetIdLevel2)).findFirst().get(); + + assertThat(job2.getJob().getState()).isEqualTo(JobState.COMPLETED); + assertThat(job2.getShells()).hasSize(1); + assertThat(job2.getRelationships()).hasSize(0); + assertThat(job2.getTombstones()).hasSize(0); + assertThat(job2.getSubmodels()).hasSize(0); + + WiremockSupport.verifyBatchCallbackCall(allBatches.get(0).getBatchId().toString(), JobState.COMPLETED, 1); + WiremockSupport.verifyBatchCallbackCall(allBatches.get(1).getBatchId().toString(), JobState.COMPLETED, 1); + } + + private void waitForBatchOrderEventListenerFired() { + Awaitility.await() + .timeout(Duration.ofSeconds(30)) + .pollInterval(Duration.ofMillis(500)) + .until(() -> persistentBatchStore.findAll().stream() + .map(Batch::getJobProgressList) + .flatMap(List::stream) + .allMatch(jobProgress -> jobProgress.getJobId() != null)); + } + + protected String toBlobId(final String batchId) { + return BATCH_PREFIX + batchId; + } + private void successfulRegistryAndDataRequest(final String globalAssetId, final String idShort, final String bpn, final String batchFileName, final String sbomFileName) { @@ -520,16 +700,16 @@ private void successfulNegotiation(final String edcAssetId) { endpointDataReferenceStorage.put(contractAgreementId, createEndpointDataReference(contractAgreementId)); } - private void failedRegistryRequestMissmatchPolicy() { + private void failedRegistryRequestMismatchPolicy() { final String registryEdcAssetId = "registry-asset"; - failedPolicyMissmatchNegotiation(registryEdcAssetId); + failedPolicyMismatchNegotiation(registryEdcAssetId); } private void failedRegistryRequestEdcError() { failedNegotiation(); } - private void failedPolicyMissmatchNegotiation(final String edcAssetId) { + private void failedPolicyMismatchNegotiation(final String edcAssetId) { final String contractAgreementId = "%s:%s:%s".formatted(randomUUID(), edcAssetId, randomUUID()); SubmodelFacadeWiremockSupport.prepareMissmatchPolicyCatalog(edcAssetId, contractAgreementId); } @@ -542,11 +722,11 @@ private void emptyCatalog(final String bpn, final String edcUrl) { SubmodelFacadeWiremockSupport.prepareEmptyCatalog(bpn, edcUrl); } - private void waitForCompletion(final JobHandle jobHandle) { + private void waitForCompletion(final UUID jobHandleId) { Awaitility.await() .timeout(Duration.ofSeconds(35)) .pollInterval(Duration.ofMillis(500)) - .until(() -> irsService.getJobForJobId(jobHandle.getId(), false) + .until(() -> irsService.getJobForJobId(jobHandleId, false) .getJob() .getState() .equals(JobState.COMPLETED)); diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/WiremockSupport.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/WiremockSupport.java index addaad76a6..5d5f9bb421 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/WiremockSupport.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/WiremockSupport.java @@ -40,12 +40,16 @@ import java.util.Base64; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; import org.eclipse.tractusx.irs.component.PartChainIdentificationKey; +import org.eclipse.tractusx.irs.component.RegisterBatchOrder; +import org.eclipse.tractusx.irs.component.RegisterBpnInvestigationBatchOrder; import org.eclipse.tractusx.irs.component.RegisterJob; import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; +import org.eclipse.tractusx.irs.component.enums.BatchStrategy; import org.eclipse.tractusx.irs.component.enums.Direction; import org.eclipse.tractusx.irs.component.enums.JobState; import org.eclipse.tractusx.irs.data.StringMapper; @@ -61,6 +65,7 @@ public class WiremockSupport { public static final String SUBMODEL_SUFFIX = "/\\$value"; public static final String CALLBACK_URL = "http://localhost/callback?id={id}&state={state}"; + public static final String CALLBACK_BATCH_URL = "http://localhost/callback?batchId={batchId}&batchState={batchState}"; public static final String CALLBACK_PATH = "/callback"; public static EndpointDataReference createEndpointDataReference(final String contractAgreementId) { @@ -111,6 +116,32 @@ static RegisterJob jobRequest(final String globalAssetId, final String bpn, fina .build(); } + static RegisterBatchOrder batchOrderRequest(Set keys, final int depth, + final String callbackUrl) { + return RegisterBatchOrder.builder() + .keys(keys) + .depth(depth) + .callbackUrl(callbackUrl) + .batchStrategy(BatchStrategy.PRESERVE_BATCH_ORDER) + .direction(Direction.DOWNWARD) + .collectAspects(true) + .batchSize(1) + .timeout(100) + .aspects(List.of(BATCH_3_0_0, SINGLE_LEVEL_BOM_AS_BUILT_3_0_0)) + .build(); + } + + static RegisterBpnInvestigationBatchOrder bpnInvestigationBatchOrderRequest(Set keys, final String callbackUrl) { + return RegisterBpnInvestigationBatchOrder.builder() + .keys(keys) + .incidentBPNSs(List.of()) + .callbackUrl(callbackUrl) + .batchStrategy(BatchStrategy.PRESERVE_BATCH_ORDER) + .batchSize(1) + .timeout(100) + .build(); + } + static void successfulDiscovery() { stubFor(DiscoveryServiceWiremockSupport.postDiscoveryFinder200()); stubFor(DiscoveryServiceWiremockSupport.postEdcDiscovery200()); @@ -172,6 +203,11 @@ static void verifyCallbackCall(final String jobId, final JobState state, final i .withQueryParam("state", equalTo(state.toString()))); } + static void verifyBatchCallbackCall(final String jobId, final JobState state, final int times) { + verify(times, getRequestedFor(urlPathEqualTo(CALLBACK_PATH)).withQueryParam("batchId", equalTo(jobId)) + .withQueryParam("batchState", equalTo(state.toString()))); + } + static void successfulSemanticHubRequests() { SemanticHubWireMockSupport.semanticHubWillReturnBatchSchema(); SemanticHubWireMockSupport.semanticHubWillReturnSingleLevelBomAsBuiltSchema(); diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/services/CreationBatchServiceTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/services/CreationBatchServiceTest.java index c5948517a8..674942fa69 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/services/CreationBatchServiceTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/services/CreationBatchServiceTest.java @@ -36,7 +36,6 @@ import java.util.stream.IntStream; import org.eclipse.tractusx.irs.IrsApplication; -import org.eclipse.tractusx.irs.common.auth.SecurityHelperService; import org.eclipse.tractusx.irs.component.PartChainIdentificationKey; import org.eclipse.tractusx.irs.component.RegisterBatchOrder; import org.eclipse.tractusx.irs.component.RegisterBpnInvestigationBatchOrder; @@ -62,7 +61,6 @@ class CreationBatchServiceTest { private BatchStore batchStore; private final ApplicationEventPublisher applicationEventPublisher = mock(ApplicationEventPublisher.class); private final JobEventLinkedQueueListener jobEventLinkedQueueListener = mock(JobEventLinkedQueueListener.class); - private final SecurityHelperService securityHelperService = mock(SecurityHelperService.class); private final IrsConfiguration irsConfiguration = mock(IrsConfiguration.class); private final static String EXAMPLE_URL = "https://exampleUrl.com"; private CreationBatchService service; @@ -72,7 +70,7 @@ void beforeEach() { batchOrderStore = new InMemoryBatchOrderStore(); batchStore = new InMemoryBatchStore(); service = new CreationBatchService(batchOrderStore, batchStore, applicationEventPublisher, - jobEventLinkedQueueListener, securityHelperService, irsConfiguration); + jobEventLinkedQueueListener, irsConfiguration); } @Test diff --git a/irs-api/src/test/resources/__files/semantichub/all-models-page-IT.json b/irs-api/src/test/resources/__files/semantichub/all-models-page-IT.json index de80a4d7ec..f630950a73 100644 --- a/irs-api/src/test/resources/__files/semantichub/all-models-page-IT.json +++ b/irs-api/src/test/resources/__files/semantichub/all-models-page-IT.json @@ -692,10 +692,24 @@ "name": "TractionBatteryCode", "type": "SAMM", "status": "RELEASED" + }, + { + "urn": "urn:samm:io.catenax.part_site_information_as_planned:1.0.0#PartSiteInformationAsPlanned", + "version": "1.0.0", + "name": "PartSiteInformationAsPlanned", + "type": "SAMM", + "status": "RELEASED" + }, + { + "urn": "urn:samm:io.catenax.part_as_planned:1.0.1#PartAsPlanned", + "version": "1.0.1", + "name": "PartAsPlanned", + "type": "SAMM", + "status": "RELEASED" } ], - "totalItems": 99, + "totalItems": 101, "currentPage": 0, "totalPages": 1, - "itemCount": 99 + "itemCount": 101 } \ No newline at end of file diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/RegisterBatchOrder.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/RegisterBatchOrder.java index aaa70ab534..6de0bb3410 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/RegisterBatchOrder.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/RegisterBatchOrder.java @@ -174,6 +174,5 @@ public int getDepth() { /* package */ static final int MIN_JOB_TIMEOUT = 60; /* package */ static final int MAX_JOB_TIMEOUT = 7200; /* package */ static final int DEFAULT_JOB_TIMEOUT = 3600; - /* package */ static final String GLOBAL_ASSET_ID_REGEX = "^urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"; } } diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/RegisterBpnInvestigationBatchOrder.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/RegisterBpnInvestigationBatchOrder.java index 3816d8d02a..d9744920ab 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/RegisterBpnInvestigationBatchOrder.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/RegisterBpnInvestigationBatchOrder.java @@ -141,6 +141,5 @@ public class RegisterBpnInvestigationBatchOrder { /* package */ static final int MIN_JOB_TIMEOUT = 60; /* package */ static final int MAX_JOB_TIMEOUT = 7200; /* package */ static final int DEFAULT_JOB_TIMEOUT = 3600; - /* package */ static final String GLOBAL_ASSET_ID_REGEX = "^urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"; } }