Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
joostfarla committed Sep 27, 2023
1 parent 0852b05 commit cf61a0b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
6 changes: 3 additions & 3 deletions data/bld/BuildingPart.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"id": "B0001",
"id": "BP0001",
"isPartOf": [
{
"id": "B0001"
Expand All @@ -11,7 +11,7 @@
}
},
{
"id": "B0002",
"id": "BP0002",
"isPartOf": [
{
"id": "B0002"
Expand All @@ -22,7 +22,7 @@
}
},
{
"id": "B0003",
"id": "BP0003",
"isPartOf": [
{
"id": "B0002"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,29 @@ private FetchOperation fetchSourceObject(ObjectTypeRef sourceTypeRef, Set<Path>
var keyProperty = sourceType.getProperty(keyPath.getFirstSegment());
selectedProperties.add(SelectedProperty.forProperty(keyProperty));
});
// } else {
// selectedProperties.add(new SelectedProperty(property, selectIdentity(targetTypeRef)));
} else {
var targetModel = modelMapping.getSourceModel(targetTypeRef.getModelAlias());

// TODO: Refactoe
if (property.getCardinality().isSingular()) {
selectedProperties.add(SelectedProperty.builder()
.property(property)
.nestedRequest(ObjectRequest.builder(targetModel)
.objectType(targetTypeRef)
.objectKey(Map.of())
.selectedProperties(selectIdentity(targetTypeRef))
.build())
.build());
} else {
// TODO: Filter
selectedProperties.add(SelectedProperty.builder()
.property(property)
.nestedRequest(CollectionRequest.builder(targetModel)
.objectType(targetTypeRef)
.selectedProperties(selectIdentity(targetTypeRef))
.build())
.build());
}
}

var identityPaths = targetType.getIdentityProperties()
Expand Down Expand Up @@ -304,13 +325,7 @@ private Set<SelectedProperty> selectIdentity(ObjectTypeRef typeRef) {
return modelMapping.getSourceType(typeRef)
.getIdentityProperties()
.stream()
.map(property -> {
// if (property instanceof Relation relation) {
// return new SelectedProperty(property, selectIdentity(relation.getTarget(typeRef)));
// }

return SelectedProperty.forProperty(property);
})
.map(SelectedProperty::forProperty)
.collect(toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import nl.geostandaarden.imx.orchestrate.engine.exchange.CollectionRequest;
import nl.geostandaarden.imx.orchestrate.engine.exchange.ObjectRequest;
import nl.geostandaarden.imx.orchestrate.engine.source.DataRepository;
import nl.geostandaarden.imx.orchestrate.model.ComponentRegistry;
Expand All @@ -20,6 +21,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

Expand Down Expand Up @@ -67,13 +69,31 @@ void fetch() {
.build();

when(dataRepositoryMock.findOne(any(ObjectRequest.class)))
.thenReturn(Mono.just(Map.of("id", "B0001", "area", 123)));
.thenAnswer(invocation -> {
var objectType = ((ObjectRequest) invocation.getArgument(0)).getObjectType();

return switch (objectType.getName()) {
case "Building" -> Mono.just(Map.of("id", "B0001", "area", 123));
case "Address" -> Mono.just(Map.of("id", "A0001", "houseNumber", 23, "postalCode", "1234AB"));
default -> throw new IllegalStateException();
};
});

when(dataRepositoryMock.find(any(CollectionRequest.class)))
.thenAnswer(invocation -> {
var objectType = ((CollectionRequest) invocation.getArgument(0)).getObjectType();

return switch (objectType.getName()) {
case "BuildingPart" -> Flux.just(Map.of("id", "BP0001", "hasMainAddress", Map.of("id", "A0001")));
default -> throw new IllegalStateException();
};
});

var resultMono = engine.fetch(request);

StepVerifier.create(resultMono)
.assertNext(result -> {
System.out.println(result);
System.out.println(result.getProperties());
})
.expectComplete()
.verify();
Expand Down

0 comments on commit cf61a0b

Please sign in to comment.