Skip to content

Commit

Permalink
Merge pull request #909 from Cofinity-X/chore/upstream-contribution
Browse files Browse the repository at this point in the history
test: add integration tests for /irs/orders API https://github.com/ec…
  • Loading branch information
ds-lcapellino authored Jan 14, 2025
2 parents b66ccea + fcc85b2 commit 3fa6e38
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 32 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private Optional<List<AspectModel>> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ private RegisterBpnInvestigationJob createRegisterBpnInvestigationBatchOrder(fin
private ProcessingState calculateBatchOrderState(final List<ProcessingState> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -111,6 +116,32 @@ static RegisterJob jobRequest(final String globalAssetId, final String bpn, fina
.build();
}

static RegisterBatchOrder batchOrderRequest(Set<PartChainIdentificationKey> 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<PartChainIdentificationKey> 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());
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -72,7 +70,7 @@ void beforeEach() {
batchOrderStore = new InMemoryBatchOrderStore();
batchStore = new InMemoryBatchStore();
service = new CreationBatchService(batchOrderStore, batchStore, applicationEventPublisher,
jobEventLinkedQueueListener, securityHelperService, irsConfiguration);
jobEventLinkedQueueListener, irsConfiguration);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}$";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}$";
}
}

0 comments on commit 3fa6e38

Please sign in to comment.