-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add e2e tests, add generator service impl
- Loading branch information
1 parent
293845d
commit b32fb30
Showing
13 changed files
with
160 additions
and
47 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
46 changes: 46 additions & 0 deletions
46
...ava/org/eclipse/edc/connector/dataplane/framework/PublicEndpointGeneratorServiceImpl.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,46 @@ | ||
/* | ||
* Copyright (c) 2024 Metaform Systems, Inc. | ||
* | ||
* 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 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Metaform Systems, Inc. - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.dataplane.framework; | ||
|
||
import org.eclipse.edc.connector.dataplane.spi.Endpoint; | ||
import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService; | ||
import org.eclipse.edc.spi.result.Result; | ||
import org.eclipse.edc.spi.types.domain.DataAddress; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Function; | ||
|
||
class PublicEndpointGeneratorServiceImpl implements PublicEndpointGeneratorService { | ||
private final Map<String, Function<DataAddress, Endpoint>> generatorFunctions = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public Result<Endpoint> generateFor(DataAddress sourceDataAddress) { | ||
Objects.requireNonNull(sourceDataAddress); | ||
Objects.requireNonNull(sourceDataAddress.getType()); | ||
|
||
return Optional.ofNullable(generatorFunctions.get(sourceDataAddress.getType())) | ||
.map(function -> function.apply(sourceDataAddress)) | ||
.map(Result::success) | ||
.orElseGet(() -> Result.failure("No Endpoint generator function registered for source data type '%s'".formatted(sourceDataAddress.getType()))); | ||
} | ||
|
||
@Override | ||
public void addGeneratorFunction(String destinationType, Function<DataAddress, Endpoint> generatorFunction) { | ||
generatorFunctions.put(destinationType, generatorFunction); | ||
} | ||
} |
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
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
47 changes: 47 additions & 0 deletions
47
...org/eclipse/edc/connector/dataplane/framework/PublicEndpointGeneratorServiceImplTest.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,47 @@ | ||
/* | ||
* Copyright (c) 2024 Metaform Systems, Inc. | ||
* | ||
* 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 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Metaform Systems, Inc. - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.dataplane.framework; | ||
|
||
import org.eclipse.edc.connector.dataplane.spi.Endpoint; | ||
import org.eclipse.edc.spi.types.domain.DataAddress; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | ||
|
||
|
||
class PublicEndpointGeneratorServiceImplTest { | ||
|
||
private final PublicEndpointGeneratorServiceImpl generatorService = new PublicEndpointGeneratorServiceImpl(); | ||
|
||
@Test | ||
void generateFor() { | ||
var endpoint = new Endpoint(Map.of("fizz", "buzz"), "bar-type"); | ||
generatorService.addGeneratorFunction("testtype", dataAddress -> endpoint); | ||
|
||
assertThat(generatorService.generateFor(DataAddress.Builder.newInstance().type("testtype").build())).isSucceeded() | ||
.isEqualTo(endpoint); | ||
} | ||
|
||
@Test | ||
void generateFor_noFunction() { | ||
assertThat(generatorService.generateFor(DataAddress.Builder.newInstance().type("testtype").build())) | ||
.isFailed() | ||
.detail() | ||
.isEqualTo("No Endpoint generator function registered for source data type 'testtype'"); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.