Skip to content

Commit

Permalink
refactor: adapt code base to checkstyle rules
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed May 23, 2023
1 parent 69e4a06 commit 5c1defb
Show file tree
Hide file tree
Showing 141 changed files with 4,229 additions and 4,306 deletions.
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 @@ -22,7 +22,11 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import static java.util.Collections.emptyList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class InMemoryEndpointDataReferenceCacheTest {
private static final String ASSET_ID = "asset1";
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 @@ -39,7 +39,7 @@ public class AdapterTransferProcessServiceImplTest {
ContractNegotiationService contractNegotiationService = mock(ContractNegotiationService.class);

@Test
void initEdrNegotiation_shouldFireAContractNegotiation_WhenUsingCallbacks() {
void initEdrNegotiation_shouldFireContractNegotiation_whenUsingCallbacks() {
var transferService = new AdapterTransferProcessServiceImpl(contractNegotiationService);

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 @@ -30,7 +30,9 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.tractusx.edc.cp.adapter.callback.InProcessCallbackMessageDispatcher.CALLBACK_EVENT_LOCAL;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@ExtendWith(DependencyInjectionExtension.class)
public class LocalCallbackExtensionTest {
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

0 comments on commit 5c1defb

Please sign in to comment.