Skip to content

Commit

Permalink
chore: fix tests (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood authored and paullatzelsperger committed Jun 14, 2023
1 parent 2c3820c commit f71bfda
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.edc.spi.monitor.Monitor;
import org.jetbrains.annotations.Nullable;

import java.util.Map;
import java.util.Objects;

import static java.lang.String.format;
Expand Down Expand Up @@ -102,8 +103,13 @@ protected boolean evaluate(
monitor.debug(message);
return false;
}

var referringConnectorClaim = getReferringConnectorClaim(policyContext.getParticipantAgent());
final ParticipantAgent participantAgent = policyContext.getParticipantAgent();

if (participantAgent == null) {
return false;
}

if (referringConnectorClaim == null || referringConnectorClaim.isEmpty()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void getEdr_shouldReturnDataAddress_whenFound() {
var transferProcessId = "id";
var edr = EndpointDataReference.Builder.newInstance().endpoint("test").id(transferProcessId).build();
var response = Json.createObjectBuilder()
.add(DataAddress.EDC_DATA_ADDRESS_TYPE, EndpointDataReference.EDR_SIMPLE_TYPE)
.add(DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY, EndpointDataReference.EDR_SIMPLE_TYPE)
.add(EndpointDataReference.ENDPOINT, edr.getEndpoint())
.add(EndpointDataReference.ID, edr.getId())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.edc.connector.spi.contractnegotiation.ContractNegotiationService;
import org.eclipse.edc.connector.spi.policydefinition.PolicyDefinitionService;
import org.eclipse.edc.connector.spi.transferprocess.TransferProcessService;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.junit.annotations.ApiTest;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.spi.asset.DataAddressResolver;
Expand All @@ -45,6 +46,35 @@ public class TxObservabilityApiControllerTest {

private static final String API_KEY = "12345";

// register all services that are required by the management API
protected void registerServiceMocks(EdcExtension extension) {
extension.registerServiceMock(DataAddressResolver.class, mock(DataAddressResolver.class));
extension.registerServiceMock(CatalogService.class, mock(CatalogService.class));
extension.registerServiceMock(ContractAgreementService.class, mock(ContractAgreementService.class));
extension.registerServiceMock(ContractDefinitionService.class, mock(ContractDefinitionService.class));
extension.registerServiceMock(AssetService.class, mock(AssetService.class));
extension.registerServiceMock(ContractNegotiationService.class, mock(ContractNegotiationService.class));
extension.registerServiceMock(PolicyDefinitionService.class, mock(PolicyDefinitionService.class));
extension.registerServiceMock(TransferProcessService.class, mock(TransferProcessService.class));
extension.registerServiceMock(JsonLd.class, mock(JsonLd.class));
}

static class BaseTest {
protected final int port = getFreePort();
protected String basePath;

protected BaseTest(String basePath) {
this.basePath = basePath;
}

protected RequestSpecification baseRequest() {
return given()
.baseUri("http://localhost:" + port)
.basePath(basePath)
.when();
}
}

@Nested
@DisplayName("Allow unauthenticated access")
class AllowsUnauthenticatedContextTest extends BaseTest {
Expand Down Expand Up @@ -118,33 +148,4 @@ void defaultContext_whenNoAuthHeader_shouldReturn401(String path) {
.body(notNullValue());
}
}

// register all services that are required by the management API
protected void registerServiceMocks(EdcExtension extension) {
extension.registerServiceMock(DataAddressResolver.class, mock(DataAddressResolver.class));
extension.registerServiceMock(CatalogService.class, mock(CatalogService.class));
extension.registerServiceMock(ContractAgreementService.class, mock(ContractAgreementService.class));
extension.registerServiceMock(ContractDefinitionService.class, mock(ContractDefinitionService.class));
extension.registerServiceMock(AssetService.class, mock(AssetService.class));
extension.registerServiceMock(ContractNegotiationService.class, mock(ContractNegotiationService.class));
extension.registerServiceMock(PolicyDefinitionService.class, mock(PolicyDefinitionService.class));
extension.registerServiceMock(TransferProcessService.class, mock(TransferProcessService.class));
}

static class BaseTest {
protected final int port = getFreePort();
protected String basePath;

protected BaseTest(String basePath) {
this.basePath = basePath;
}

protected RequestSpecification baseRequest() {
return given()
.baseUri("http://localhost:" + port)
.basePath(basePath)
.when();
}
}

}

0 comments on commit f71bfda

Please sign in to comment.