Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: adapt code base to checkstyle rules #402

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ jobs:
- name: Run Checkstyle
run: |
./gradlew checkstyleMain checkstyleTest
echo "Running Checkstyle is currently a placeholder"

markdown-lint:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class InMemoryEndpointDataReferenceCacheTest {

private static final String EDR_ID = "edr1";

private InMemoryEndpointDataReferenceCache cache = new InMemoryEndpointDataReferenceCache();
private final InMemoryEndpointDataReferenceCache cache = new InMemoryEndpointDataReferenceCache();

@Test
@SuppressWarnings("DataFlowIssue")
void verify_operations() {
var edr = EndpointDataReference.Builder.newInstance().
endpoint("http://test.com")
var edr = EndpointDataReference.Builder.newInstance()
.endpoint("http://test.com")
.id(EDR_ID)
.authCode("11111")
.authKey("authentication").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class PersistentCacheEntryTest {
void verify_serializeDeserialize() throws JsonProcessingException {
var mapper = new ObjectMapper();

var edr = EndpointDataReference.Builder.newInstance().
endpoint("http://test.com")
var edr = EndpointDataReference.Builder.newInstance()
.endpoint("http://test.com")
.id(randomUUID().toString())
.authCode("11111")
.authKey("authentication").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.runtime.metamodel.annotation.Provides;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.security.*;
import org.eclipse.edc.spi.security.CertificateResolver;
import org.eclipse.edc.spi.security.PrivateKeyResolver;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.edc.spi.security.VaultCertificateResolver;
import org.eclipse.edc.spi.security.VaultPrivateKeyResolver;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
import org.junit.jupiter.params.provider.ValueSource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class VaultMemoryExtensionTest {
private VaultMemoryExtension extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer;
import org.eclipse.edc.web.spi.configuration.WebServiceSettings;
import org.eclipse.tractusx.edc.dataplane.proxy.consumer.api.asset.ConsumerAssetRequestController;
import org.eclipse.tractusx.edc.dataplane.proxy.consumer.api.asset.ClientErrorExceptionMapper;
import org.eclipse.tractusx.edc.dataplane.proxy.consumer.api.asset.ConsumerAssetRequestController;
import org.eclipse.tractusx.edc.edr.spi.EndpointDataReferenceCache;

import java.util.concurrent.ExecutorService;
Expand All @@ -38,21 +38,16 @@
*/
@Extension(value = DataPlaneProxyConsumerApiExtension.NAME)
public class DataPlaneProxyConsumerApiExtension implements ServiceExtension {
public static final int DEFAULT_THREAD_POOL = 10;
static final String NAME = "Data Plane Proxy Consumer API";

private static final int DEFAULT_PROXY_PORT = 8186;
private static final String CONSUMER_API_ALIAS = "consumer.api";
private static final String CONSUMER_CONTEXT_PATH = "/proxy";
private static final String CONSUMER_CONFIG_KEY = "web.http.proxy";

@Setting(value = "Data plane proxy API consumer port", type = "int")
private static final String CONSUMER_PORT = "tx.dpf.consumer.proxy.port";

@Setting(value = "Thread pool size for the consumer data plane proxy gateway", type = "int")
private static final String THREAD_POOL_SIZE = "tx.dpf.consumer.proxy.thread.pool";

public static final int DEFAULT_THREAD_POOL = 10;

@Inject
private WebService webService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ private void handleCompletion(AsyncResponse response, StreamResult<Void> result,
case GENERAL_ERROR:
response.resume(status(INTERNAL_SERVER_ERROR).type(APPLICATION_JSON).build());
break;
default:
throw new IllegalStateException("Unexpected value: " + result.reason());
}
} else if (throwable != null) {
reportError(response, throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* Implements the HTTP data proxy API.
*/
@Path("/" + ProviderGatewayController.GATEWAY_PATH)
public class ProviderGatewayController implements ProviderGatewayApi{
public class ProviderGatewayController implements ProviderGatewayApi {
protected static final String GATEWAY_PATH = "gateway";

private static final String HTTP_DATA = "HttpData";
Expand Down Expand Up @@ -185,6 +185,8 @@ private void handleCompletion(AsyncResponse response, StreamResult<Void> result,
case GENERAL_ERROR:
response.resume(status(INTERNAL_SERVER_ERROR).type(APPLICATION_JSON).build());
break;
default:
throw new IllegalStateException("Unexpected value: " + result.reason());
}
} else if (throwable != null) {
reportError(response, throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Verifies RSA public key parsing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
* Tokens for testing.
*/
public class TestTokens {
public static final String TEST_TOKEN = "eyJhbGciOiJSUzI1NiIsInZlcnNpb24iOnRydWV9.eyJpc3MiOiJ0ZXN0LWNvbm5lY3RvciIsInN1YiI6ImNvbnN1bWVyLWNvbm5lY3RvciIsImF1ZCI6InRlc3QtY29ubmV" +
"jdG9yIiwiaWF0IjoxNjgxOTEzNjM2LCJleHAiOjMzNDU5NzQwNzg4LCJjaWQiOiIzMmE2M2E3ZC04MGQ2LTRmMmUtOTBlNi04MGJhZjVmYzJiM2MifQ.QAuotoRxpEqfuzkTcTq2w5Tcyy3Rc3UzUjjvNc_zwgNROGLe-w" +
"O9tFET1dJ_I5BttRxkngDS37dS4R6lN5YXaGHgcH2rf_FuVcJUSFqTp_usGAcx6m7pQQwqpNdcYgmq0NJp3xP87EFPHAy4kBxB5bqpmx4J-zrj9U_gerZ2WlRqpu0SdgP0S5v5D1Gm-vYkLqgvsugrAWH3Ti7OjC5UMdj0k" +
"DFwro2NpMY8SSNryiVvBEv8hn0KZdhhebIqPdhqbEQZ9d8WKzcgoqQ3DBd4ijzkd3Fz7ADD2gy_Hxn8Hi2LcItuB514TjCxYAncTNqZC_JSFEyuxwcGFVz3LdSXgw";
private static final String DELIMITER = "-----";
private static final String HEADER = DELIMITER + "BEGIN" + " PUBLIC " + "KEY" + DELIMITER + "\n";
private static final String FOOTER = "\n" + DELIMITER + "END" + " PUBLIC " + "KEY" + DELIMITER + "\n";

public static final String TEST_TOKEN = "eyJhbGciOiJSUzI1NiIsInZlcnNpb24iOnRydWV9.eyJpc3MiOiJ0ZXN0LWNvbm5lY3RvciIsInN1YiI6ImNvbnN1bWVyLWNvbm5lY3RvciIsImF1ZCI6InRlc3QtY29ubmVjdG9yIiwiaWF0IjoxNjgxOTEzNjM2LCJleHAiOjMzNDU5NzQwNzg4LCJjaWQiOiIzMmE2M2E3ZC04MGQ2LTRmMmUtOTBlNi04MGJhZjVmYzJiM2MifQ.QAuotoRxpEqfuzkTcTq2w5Tcyy3Rc3UzUjjvNc_zwgNROGLe-wO9tFET1dJ_I5BttRxkngDS37dS4R6lN5YXaGHgcH2rf_FuVcJUSFqTp_usGAcx6m7pQQwqpNdcYgmq0NJp3xP87EFPHAy4kBxB5bqpmx4J-zrj9U_gerZ2WlRqpu0SdgP0S5v5D1Gm-vYkLqgvsugrAWH3Ti7OjC5UMdj0kDFwro2NpMY8SSNryiVvBEv8hn0KZdhhebIqPdhqbEQZ9d8WKzcgoqQ3DBd4ijzkd3Fz7ADD2gy_Hxn8Hi2LcItuB514TjCxYAncTNqZC_JSFEyuxwcGFVz3LdSXgw";


public static String generatePublic() {
try {
var generator = KeyPairGenerator.getInstance("RSA");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public abstract class AbstractBusinessPartnerValidation {
private static final String REFERRING_CONNECTOR_CLAIM = "referringConnector";
private final Monitor monitor;
private final boolean logAgreementEvaluation;

protected AbstractBusinessPartnerValidation(Monitor monitor, boolean logAgreementEvaluation) {
this.monitor = Objects.requireNonNull(monitor);
this.logAgreementEvaluation = logAgreementEvaluation;
Expand Down Expand Up @@ -131,13 +131,7 @@ protected boolean evaluate(
}
}

/**
* @param referringConnectorClaim of the participant
* @param businessPartnerNumber object
* @return true if object is string and successfully evaluated against the claim
*/
private boolean isBusinessPartnerNumber(
String referringConnectorClaim, Object businessPartnerNumber, PolicyContext policyContext) {
private boolean isBusinessPartnerNumber(String referringConnectorClaim, Object businessPartnerNumber, PolicyContext policyContext) {
if (businessPartnerNumber == null) {
final String message = format(FAIL_EVALUATION_BECAUSE_RIGHT_VALUE_NOT_STRING, "null");
monitor.warning(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AbstractBusinessPartnerValidationTest {
private ParticipantAgent participantAgent;

@BeforeEach
void BeforeEach() {
void beforeEach() {
this.monitor = Mockito.mock(Monitor.class);
this.policyContext = Mockito.mock(PolicyContext.class);
this.participantAgent = Mockito.mock(ParticipantAgent.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private Result<Void> storeEdr(EndpointDataReference edr) {
var transferProcessId = transferProcessStore.processIdForDataRequestId(edr.getId());
var transferProcess = transferProcessStore.findById(transferProcessId);
if (transferProcess != null) {
var cacheEntry = EndpointDataReferenceEntry.Builder.newInstance().
transferProcessId(transferProcess.getId())
var cacheEntry = EndpointDataReferenceEntry.Builder.newInstance()
.transferProcessId(transferProcess.getId())
.assetId(transferProcess.getDataRequest().getAssetId())
.agreementId(transferProcess.getDataRequest().getContractId())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class AdapterTransferProcessServiceImplTest {
EndpointDataReferenceCache endpointDataReferenceCache = mock(EndpointDataReferenceCache.class);

@Test
void initEdrNegotiation_shouldFireAContractNegotiation_WhenUsingCallbacks() {
void initEdrNegotiation_shouldFireContractNegotiation_WhenUsingCallbacks() {
var transferService = new AdapterTransferProcessServiceImpl(contractNegotiationService, endpointDataReferenceCache);

var captor = ArgumentCaptor.forClass(ContractRequest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void setup() {
}

@Test
void invoke_shouldStartATransferProcess() {
void invoke_shouldStartTransferProcess() {

var captor = ArgumentCaptor.forClass(TransferRequest.class);

Expand Down Expand Up @@ -99,8 +99,8 @@ void invoke_shouldStartATransferProcess() {
}

@Test
void invoke_shouldThrowException_whenATransferRequestFails() {
void invoke_shouldThrowException_whenTransferRequestFails() {

when(transferProcessService.initiateTransfer(any())).thenReturn(ServiceResult.badRequest("test"));

var event = getNegotiationFinalizedEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void send_shouldInvokeRegisteredCallback() {
}

@Test
void send_shouldNotInvokeRegisteredCallback_whenItsNotACallbackRemoteMessage() {
void send_shouldNotInvokeRegisteredCallback_whenItsNotCallbackRemoteMessage() {

assertThatThrownBy(() -> dispatcher.send(Object.class, new TestMessage()).join())
.hasCauseInstanceOf(EdcException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
*/
package org.eclipse.tractusx.edc.oauth2;

import java.util.Map;
import org.eclipse.edc.iam.oauth2.spi.CredentialsRequestAdditionalParametersProvider;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.spi.system.ServiceExtension;

public class CXOAuth2Extension implements ServiceExtension {
import java.util.Map;

public class CxOauth2Extension implements ServiceExtension {

@Override
public String name() {
return "CX OAuth2";
}
@Override
public String name() {
return "CX OAuth2";
}

@Provider
public CredentialsRequestAdditionalParametersProvider
credentialsRequestAdditionalParametersProvider() {
return tokenParameters -> Map.of("resource", tokenParameters.getAudience());
}
@Provider
public CredentialsRequestAdditionalParametersProvider credentialsRequestAdditionalParametersProvider() {
return tokenParameters -> Map.of("resource", tokenParameters.getAudience());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
# SPDX-License-Identifier: Apache-2.0
#

org.eclipse.tractusx.edc.oauth2.CXOAuth2Extension
org.eclipse.tractusx.edc.oauth2.CxOauth2Extension
Loading