From 0537dc2fc55fa5fd2527db36fcf2e9740a54b863 Mon Sep 17 00:00:00 2001 From: Martin Vogel <martin.vogel@sinc.de> Date: Tue, 6 Sep 2022 12:50:00 +0200 Subject: [PATCH] chore: fix sonar lint issues --- .../domain/model/destination/Destination.java | 4 +- .../api/domain/model/event/EventLog.java | 2 +- .../metadata/AdditionalReferenceInfo.java | 3 -- .../model/metadata/ContentStructure.java | 3 -- .../api/domain/model/metadata/Metadata.java | 4 +- .../model/metadata/PublicServiceType.java | 3 -- .../domain/model/metadata/data/Signature.java | 3 -- .../model/metadata/data/SubmissionSchema.java | 3 -- .../api/domain/model/submission/Callback.java | 3 -- .../domain/model/submission/Submission.java | 2 - .../fitko/fitconnect/client/SenderClient.java | 18 ++++---- .../fitconnect/client/SubscriberClient.java | 2 +- .../client/cmd/CommandLineClient.java | 5 +-- .../factory/ApplicationConfigLoader.java | 4 +- .../client/ClientIntegrationTest.java | 8 ++-- .../fitconnect/client/SenderClientTest.java | 42 +++++++++---------- .../client/SubscriberClientTest.java | 32 +++++++------- .../client/factory/ClientFactoryTest.java | 8 ++-- .../core/auth/DefaultOAuthService.java | 11 +++-- .../fitconnect/core/crypto/HashService.java | 2 +- .../events/SecurityEventTokenService.java | 9 ++-- .../fitconnect/core/util/Preconditions.java | 9 ++-- .../fitko/fitconnect/core/util/Strings.java | 2 + ...tConfig.java => SubmissionSenderTest.java} | 36 +++++++--------- .../core/SubmissionSubscriberTest.java | 29 ++++++------- .../core/auth/DefaultOAuthServiceTest.java | 8 ++-- .../core/auth/OAuthTokenIntegrationTest.java | 4 +- .../core/crypto/HashServiceTest.java | 10 ++--- .../DestinationRestServiceTest.java | 6 +-- .../core/events/EventLogApiServiceTest.java | 10 ++--- .../events/SecurityEventTokenServiceTest.java | 12 +++--- .../fitconnect/core/http/ProxyConfigTest.java | 10 ++--- .../submission/SubmissionApiServiceTest.java | 23 +++++----- .../fitconnect/core/util/StringsTest.java | 6 +-- .../DefaultValidationServiceTest.java | 18 ++++---- 35 files changed, 159 insertions(+), 195 deletions(-) rename core/src/test/java/de/fitko/fitconnect/core/{SubmissionSenderTestConfig.java => SubmissionSenderTest.java} (90%) diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/destination/Destination.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/destination/Destination.java index 7210e7547..2d405d471 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/destination/Destination.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/destination/Destination.java @@ -1,14 +1,12 @@ package de.fitko.fitconnect.api.domain.model.destination; -import com.fasterxml.jackson.annotation.*; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.annotation.JsonProperty; import de.fitko.fitconnect.api.domain.model.submission.Callback; import lombok.Data; import lombok.NoArgsConstructor; import java.util.LinkedHashSet; -import java.util.Objects; import java.util.Set; import java.util.UUID; diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/event/EventLog.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/event/EventLog.java index fd14f18a4..4baff7866 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/event/EventLog.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/event/EventLog.java @@ -21,7 +21,7 @@ public class EventLog { private Integer totalCount; @JsonProperty("eventLog") - private List<String> eventLog = new ArrayList<>(); + private List<String> eventLogs = new ArrayList<>(); } diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/AdditionalReferenceInfo.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/AdditionalReferenceInfo.java index 3b208af5d..d28cb6ba4 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/AdditionalReferenceInfo.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/AdditionalReferenceInfo.java @@ -3,10 +3,7 @@ package de.fitko.fitconnect.api.domain.model.metadata; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.Data; -import lombok.Getter; -import lombok.Setter; import java.util.Map; diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/ContentStructure.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/ContentStructure.java index 0085fa3f3..9931774f8 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/ContentStructure.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/ContentStructure.java @@ -3,12 +3,9 @@ package de.fitko.fitconnect.api.domain.model.metadata; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; import de.fitko.fitconnect.api.domain.model.metadata.attachment.Attachment; import de.fitko.fitconnect.api.domain.model.metadata.data.Data; -import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import java.util.List; import java.util.Map; diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/Metadata.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/Metadata.java index eb12ef031..4923277de 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/Metadata.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/Metadata.java @@ -3,8 +3,8 @@ package de.fitko.fitconnect.api.domain.model.metadata; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.*; +import lombok.Data; +import lombok.NoArgsConstructor; import java.util.List; import java.util.Map; diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/PublicServiceType.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/PublicServiceType.java index 154fe0918..407f84dcf 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/PublicServiceType.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/PublicServiceType.java @@ -3,10 +3,7 @@ package de.fitko.fitconnect.api.domain.model.metadata; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.Data; -import lombok.Getter; -import lombok.Setter; import java.util.Map; diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/data/Signature.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/data/Signature.java index 972ba6093..316d85bf0 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/data/Signature.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/data/Signature.java @@ -3,12 +3,9 @@ package de.fitko.fitconnect.api.domain.model.metadata.data; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; import de.fitko.fitconnect.api.domain.model.metadata.EidasAdesProfile; import de.fitko.fitconnect.api.domain.model.metadata.SignatureFormat; import lombok.Data; -import lombok.Getter; -import lombok.Setter; import java.util.Map; diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/data/SubmissionSchema.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/data/SubmissionSchema.java index 42dff9ea9..05f859754 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/data/SubmissionSchema.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/data/SubmissionSchema.java @@ -3,11 +3,8 @@ package de.fitko.fitconnect.api.domain.model.metadata.data; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.Data; -import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import java.net.URI; import java.util.Map; diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/Callback.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/Callback.java index 4ba759951..392aa49d5 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/Callback.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/Callback.java @@ -2,9 +2,6 @@ package de.fitko.fitconnect.api.domain.model.submission; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; -import lombok.Getter; -import lombok.Setter; -import lombok.Value; import java.net.URI; diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/Submission.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/Submission.java index a82d214b2..39a47f9aa 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/Submission.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/Submission.java @@ -2,9 +2,7 @@ package de.fitko.fitconnect.api.domain.model.submission; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; -import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import java.util.List; import java.util.UUID; diff --git a/client/src/main/java/de/fitko/fitconnect/client/SenderClient.java b/client/src/main/java/de/fitko/fitconnect/client/SenderClient.java index 897d70293..0092c2867 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/SenderClient.java +++ b/client/src/main/java/de/fitko/fitconnect/client/SenderClient.java @@ -347,18 +347,18 @@ public class SenderClient { } private ServiceType createServiceTypeWithDescription(final String name, final String description, final String leikaKey) { - final var serviceType = new ServiceType(); - serviceType.setName(name); - serviceType.setDescription(description); - serviceType.setIdentifier(leikaKey); - return serviceType; + final var serviceTypeModel = new ServiceType(); + serviceTypeModel.setName(name); + serviceTypeModel.setDescription(description); + serviceTypeModel.setIdentifier(leikaKey); + return serviceTypeModel; } private ServiceType createServiceTypeWithoutDescription(final String name, final String leikaKey) { - final var serviceType = new ServiceType(); - serviceType.setName(name); - serviceType.setIdentifier(leikaKey); - return serviceType; + final var serviceTypeModel = new ServiceType(); + serviceTypeModel.setName(name); + serviceTypeModel.setIdentifier(leikaKey); + return serviceTypeModel; } private Data createData(final DataPayload dataPayload) { diff --git a/client/src/main/java/de/fitko/fitconnect/client/SubscriberClient.java b/client/src/main/java/de/fitko/fitconnect/client/SubscriberClient.java index bcb18bea0..03d92ba42 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/SubscriberClient.java +++ b/client/src/main/java/de/fitko/fitconnect/client/SubscriberClient.java @@ -155,7 +155,7 @@ public class SubscriberClient { } catch (final DecryptionException e) { logger.error("Decrypting payload failed", e); } catch (final RestApiException e) { - logger.error("API request failed", submissionId, e); + logger.error("API request failed", e); } catch (final EventCreationException e) { logger.error("Creating SET event failed", e); } catch (final InvalidSigningKeyException e) { diff --git a/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineClient.java b/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineClient.java index 4b6c55d7c..aa8e36af5 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineClient.java +++ b/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineClient.java @@ -85,7 +85,7 @@ public class CommandLineClient { jc.parse(args); return jc.getParsedCommand(); } catch (final ParameterException e) { - logger.error(e.getMessage() + "\n"); + logger.error(e.getMessage(), "\n"); jc.usage(); return null; } @@ -131,12 +131,11 @@ public class CommandLineClient { private void writeData(final SubscriberClient.ReceivedSubmission submissionData, final String dataDirPath) throws IOException { logger.info("Creating data directory for submission in {}", dataDirPath); Files.createDirectories(Path.of(dataDirPath)); - final String data = submissionData.getData(); final var fileEnding = AttachmentDataType.getFileTypeFromMimeType(submissionData.getMimeType()); final var filePath = Path.of(dataDirPath + "/data." + fileEnding); logger.info("Writing data.{}", fileEnding); - Files.write(filePath, data.getBytes(StandardCharsets.UTF_8)); + Files.write(filePath, submissionData.getData().getBytes(StandardCharsets.UTF_8)); for (final AttachmentWithData attachment : submissionData.getAttachments()) { final String filename = attachment.getAttachmentMetadata().getFilename(); diff --git a/client/src/main/java/de/fitko/fitconnect/client/factory/ApplicationConfigLoader.java b/client/src/main/java/de/fitko/fitconnect/client/factory/ApplicationConfigLoader.java index ab336b5da..ce7b0f3f6 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/factory/ApplicationConfigLoader.java +++ b/client/src/main/java/de/fitko/fitconnect/client/factory/ApplicationConfigLoader.java @@ -4,14 +4,14 @@ import de.fitko.fitconnect.api.config.ApplicationConfig; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; public class ApplicationConfigLoader { + private ApplicationConfigLoader(){} + /** * Load ApplicationConfig from path. * diff --git a/client/src/test/java/de/fitko/fitconnect/client/ClientIntegrationTest.java b/client/src/test/java/de/fitko/fitconnect/client/ClientIntegrationTest.java index 3b12e19c3..bc9c7cca8 100644 --- a/client/src/test/java/de/fitko/fitconnect/client/ClientIntegrationTest.java +++ b/client/src/test/java/de/fitko/fitconnect/client/ClientIntegrationTest.java @@ -19,14 +19,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** * This test uses real credentials and endpoints stored in gitlab ci variables to test the sdk against a real system */ -public class ClientIntegrationTest { +class ClientIntegrationTest { final String authBaseUrl = "https://auth-testing.fit-connect.fitko.dev"; final String submissionBaseUrl = "https://submission-api-testing.fit-connect.fitko.dev"; @Test @EnabledIfEnvironmentVariable(named = "TEST_DESTINATION_ID", matches = ".*") - public void testSendAndConfirmCycle() { + void testSendAndConfirmCycle() { // Given final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true); @@ -55,7 +55,7 @@ public class ClientIntegrationTest { @Test @EnabledIfEnvironmentVariable(named = "TEST_DESTINATION_ID", matches = ".*") - public void testListSubmissions() { + void testListSubmissions() { // Given final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true); @@ -100,7 +100,7 @@ public class ClientIntegrationTest { @Test @EnabledIfEnvironmentVariable(named = "TEST_DESTINATION_ID", matches = ".*") - public void testAbortedSendSubmissionWithKeyValidationNotSilent() { + void testAbortedSendSubmissionWithKeyValidationNotSilent() { // Given final var prodEnv = new Environment(authBaseUrl, submissionBaseUrl, false); diff --git a/client/src/test/java/de/fitko/fitconnect/client/SenderClientTest.java b/client/src/test/java/de/fitko/fitconnect/client/SenderClientTest.java index c203eee55..f2937f047 100644 --- a/client/src/test/java/de/fitko/fitconnect/client/SenderClientTest.java +++ b/client/src/test/java/de/fitko/fitconnect/client/SenderClientTest.java @@ -33,19 +33,17 @@ public class SenderClientTest { private Sender senderMock; private SenderClient.WithDestination underTest; - private Environment environmentMock; private final LogCaptor logs = new LogCaptor(); @BeforeEach public void setup() { - senderMock = mock(Sender.class); - environmentMock = mock(Environment.class); - underTest = SenderClient.build(senderMock, "", environmentMock); + this.senderMock = mock(Sender.class); + this.underTest = SenderClient.build(senderMock, "", mock(Environment.class)); } @Test - public void testSendSubmissionWithJsonData() throws Exception { + void testSendSubmissionWithJsonData() throws Exception { // Given @@ -80,7 +78,7 @@ public class SenderClientTest { } @Test - public void testSendSubmissionWithXmlData() throws Exception { + void testSendSubmissionWithXmlData() throws Exception { // Given @@ -114,7 +112,7 @@ public class SenderClientTest { } @Test - public void testMimeTypeDetection() throws Exception { + void testMimeTypeDetection() throws Exception { // Given final UUID destinationId = setupTestMocks(); @@ -137,7 +135,7 @@ public class SenderClientTest { @Test - public void testWithMissingData() throws Exception { + void testWithMissingData() throws Exception { // Given final UUID destinationId = setupTestMocks(); @@ -155,7 +153,7 @@ public class SenderClientTest { } @Test - public void testWithMissingDestinationId() throws Exception { + void testWithMissingDestinationId() throws Exception { // Given setupTestMocks(); @@ -173,7 +171,7 @@ public class SenderClientTest { } @Test - public void testMissingDataMimeTypeSchema() throws Exception { + void testMissingDataMimeTypeSchema() throws Exception { // Given final var destinationId = UUID.randomUUID(); @@ -201,7 +199,7 @@ public class SenderClientTest { } @Test - public void testWithMissingServiceTypeName() throws Exception { + void testWithMissingServiceTypeName() throws Exception { // Given final var destinationId = setupTestMocks(); @@ -219,7 +217,7 @@ public class SenderClientTest { } @Test - public void testWithOptionalServiceTypeIdentifier() throws Exception { + void testWithOptionalServiceTypeIdentifier() throws Exception { // Given final var destinationId = setupTestMocks(); @@ -237,7 +235,7 @@ public class SenderClientTest { } @Test - public void testWithMissingServiceTypeDescription() throws Exception { + void testWithMissingServiceTypeDescription() throws Exception { // Given final var destinationId = setupTestMocks(); @@ -254,7 +252,7 @@ public class SenderClientTest { } @Test - public void testWithEmptyAttachments() throws Exception { + void testWithEmptyAttachments() throws Exception { // Given final UUID destinationId = setupTestMocks(); @@ -273,7 +271,7 @@ public class SenderClientTest { } @Test - public void testWithAttachmentFileNull() throws Exception { + void testWithAttachmentFileNull() throws Exception { // Given final UUID destinationId = setupTestMocks(); @@ -292,7 +290,7 @@ public class SenderClientTest { } @Test - public void testWithAttachmentPathNotPresent() throws Exception { + void testWithAttachmentPathNotPresent() throws Exception { // Given final UUID destinationId = setupTestMocks(); @@ -311,7 +309,7 @@ public class SenderClientTest { } @Test - public void testInvalidPublicKey() throws Exception { + void testInvalidPublicKey() throws Exception { // Given final var destinationId = setupTestMocks(); @@ -330,7 +328,7 @@ public class SenderClientTest { } @Test - public void testEncryptionError() throws Exception { + void testEncryptionError() throws Exception { // Given final var destinationId = setupTestMocks(); @@ -349,7 +347,7 @@ public class SenderClientTest { } @Test - public void testAnnouncingSubmissionFailed() throws Exception { + void testAnnouncingSubmissionFailed() throws Exception { // Given final var destinationId = setupTestMocks(); @@ -369,7 +367,7 @@ public class SenderClientTest { } @Test - public void testRestApiCallFailed() throws Exception { + void testRestApiCallFailed() throws Exception { // Given final var destinationId = setupTestMocks(); @@ -388,7 +386,7 @@ public class SenderClientTest { } @Test - public void testGettingEncryptionKeyFailed() throws Exception { + void testGettingEncryptionKeyFailed() throws Exception { // Given final var destinationId = setupTestMocks(); @@ -406,7 +404,7 @@ public class SenderClientTest { } @Test - public void testFailOnInvalidMetadata() throws Exception { + void testFailOnInvalidMetadata() throws Exception { // Given final var destinationId = setupTestMocks(); diff --git a/client/src/test/java/de/fitko/fitconnect/client/SubscriberClientTest.java b/client/src/test/java/de/fitko/fitconnect/client/SubscriberClientTest.java index 8469c78a8..1be408880 100644 --- a/client/src/test/java/de/fitko/fitconnect/client/SubscriberClientTest.java +++ b/client/src/test/java/de/fitko/fitconnect/client/SubscriberClientTest.java @@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -public class SubscriberClientTest { +class SubscriberClientTest { public static final ObjectMapper mapper = new ObjectMapper(); @@ -53,13 +53,13 @@ public class SubscriberClientTest { } @Test - public void testMissingPrivateKey() { + void testMissingPrivateKey() { assertNull(SubscriberClient.builder(subscriberMock, null, "")); logs.assertContains("No decryption key set, please check environment"); } @Test - public void testPrivateKeyNotParseable() { + void testPrivateKeyNotParseable() { // Given final var client = SubscriberClient.builder(subscriberMock, "broken key", ""); @@ -73,13 +73,13 @@ public class SubscriberClientTest { } @Test - public void testMissingMetadataSchema() { + void testMissingMetadataSchema() { assertNull(SubscriberClient.builder(subscriberMock, privateKey, null)); logs.assertContains("No metadata schema present, please check environment"); } @Test - public void testNoSubmissionsFound() { + void testNoSubmissionsFound() { assertThat(underTest.getAvailableSubmissions(null).isEmpty(), is(true)); assertThat(underTest.getAvailableSubmissions(UUID.randomUUID()).isEmpty(), is(true)); @@ -89,7 +89,7 @@ public class SubscriberClientTest { } @Test - public void testRestCallFailed() { + void testRestCallFailed() { // Given when(subscriberMock.getSubmission(any())).thenThrow(new RestApiException("Submission not found")); @@ -102,7 +102,7 @@ public class SubscriberClientTest { } @Test - public void testDecryptionFailed() { + void testDecryptionFailed() { // Given final var submissionId = UUID.randomUUID(); final var submission = new Submission(); @@ -122,7 +122,7 @@ public class SubscriberClientTest { } @Test - public void testCreatingSetEventFailed() throws JsonProcessingException { + void testCreatingSetEventFailed() throws JsonProcessingException { // Given final var submissionId = UUID.randomUUID(); @@ -148,7 +148,7 @@ public class SubscriberClientTest { } @Test - public void testSigningKeyInvalid() throws JsonProcessingException { + void testSigningKeyInvalid() throws JsonProcessingException { // Given final var submissionId = UUID.randomUUID(); @@ -176,7 +176,7 @@ public class SubscriberClientTest { @Test - public void testReadingMetadataFailed() { + void testReadingMetadataFailed() { // Given final var submissionId = UUID.randomUUID(); final var submission = new Submission(); @@ -197,7 +197,7 @@ public class SubscriberClientTest { @Test - public void testSubmissionsFound() { + void testSubmissionsFound() { // Given final var destinationId = UUID.randomUUID(); @@ -216,7 +216,7 @@ public class SubscriberClientTest { } @Test - public void testGetSubmission() throws Exception { + void testGetSubmission() throws Exception { // Given final var dataPayload = "{ some : 'data foo' }"; @@ -272,7 +272,7 @@ public class SubscriberClientTest { } @Test - public void testSubmissionNotFound() { + void testSubmissionNotFound() { // Given when(subscriberMock.getSubmission(any())).thenReturn(null); @@ -284,7 +284,7 @@ public class SubscriberClientTest { } @Test - public void testInvalidMetadata() throws JsonProcessingException { + void testInvalidMetadata() throws JsonProcessingException { // Given final var submissionId = UUID.randomUUID(); final var destinationId = UUID.randomUUID(); @@ -311,7 +311,7 @@ public class SubscriberClientTest { } @Test - public void testCorruptedData() throws JsonProcessingException, ParseException { + void testCorruptedData() throws JsonProcessingException, ParseException { // Given final RSAKey decryptionKey = RSAKey.parse(privateKey); final RSAKey encryptionKey = decryptionKey.toPublicJWK(); @@ -360,7 +360,7 @@ public class SubscriberClientTest { } @Test - public void testCorruptedAttachment() throws JsonProcessingException, ParseException { + void testCorruptedAttachment() throws JsonProcessingException, ParseException { // Given final RSAKey decryptionKey = RSAKey.parse(privateKey); final RSAKey encryptionKey = decryptionKey.toPublicJWK(); diff --git a/client/src/test/java/de/fitko/fitconnect/client/factory/ClientFactoryTest.java b/client/src/test/java/de/fitko/fitconnect/client/factory/ClientFactoryTest.java index c1be40f03..3e611a621 100644 --- a/client/src/test/java/de/fitko/fitconnect/client/factory/ClientFactoryTest.java +++ b/client/src/test/java/de/fitko/fitconnect/client/factory/ClientFactoryTest.java @@ -8,16 +8,16 @@ import java.util.Map; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -public class ClientFactoryTest { +class ClientFactoryTest { @Test - public void testMissingConfiguration() { + void testMissingConfiguration() { assertThrows(IllegalStateException.class, () -> ClientFactory.senderClient()); assertThrows(IllegalStateException.class, () -> ClientFactory.subscriberClient()); } @Test - public void testSenderClientConstruction() { + void testSenderClientConstruction() { final var envName = new EnvironmentName("DEV"); final var environments = Map.of(envName, new Environment("https://auth", "", true)); @@ -42,7 +42,7 @@ public class ClientFactoryTest { } @Test - public void testSubscriberClientConstruction() { + void testSubscriberClientConstruction() { final var envName = new EnvironmentName("DEV"); final var environments = Map.of(envName, new Environment("https://auth", "", true)); diff --git a/core/src/main/java/de/fitko/fitconnect/core/auth/DefaultOAuthService.java b/core/src/main/java/de/fitko/fitconnect/core/auth/DefaultOAuthService.java index 0d3ac1949..08da79e45 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/auth/DefaultOAuthService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/auth/DefaultOAuthService.java @@ -72,15 +72,14 @@ public class DefaultOAuthService implements OAuthService { checkNotNull("tokenUrl", tokenUrl); final String requestBody = buildRequestBody(clientId, clientSecret); this.currentToken = performTokenRequest(requestBody); - this.tokenExpirationTime = LocalDateTime.now().plusSeconds(currentToken.getExpiresIn()); + this.tokenExpirationTime = LocalDateTime.now().plusSeconds(this.currentToken.getExpiresIn()); } private String buildRequestBody(final String clientId, final String clientSecret, final String... scope) { - final var data = new HashMap<String, String>() {{ - put("grant_type", "client_credentials"); - put("client_id", clientId); - put("client_secret", clientSecret); - }}; + final var data = new HashMap<String, String>(); + data.put("grant_type", "client_credentials"); + data.put("client_id", clientId); + data.put("client_secret", clientSecret); if (scope.length > 0) { data.put("scope", String.join(",", scope)); diff --git a/core/src/main/java/de/fitko/fitconnect/core/crypto/HashService.java b/core/src/main/java/de/fitko/fitconnect/core/crypto/HashService.java index 1cc1781d4..d8158b9fa 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/crypto/HashService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/crypto/HashService.java @@ -38,7 +38,7 @@ public class HashService implements MessageDigestService { @Override public String toHexString(final byte[] hash) { - final StringBuffer hexStringBuffer = new StringBuffer(); + final StringBuilder hexStringBuffer = new StringBuilder(); for (int i = 0; i < hash.length; i++) { hexStringBuffer.append(byteToHex(hash[i])); } diff --git a/core/src/main/java/de/fitko/fitconnect/core/events/SecurityEventTokenService.java b/core/src/main/java/de/fitko/fitconnect/core/events/SecurityEventTokenService.java index 052f982bc..e4264cf1d 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/events/SecurityEventTokenService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/events/SecurityEventTokenService.java @@ -6,7 +6,6 @@ import com.nimbusds.jose.JWSHeader; import com.nimbusds.jose.JWSSigner; import com.nimbusds.jose.crypto.RSASSASigner; import com.nimbusds.jose.jwk.JWK; -import com.nimbusds.jose.jwk.KeyOperation; import com.nimbusds.jose.jwk.RSAKey; import com.nimbusds.jwt.JWTClaimsSet; import com.nimbusds.jwt.SignedJWT; @@ -112,11 +111,11 @@ public class SecurityEventTokenService implements SecurityEventService { } } - public static void validateRSAKey(final RSAKey RSAKey){ - validateTrueOrElseThrow(RSAKey.getModulus().decodeToBigInteger().bitLength() >= 4096, "JWK has wrong key length."); - validateTrueOrElseThrow(RSAKey.getAlgorithm().equals(JWSAlgorithm.PS512), "The specified public key does not use PS512 as algorithm."); + public static void validateRSAKey(final RSAKey rsaKey){ + validateTrueOrElseThrow(rsaKey.getModulus().decodeToBigInteger().bitLength() >= 4096, "JWK has wrong key length."); + validateTrueOrElseThrow(rsaKey.getAlgorithm().equals(JWSAlgorithm.PS512), "The specified public key does not use PS512 as algorithm."); //validateTrueOrElseThrow(RSAKey.getKeyOperations().size() == 1 && RSAKey.getKeyOperations().contains(KeyOperation.VERIFY), "The specified public key is not intended for 'verify' as specified through key operation."); - validateTrueOrElseThrow(RSAKey.getPublicExponent().toString().equals("AQAB"), "The specified public key does not match the public exponent 'AQAB'."); + validateTrueOrElseThrow(rsaKey.getPublicExponent().toString().equals("AQAB"), "The specified public key does not match the public exponent 'AQAB'."); } diff --git a/core/src/main/java/de/fitko/fitconnect/core/util/Preconditions.java b/core/src/main/java/de/fitko/fitconnect/core/util/Preconditions.java index d809bc436..ea9677126 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/util/Preconditions.java +++ b/core/src/main/java/de/fitko/fitconnect/core/util/Preconditions.java @@ -4,14 +4,15 @@ import java.util.function.Supplier; public class Preconditions { + private Preconditions() {} + /** * Throws a supplied (runtime) exception if the expression evaluates to false * - * @param argumentName name of the argument to check * @param expression expression to evaluate * @param exceptionSupplier supplier for the exception */ - public static void checkArgument(final String argumentName, final boolean expression, final Supplier<? extends RuntimeException> exceptionSupplier) { + public static void checkArgument(final boolean expression, final Supplier<? extends RuntimeException> exceptionSupplier) { if (!expression) { throw exceptionSupplier.get(); } @@ -23,7 +24,7 @@ public class Preconditions { * @param expression expression to evaluate */ public static void checkArgument(final String argumentName, final boolean expression) { - checkArgument(argumentName, expression, () -> new IllegalStateException("Parameter " + argumentName + " must not be null")); + checkArgument(expression, () -> new IllegalStateException("Parameter " + argumentName + " must not be null")); } /** @@ -33,6 +34,6 @@ public class Preconditions { * @param argument argument to check */ public static void checkNotNull(final String argumentName, final Object argument) { - checkArgument(argumentName, argument != null, () -> new IllegalStateException("Parameter " + argumentName + " must not be null")); + checkArgument(argument != null, () -> new IllegalStateException("Parameter " + argumentName + " must not be null")); } } diff --git a/core/src/main/java/de/fitko/fitconnect/core/util/Strings.java b/core/src/main/java/de/fitko/fitconnect/core/util/Strings.java index 22fce6c7c..4dd79e641 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/util/Strings.java +++ b/core/src/main/java/de/fitko/fitconnect/core/util/Strings.java @@ -2,6 +2,8 @@ package de.fitko.fitconnect.core.util; public class Strings { + private Strings() {} + /** * Tests a given string on null or empty * @param s string to test diff --git a/core/src/test/java/de/fitko/fitconnect/core/SubmissionSenderTestConfig.java b/core/src/test/java/de/fitko/fitconnect/core/SubmissionSenderTest.java similarity index 90% rename from core/src/test/java/de/fitko/fitconnect/core/SubmissionSenderTestConfig.java rename to core/src/test/java/de/fitko/fitconnect/core/SubmissionSenderTest.java index 4af26b5ae..325d36871 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/SubmissionSenderTestConfig.java +++ b/core/src/test/java/de/fitko/fitconnect/core/SubmissionSenderTest.java @@ -7,11 +7,7 @@ import com.nimbusds.jose.jwk.RSAKey; import com.nimbusds.jose.jwk.gen.RSAKeyGenerator; import de.fitko.fitconnect.api.domain.model.destination.Destination; import de.fitko.fitconnect.api.domain.model.jwk.JWK; -import de.fitko.fitconnect.api.domain.model.metadata.ContentStructure; import de.fitko.fitconnect.api.domain.model.metadata.Metadata; -import de.fitko.fitconnect.api.domain.model.metadata.PublicServiceType; -import de.fitko.fitconnect.api.domain.model.metadata.attachment.Attachment; -import de.fitko.fitconnect.api.domain.model.metadata.data.*; import de.fitko.fitconnect.api.domain.model.submission.*; import de.fitko.fitconnect.api.domain.validation.ValidationResult; import de.fitko.fitconnect.api.exceptions.*; @@ -26,10 +22,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.net.URI; import java.text.ParseException; import java.util.Collections; -import java.util.List; import java.util.UUID; import static org.hamcrest.MatcherAssert.assertThat; @@ -39,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -public class SubmissionSenderTestConfig { +class SubmissionSenderTest { private DestinationService destinationServiceMock; private SubmissionService submissionServiceMock; @@ -70,7 +64,7 @@ public class SubmissionSenderTestConfig { } @Test - public void validatePublicKey() throws JOSEException { + void validatePublicKey() throws JOSEException { //Given final RSAKey publicKey = new RSAKeyGenerator(2048) @@ -89,7 +83,7 @@ public class SubmissionSenderTestConfig { } @Test - public void encryptBytes() throws JOSEException { + void encryptBytes() throws JOSEException { //Given final RSAKey publicKey = new RSAKeyGenerator(2048) @@ -109,7 +103,7 @@ public class SubmissionSenderTestConfig { } @Test - public void createHash() { + void createHash() { // Given when(cryptoServiceMock.hashBytes(any())).thenReturn("hashedData"); @@ -123,7 +117,7 @@ public class SubmissionSenderTestConfig { } @Test - public void createSubmission() { + void createSubmission() { // Given final var createSubmission = CreateSubmission.builder() @@ -148,7 +142,7 @@ public class SubmissionSenderTestConfig { } @Test - public void uploadAttachment() { + void uploadAttachment() { // Given final var submissionId = UUID.randomUUID(); @@ -165,7 +159,7 @@ public class SubmissionSenderTestConfig { } @Test - public void getEncryptionKeyForDestination() throws ParseException, IOException { + void getEncryptionKeyForDestination() throws ParseException, IOException { // Given final var submissionId = UUID.randomUUID(); @@ -184,7 +178,7 @@ public class SubmissionSenderTestConfig { } @Test - public void getEncryptionKeyForDestinationFailed() { + void getEncryptionKeyForDestinationFailed() { // Given when(destinationServiceMock.getEncryptionKey(any(), any())).thenThrow(RestApiException.class); @@ -199,7 +193,7 @@ public class SubmissionSenderTestConfig { @Test - public void encryptObject() throws JOSEException { + void encryptObject() throws JOSEException { //Given final RSAKey publicKey = new RSAKeyGenerator(2048) @@ -220,7 +214,7 @@ public class SubmissionSenderTestConfig { } @Test - public void encryptingObjectFailed() throws JOSEException { + void encryptingObjectFailed() throws JOSEException { //Given final RSAKey publicKey = new RSAKeyGenerator(2048) @@ -241,7 +235,7 @@ public class SubmissionSenderTestConfig { } @Test - public void sendSubmission() { + void sendSubmission() { // Given final SubmitSubmission submitSubmission = new SubmitSubmission(); @@ -264,7 +258,7 @@ public class SubmissionSenderTestConfig { } @Test - public void getDestination() { + void getDestination() { // Given final var destinationId = UUID.randomUUID(); @@ -282,7 +276,7 @@ public class SubmissionSenderTestConfig { } @Test - public void testValidMetadata() { + void testValidMetadata() { // Given final var metadata = new Metadata(); @@ -297,7 +291,7 @@ public class SubmissionSenderTestConfig { } @Test - public void testInvalidMetadata() { + void testInvalidMetadata() { // Given final var invalidMetadata = new Metadata(); @@ -313,6 +307,6 @@ public class SubmissionSenderTestConfig { } private String getResourceAsString(final String filename) throws IOException { - return new String(SubmissionSenderTestConfig.class.getResourceAsStream(filename).readAllBytes()); + return new String(SubmissionSenderTest.class.getResourceAsStream(filename).readAllBytes()); } } \ No newline at end of file diff --git a/core/src/test/java/de/fitko/fitconnect/core/SubmissionSubscriberTest.java b/core/src/test/java/de/fitko/fitconnect/core/SubmissionSubscriberTest.java index c91a6ae26..82ea0cd30 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/SubmissionSubscriberTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/SubmissionSubscriberTest.java @@ -32,7 +32,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.*; -public class SubmissionSubscriberTest { +class SubmissionSubscriberTest { private SubmissionService submissionServiceMock; private EventLogService eventLogServiceMock; @@ -61,7 +61,7 @@ public class SubmissionSubscriberTest { } @Test - public void decryptStringContent() throws JOSEException { + void decryptStringContent() throws JOSEException { // Given final RSAKey privateKey = new RSAKeyGenerator(2048) @@ -81,7 +81,7 @@ public class SubmissionSubscriberTest { } @Test - public void pollAvailableSubmissions() { + void pollAvailableSubmissions() { // Given final var destinationId = UUID.randomUUID(); @@ -101,7 +101,7 @@ public class SubmissionSubscriberTest { } @Test - public void getSubmission() { + void getSubmission() { // Given final var submissionId = UUID.randomUUID(); @@ -120,7 +120,7 @@ public class SubmissionSubscriberTest { } @Test - public void submissionNotFound() { + void submissionNotFound() { // Given when(submissionServiceMock.getSubmission(any())).thenThrow(RestApiException.class); @@ -134,7 +134,7 @@ public class SubmissionSubscriberTest { } @Test - public void fetchAttachment() { + void fetchAttachment() { // Given final var submissionId = UUID.randomUUID(); @@ -150,13 +150,8 @@ public class SubmissionSubscriberTest { assertThat(encryptedAttachment, equalTo(expectedAttachment)); } - @Disabled("Needs proper impl first") - void validateEventLog() { - - } - @Test - public void validateMetadata() { + void validateMetadata() { // Given when(validationServiceMock.validateMetadataSchema(any(), any())).thenReturn(ValidationResult.ok()); @@ -169,7 +164,7 @@ public class SubmissionSubscriberTest { } @Test - public void invalidMetadata() { + void invalidMetadata() { // Given when(validationServiceMock.validateMetadataSchema(any(), any())).thenReturn(ValidationResult.error(new Exception("Failed parsing metadata"))); @@ -183,7 +178,7 @@ public class SubmissionSubscriberTest { } @Test - public void validateHashIntegrity() { + void validateHashIntegrity() { when(validationServiceMock.validateIntegrity(any(),any())).thenReturn(ValidationResult.ok()); @@ -195,7 +190,7 @@ public class SubmissionSubscriberTest { } @Test - public void validateCorruptHash() { + void validateCorruptHash() { // Given when(validationServiceMock.validateIntegrity(any(),any())).thenReturn(ValidationResult.error( @@ -210,7 +205,7 @@ public class SubmissionSubscriberTest { } @Test - public void confirmValidSubmission() { + void confirmValidSubmission() { // Given final var submissionId = UUID.randomUUID(); @@ -229,7 +224,7 @@ public class SubmissionSubscriberTest { } @Test - public void rejectSubmission() { + void rejectSubmission() { // Given final var submissionId = UUID.randomUUID(); diff --git a/core/src/test/java/de/fitko/fitconnect/core/auth/DefaultOAuthServiceTest.java b/core/src/test/java/de/fitko/fitconnect/core/auth/DefaultOAuthServiceTest.java index d03efddf8..c2762e957 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/auth/DefaultOAuthServiceTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/auth/DefaultOAuthServiceTest.java @@ -15,7 +15,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertThrows; -public class DefaultOAuthServiceTest extends RestEndpointBase { +class DefaultOAuthServiceTest extends RestEndpointBase { private OAuthService underTest; @@ -27,7 +27,7 @@ public class DefaultOAuthServiceTest extends RestEndpointBase { } @Test - public void serviceNotInitialized() { + void serviceNotInitialized() { // Given final OAuthService instance = new DefaultOAuthService(null, null, null, null); @@ -40,7 +40,7 @@ public class DefaultOAuthServiceTest extends RestEndpointBase { } @Test - public void getCurrentToken() throws JsonProcessingException { + void getCurrentToken() throws JsonProcessingException { // Given final OAuthToken token= new OAuthToken(); token.setAccessToken("123"); @@ -57,7 +57,7 @@ public class DefaultOAuthServiceTest extends RestEndpointBase { } @Test - public void refreshTokenWhenExpired() throws JsonProcessingException { + void refreshTokenWhenExpired() throws JsonProcessingException { // Given final OAuthToken oldToken = new OAuthToken(); oldToken.setAccessToken("123"); diff --git a/core/src/test/java/de/fitko/fitconnect/core/auth/OAuthTokenIntegrationTest.java b/core/src/test/java/de/fitko/fitconnect/core/auth/OAuthTokenIntegrationTest.java index ac888e38b..5a165a999 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/auth/OAuthTokenIntegrationTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/auth/OAuthTokenIntegrationTest.java @@ -6,10 +6,10 @@ import org.springframework.web.client.RestTemplate; import static org.junit.jupiter.api.Assertions.*; -public class OAuthTokenIntegrationTest { +class OAuthTokenIntegrationTest { @Test - public void retrieveAuthenticationToken() { + void retrieveAuthenticationToken() { // Given final var tokenUrl = "https://auth-testing.fit-connect.fitko.dev/token"; diff --git a/core/src/test/java/de/fitko/fitconnect/core/crypto/HashServiceTest.java b/core/src/test/java/de/fitko/fitconnect/core/crypto/HashServiceTest.java index d0a4b1f05..4b4074956 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/crypto/HashServiceTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/crypto/HashServiceTest.java @@ -14,7 +14,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class HashServiceTest { +class HashServiceTest { private MessageDigestService underTest; @@ -25,7 +25,7 @@ public class HashServiceTest { } @Test - public void createHash() throws IOException { + void createHash() throws IOException { // Given final byte[] expectedHash = {-13, -77, -85, 62, 99, 81, -30, 91, 92, 24, -126, -66, -88, -45, 126, -6, -35, @@ -43,7 +43,7 @@ public class HashServiceTest { } @Test - public void verify() throws IOException { + void verify() throws IOException { // Given final byte[] expectedHash = {-13, -77, -85, 62, 99, 81, -30, 91, 92, 24, -126, -66, -88, -45, 126, -6, -35, -64, -22, 114, -65, 21, 59, -80, 103, 104, -113, 119, 90, 38, -127, 13, 50, -75, 79, 1, 75, -15, -50, @@ -60,7 +60,7 @@ public class HashServiceTest { } @Test - public void toHexString() { + void toHexString() { // Given final byte[] data = "some data".getBytes(StandardCharsets.UTF_8); final var expectedHexString = "736f6d652064617461"; @@ -73,7 +73,7 @@ public class HashServiceTest { } @Test - public void fromHexString() { + void fromHexString() { // Given final var hexString = "736f6d652064617461"; diff --git a/core/src/test/java/de/fitko/fitconnect/core/destination/DestinationRestServiceTest.java b/core/src/test/java/de/fitko/fitconnect/core/destination/DestinationRestServiceTest.java index 4a76c517e..a273da99a 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/destination/DestinationRestServiceTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/destination/DestinationRestServiceTest.java @@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class DestinationRestServiceTest extends RestEndpointBase { +class DestinationRestServiceTest extends RestEndpointBase { DestinationService underTest; OAuthService authServiceMock; @@ -34,7 +34,7 @@ public class DestinationRestServiceTest extends RestEndpointBase { } @Test - public void getDestination() throws JsonProcessingException { + void getDestination() throws JsonProcessingException { //Given final Destination expectedDestination = new Destination(); @@ -57,7 +57,7 @@ public class DestinationRestServiceTest extends RestEndpointBase { } @Test - public void getEncryptionKey() throws Exception { + void getEncryptionKey() throws Exception { // Given final UUID destinationId = UUID.randomUUID(); final JWK jwk = new JWK(); diff --git a/core/src/test/java/de/fitko/fitconnect/core/events/EventLogApiServiceTest.java b/core/src/test/java/de/fitko/fitconnect/core/events/EventLogApiServiceTest.java index 039e1f214..f78967a06 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/events/EventLogApiServiceTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/events/EventLogApiServiceTest.java @@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; -public class EventLogApiServiceTest extends RestEndpointBase { +class EventLogApiServiceTest extends RestEndpointBase { EventLogService underTest; OAuthService authServiceMock; @@ -37,7 +37,7 @@ public class EventLogApiServiceTest extends RestEndpointBase { } @Test - public void getEventLog() throws JsonProcessingException { + void getEventLog() throws JsonProcessingException { // Given final var caseId = UUID.randomUUID(); @@ -54,7 +54,7 @@ public class EventLogApiServiceTest extends RestEndpointBase { " }"; final var expectedLog = new EventLog(); - expectedLog.setEventLog(List.of(sampleLog)); + expectedLog.setEventLogs(List.of(sampleLog)); final var authToken = new OAuthToken(); authToken.setAccessToken("abc"); @@ -74,7 +74,7 @@ public class EventLogApiServiceTest extends RestEndpointBase { final EventLog log = underTest.getEventLog(caseId); // Then - final List<String> eventLog = log.getEventLog(); + final List<String> eventLog = log.getEventLogs(); assertFalse(eventLog.isEmpty()); assertTrue(eventLog.stream().findFirst().isPresent()); assertThat(eventLog.stream().findFirst().get(), is(sampleLog)); @@ -82,7 +82,7 @@ public class EventLogApiServiceTest extends RestEndpointBase { } @Test - public void sendEvent() { + void sendEvent() { // Given final var caseId = UUID.randomUUID(); final var serialisedSetEvent = "eyJraWQiOiJkZDA0MDllNS00MTBlLTRkOTgtODViNi1mODFhNDBiO"; diff --git a/core/src/test/java/de/fitko/fitconnect/core/events/SecurityEventTokenServiceTest.java b/core/src/test/java/de/fitko/fitconnect/core/events/SecurityEventTokenServiceTest.java index 351882317..2b302cfd2 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/events/SecurityEventTokenServiceTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/events/SecurityEventTokenServiceTest.java @@ -23,7 +23,7 @@ import java.util.UUID; import static org.junit.jupiter.api.Assertions.*; -public class SecurityEventTokenServiceTest { +class SecurityEventTokenServiceTest { String signingKey; SecurityEventService underTest; @@ -37,7 +37,7 @@ public class SecurityEventTokenServiceTest { } @Test - public void createAcceptSubmissionEvent() throws ParseException, JOSEException { + void createAcceptSubmissionEvent() throws ParseException, JOSEException { final String event = underTest.createAcceptSubmissionEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()); @@ -49,13 +49,13 @@ public class SecurityEventTokenServiceTest { final Map<String,Object> obj = (Map<String, Object>) payload.getClaims().get("events"); final Optional<String> first = obj.keySet().stream().findFirst(); - assertEquals(jwk.getAlgorithm(), JWSAlgorithm.PS512); + assertEquals(JWSAlgorithm.PS512, jwk.getAlgorithm()); assertTrue(signedJWT.verify(jwsVerifier)); assertEquals(SecurityEventTokenService.ACCEPT_EVENT, first.get()); } @Test - public void createRejectSubmissionEvent() throws ParseException, JOSEException { + void createRejectSubmissionEvent() throws ParseException, JOSEException { // Given final String event = underTest.createRejectSubmissionEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()); @@ -68,7 +68,7 @@ public class SecurityEventTokenServiceTest { assertEquals("secevent+jwt", header.getType().getType()); assertEquals("PS512", header.getAlgorithm().getName()); assertEquals(jwk.getKeyID(), header.getKeyID()); - assertEquals(jwk.getAlgorithm(), JWSAlgorithm.PS512); + assertEquals(JWSAlgorithm.PS512, jwk.getAlgorithm()); final JWTClaimsSet payload = signedJWT.getJWTClaimsSet(); final Map<String,Object> obj = (Map<String, Object>) payload.getClaims().get("events"); @@ -80,7 +80,7 @@ public class SecurityEventTokenServiceTest { } @Test - public void signingKeyCannotBeParsed(){ + void signingKeyCannotBeParsed(){ assertThrows( InvalidSigningKeyException.class, () -> new SecurityEventTokenService("broken key"), diff --git a/core/src/test/java/de/fitko/fitconnect/core/http/ProxyConfigTest.java b/core/src/test/java/de/fitko/fitconnect/core/http/ProxyConfigTest.java index 1fb77d5da..aef00310e 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/http/ProxyConfigTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/http/ProxyConfigTest.java @@ -8,12 +8,12 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.*; -public class ProxyConfigTest { +class ProxyConfigTest { ProxyConfig underTest; @Test - public void proxyRestTemplate() { + void proxyRestTemplate() { // Given underTest = new ProxyConfig("http://testhost.de", 8080); @@ -27,7 +27,7 @@ public class ProxyConfigTest { } @Test - public void hasProxySet() { + void hasProxySet() { // Given underTest = new ProxyConfig("http://testhost.de", 8080); @@ -39,7 +39,7 @@ public class ProxyConfigTest { } @Test - public void hasProxyNotSet() { + void hasProxyNotSet() { // Given underTest = new ProxyConfig(null, 0); @@ -51,7 +51,7 @@ public class ProxyConfigTest { } @Test - public void testToString() { + void testToString() { // Given underTest = new ProxyConfig("http://testhost.de", 8080); diff --git a/core/src/test/java/de/fitko/fitconnect/core/submission/SubmissionApiServiceTest.java b/core/src/test/java/de/fitko/fitconnect/core/submission/SubmissionApiServiceTest.java index da627ed22..9f97fe41b 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/submission/SubmissionApiServiceTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/submission/SubmissionApiServiceTest.java @@ -25,11 +25,10 @@ import java.util.stream.Collectors; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; -public class SubmissionApiServiceTest extends RestEndpointBase { +class SubmissionApiServiceTest extends RestEndpointBase { private RestTemplate restTemplate; private OAuthService authServiceMock; @@ -47,7 +46,7 @@ public class SubmissionApiServiceTest extends RestEndpointBase { } @Test - public void announceSubmission() throws JsonProcessingException { + void announceSubmission() throws JsonProcessingException { // Given final var caseId = UUID.randomUUID(); final var destinationId = UUID.randomUUID(); @@ -92,7 +91,7 @@ public class SubmissionApiServiceTest extends RestEndpointBase { } @Test - public void uploadAttachment() { + void uploadAttachment() { // Given final var submissionId = UUID.randomUUID(); @@ -120,11 +119,11 @@ public class SubmissionApiServiceTest extends RestEndpointBase { // Then verify(putRequestedFor(urlEqualTo(urlPath)).withHeader("Authorization", equalTo("Bearer abc"))); assertThat(response.getHeaders().getContentTypeHeader().mimeTypePart(), is("application/jose")); - assertTrue(response.getStatus() == HttpStatus.NO_CONTENT.value()); + assertEquals(response.getStatus(), HttpStatus.NO_CONTENT.value()); } @Test - public void getAttachment() { + void getAttachment() { // Given final var submissionId = UUID.randomUUID(); @@ -153,11 +152,11 @@ public class SubmissionApiServiceTest extends RestEndpointBase { assertThat(attachment, is(encryptedAttachment)); verify(getRequestedFor(urlEqualTo(urlPath)).withHeader("Authorization", equalTo("Bearer abc"))); assertThat(response.getHeaders().getContentTypeHeader().mimeTypePart(), is("application/jose")); - assertTrue(response.getStatus() == HttpStatus.OK.value()); + assertEquals(response.getStatus(), HttpStatus.OK.value()); } @Test - public void sendSubmission() throws JsonProcessingException { + void sendSubmission() throws JsonProcessingException { // Given final var submissionId = UUID.randomUUID(); @@ -200,11 +199,11 @@ public class SubmissionApiServiceTest extends RestEndpointBase { verify(putRequestedFor(urlEqualTo(urlPath)).withHeader("Authorization", equalTo("Bearer abc"))); assertThat(response.getHeaders().getContentTypeHeader().mimeTypePart(), is("application/json")); - assertTrue(response.getStatus() == HttpStatus.OK.value()); + assertEquals(response.getStatus(), HttpStatus.OK.value()); } @Test - public void pollAvailableSubmissions() throws JsonProcessingException { + void pollAvailableSubmissions() throws JsonProcessingException { final int offset = 0; final int limit = 10; @@ -248,7 +247,7 @@ public class SubmissionApiServiceTest extends RestEndpointBase { } @Test - public void getSubmission() throws JsonProcessingException { + void getSubmission() throws JsonProcessingException { // Given final var submissionId = UUID.randomUUID(); diff --git a/core/src/test/java/de/fitko/fitconnect/core/util/StringsTest.java b/core/src/test/java/de/fitko/fitconnect/core/util/StringsTest.java index b73765ebe..adc4a413b 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/util/StringsTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/util/StringsTest.java @@ -4,10 +4,10 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -public class StringsTest { +class StringsTest { @Test - public void isEmpty() { + void isEmpty() { // Given final var emptyString = ""; @@ -20,7 +20,7 @@ public class StringsTest { } @Test - public void isNUll() { + void isNUll() { // Given final String nullString = null; diff --git a/core/src/test/java/de/fitko/fitconnect/core/validation/DefaultValidationServiceTest.java b/core/src/test/java/de/fitko/fitconnect/core/validation/DefaultValidationServiceTest.java index 81547def9..84158b25b 100644 --- a/core/src/test/java/de/fitko/fitconnect/core/validation/DefaultValidationServiceTest.java +++ b/core/src/test/java/de/fitko/fitconnect/core/validation/DefaultValidationServiceTest.java @@ -30,7 +30,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; -public class DefaultValidationServiceTest { +class DefaultValidationServiceTest { private ValidationService underTest; private MessageDigestService hashService; @@ -46,7 +46,7 @@ public class DefaultValidationServiceTest { } @Test - public void testValidKeyWithoutX509CertChain() throws JOSEException { + void testValidKeyWithoutX509CertChain() throws JOSEException { //Given final RSAKey rsaKey = new RSAKeyGenerator(4096) @@ -63,7 +63,7 @@ public class DefaultValidationServiceTest { } @Test - public void testInvalidKeyWithWrongAlgorithm() throws JOSEException { + void testInvalidKeyWithWrongAlgorithm() throws JOSEException { //Given final RSAKey rsaKey = new RSAKeyGenerator(4096) @@ -82,7 +82,7 @@ public class DefaultValidationServiceTest { } @Test - public void testValidationWithProxy() { + void testValidationWithProxy() { //Given final var config = ApplicationConfig.builder() @@ -103,7 +103,7 @@ public class DefaultValidationServiceTest { @Test - public void validateMetadata() throws IOException { + void validateMetadata() throws IOException { // Given final var submissionSchema = new SubmissionSchema(); @@ -135,7 +135,7 @@ public class DefaultValidationServiceTest { } @Test - public void validateMetadataWithMissingProperties() throws IOException { + void validateMetadataWithMissingProperties() throws IOException { // Given final var submissionSchema = new SubmissionSchema(); @@ -163,7 +163,7 @@ public class DefaultValidationServiceTest { } @Test - public void validateMetadataWithInvalidPattern() throws IOException { + void validateMetadataWithInvalidPattern() throws IOException { // Given final var submissionSchema = new SubmissionSchema(); @@ -196,7 +196,7 @@ public class DefaultValidationServiceTest { } @Test - public void validateMatchingHash() { + void validateMatchingHash() { // Given final var hexHashFromSender = hashService.toHexString(hashService.createHash("some data".getBytes())); @@ -209,7 +209,7 @@ public class DefaultValidationServiceTest { } @Test - public void validateCorruptHash() { + void validateCorruptHash() { // Given final var hexHashFromSender = "e1645e7492f032fb62c674db75500be7b260bfc0daa965821ddb3f8a49b5d33788ee3f04"; -- GitLab