diff --git a/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystem.java b/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystem.java index fcb622e64..6fecc7a10 100644 --- a/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystem.java +++ b/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystem.java @@ -18,12 +18,14 @@ import java.util.Objects; import jakarta.validation.constraints.NotNull; +import lombok.EqualsAndHashCode; import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact; import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; /** * {@link AbstractDbArtifact} implementation which dynamically creates a {@link FileInputStream} on calling {@link #getFileInputStream()}. */ +@EqualsAndHashCode(callSuper = true) public class ArtifactFilesystem extends AbstractDbArtifact { private final File file; diff --git a/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemTest.java b/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemTest.java index 02b68d9b8..e16bdec5e 100644 --- a/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemTest.java +++ b/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemTest.java @@ -49,6 +49,6 @@ class ArtifactFilesystemTest { final ArtifactFilesystem underTest = new ArtifactFilesystem( createTempFile, ArtifactFilesystemTest.class.getSimpleName(), new DbArtifactHash("1", "2", "3"), 0L, null); final byte[] buffer = new byte[1024]; - assertThat(IOUtils.read(underTest.getFileInputStream(), buffer)).isEqualTo(0); + assertThat(IOUtils.read(underTest.getFileInputStream(), buffer)).isZero(); } } \ No newline at end of file diff --git a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/AbstractDDiApiIntegrationTest.java b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/AbstractDDiApiIntegrationTest.java index 31042fe26..789cc8192 100644 --- a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/AbstractDDiApiIntegrationTest.java +++ b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/AbstractDDiApiIntegrationTest.java @@ -20,7 +20,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.StringWriter; -import java.time.Instant; import java.util.Collections; import java.util.List; import java.util.Random; @@ -33,7 +32,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; import com.fasterxml.jackson.dataformat.cbor.CBORParser; -import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.ddi.json.model.DdiActionFeedback; import org.eclipse.hawkbit.ddi.json.model.DdiAssignedVersion; import org.eclipse.hawkbit.ddi.json.model.DdiConfirmationFeedback; @@ -288,7 +286,7 @@ public abstract class AbstractDDiApiIntegrationTest extends AbstractRestIntegrat protected String getJsonActionFeedback( final DdiStatus.ExecutionStatus executionStatus, final DdiResult.FinalResult finalResult) throws JsonProcessingException { return getJsonActionFeedback( - executionStatus, finalResult, Collections.singletonList(RandomStringUtils.randomAlphanumeric(1000))); + executionStatus, finalResult, Collections.singletonList(randomString(1000))); } protected String getJsonActionFeedback( diff --git a/hawkbit-ddi/hawkbit-ddi-server/src/test/java/org/eclipse/hawkbit/app/ddi/AllowedHostNamesTest.java b/hawkbit-ddi/hawkbit-ddi-server/src/test/java/org/eclipse/hawkbit/app/ddi/AllowedHostNamesTest.java index 87d5bb6e6..734ac6a9b 100644 --- a/hawkbit-ddi/hawkbit-ddi-server/src/test/java/org/eclipse/hawkbit/app/ddi/AllowedHostNamesTest.java +++ b/hawkbit-ddi/hawkbit-ddi-server/src/test/java/org/eclipse/hawkbit/app/ddi/AllowedHostNamesTest.java @@ -24,25 +24,25 @@ import org.springframework.test.context.TestPropertySource; "hawkbit.server.security.httpFirewallIgnoredPaths=/index.html" }) @Feature("Integration Test - Security") @Story("Allowed Host Names") -public class AllowedHostNamesTest extends AbstractSecurityTest { +class AllowedHostNamesTest extends AbstractSecurityTest { @Test @Description("Tests whether a RequestRejectedException is thrown when not allowed host is used") - public void allowedHostNameWithNotAllowedHost() throws Exception { + void allowedHostNameWithNotAllowedHost() throws Exception { mvc.perform(get("/").header(HttpHeaders.HOST, "www.google.com")) .andExpect(status().isBadRequest()); } @Test @Description("Tests whether request is redirected when allowed host is used") - public void allowedHostNameWithAllowedHost() throws Exception { + void allowedHostNameWithAllowedHost() throws Exception { mvc.perform(get("/").header(HttpHeaders.HOST, "localhost")) .andExpect(status().is3xxRedirection()); } @Test @Description("Tests whether request without allowed host name and with ignored path end up with a client error") - public void notAllowedHostnameWithIgnoredPath() throws Exception { + void notAllowedHostnameWithIgnoredPath() throws Exception { mvc.perform(get("/index.html").header(HttpHeaders.HOST, "www.google.com")) .andExpect(status().is4xxClientError()); } diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpErrorMessageComposer.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpErrorMessageComposer.java index 073408f84..4d328c8a8 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpErrorMessageComposer.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpErrorMessageComposer.java @@ -32,8 +32,8 @@ public final class AmqpErrorMessageComposer { */ public static String constructErrorMessage(final Throwable throwable) { final String mainErrorMsg = throwable.getCause().getMessage(); - if (throwable instanceof ListenerExecutionFailedException) { - Collection failedMessages = ((ListenerExecutionFailedException) throwable).getFailedMessages(); + if (throwable instanceof ListenerExecutionFailedException listenerExecutionFailedException) { + Collection failedMessages = listenerExecutionFailedException.getFailedMessages(); // since the intended message content is always on top of the collection, we only extract the first one final Message failedMessage = failedMessages.iterator().next(); final byte[] amqpFailedMsgBody = failedMessage.getBody(); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index 1869d3110..e6a02ce2f 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -370,7 +370,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { // Handling remote request in parallel streams return StreamSupport.stream(partitions.spliterator(), true) // .flatMap(partition -> withSecurityContext(() -> loadingFunction.apply(partition), context).stream()) - .collect(Collectors.toList()); + .toList(); } return loadingFunction.apply(controllerIds); } @@ -436,7 +436,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { return false; } return true; - }).collect(Collectors.toList())); + }).toList()); } private void sendUpdateMessageToTargets( @@ -570,7 +570,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { } private List convertMetadata(final List metadata) { - return metadata.stream().map(md -> new DmfMetadata(md.getKey(), md.getValue())).collect(Collectors.toList()); + return metadata.stream().map(md -> new DmfMetadata(md.getKey(), md.getValue())).toList(); } private List convertArtifacts(final Target target, final List localArtifacts) { @@ -579,7 +579,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { } return localArtifacts.stream().map(localArtifact -> convertArtifact(target, localArtifact)) - .collect(Collectors.toList()); + .toList(); } private DmfArtifact convertArtifact(final Target target, final Artifact localArtifact) { @@ -619,7 +619,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { final List dmfTargets = targets.stream() .filter(target -> IpUtil.isAmqpUri(target.getAddress())) .map(t -> convertToDmfTarget(t, actions.get(t.getControllerId()).getId())) - .collect(Collectors.toList()); + .toList(); final DmfBatchDownloadAndUpdateRequest batchRequest = new DmfBatchDownloadAndUpdateRequest(); batchRequest.setTimestamp(System.currentTimeMillis()); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index a6db87128..48ec0f589 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -23,6 +23,8 @@ import java.util.UUID; import java.util.function.Function; import java.util.stream.Collectors; +import jakarta.validation.constraints.NotNull; + import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; @@ -215,7 +217,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { // Exception squid:MethodCyclomaticComplexity - false positive, is a simple mapping @SuppressWarnings("squid:MethodCyclomaticComplexity") - private static Status mapStatus(final Message message, final DmfActionUpdateStatus actionUpdateStatus, final Action action) { + private static @NotNull Status mapStatus(final Message message, final DmfActionUpdateStatus actionUpdateStatus, final Action action) { Status status = null; switch (actionUpdateStatus.getActionStatus()) { case DOWNLOAD: { @@ -226,8 +228,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { status = Status.RETRIEVED; break; } - case RUNNING: - case CONFIRMED: { + case RUNNING, CONFIRMED: { status = Status.RUNNING; break; } @@ -373,7 +374,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { } private Map> getSoftwareModulesWithMetadata(final DistributionSet distributionSet) { - final List smIds = distributionSet.getModules().stream().map(SoftwareModule::getId).collect(Collectors.toList()); + final List smIds = distributionSet.getModules().stream().map(SoftwareModule::getId).toList(); final Map> metadata = controllerManagement.findTargetVisibleMetaDataBySoftwareModuleId(smIds); return distributionSet.getModules().stream().collect(Collectors.toMap( Function.identity(), sm -> metadata.getOrDefault(sm.getId(), Collections.emptyList()))); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index 070c4311e..6db5c295c 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -83,7 +83,7 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { private Target testTarget; @BeforeEach - public void beforeEach() throws Exception { + public void beforeEach() { testTarget = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID) .securityToken(TEST_TOKEN).address(AMQP_URI.toString())); @@ -135,8 +135,7 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN); for (final org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule softwareModule : downloadAndUpdateRequest .getSoftwareModules()) { - assertThat(softwareModule.getArtifacts().isEmpty()).as("Artifact list for softwaremodule should be empty") - .isTrue(); + assertThat(softwareModule.getArtifacts()).as("Artifact list for softwaremodule should be empty").isEmpty(); assertThat(softwareModule.getMetadata()).allSatisfy(metadata -> { assertThat(metadata.getKey()).isEqualTo(TestdataFactory.VISIBLE_SM_MD_KEY); @@ -202,7 +201,7 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { assertThat(found.get().getSize()).isEqualTo(dbArtifact.getSize()); assertThat(found.get().getHashes().getMd5()).isEqualTo(dbArtifact.getMd5Hash()); assertThat(found.get().getHashes().getSha1()).isEqualTo(dbArtifact.getSha1Hash()); - assertThat(found.get().getLastModified()).isGreaterThan(0L); + assertThat(found.get().getLastModified()).isPositive(); }); } } diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 096672840..3c82ff42e 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -78,7 +78,7 @@ import org.springframework.amqp.support.converter.MessageConverter; @ExtendWith(MockitoExtension.class) @Feature("Component Tests - Device Management Federation API") @Story("AmqpMessage Handler Service Test") -public class AmqpMessageHandlerServiceTest { +class AmqpMessageHandlerServiceTest { private static final String FAIL_MESSAGE_AMQP_REJECT_REASON = AmqpRejectAndDontRequeueException.class .getSimpleName() + " was expected, "; @@ -128,7 +128,7 @@ public class AmqpMessageHandlerServiceTest { @BeforeEach @SuppressWarnings({ "rawtypes", "unchecked" }) - public void before() { + void before() { messageConverter = new Jackson2JsonMessageConverter(); lenient().when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter); final TenantConfigurationValue multiAssignmentConfig = TenantConfigurationValue.builder().value(Boolean.FALSE) @@ -146,19 +146,20 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests not allowed content-type in message") - public void wrongContentType() { + void wrongContentType() { final MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("xml"); final Message message = new Message(new byte[0], messageProperties); + final String type = MessageType.THING_CREATED.name(); assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class) .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "due to wrong content type") - .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); } @Test @Description("Tests the creation of a target/thing by calling the same method that incoming RabbitMQ messages would access.") - public void createThing() { + void createThing() { final String knownThingId = "1"; processThingCreatedMessage(knownThingId, null); @@ -169,7 +170,7 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests the creation of a target/thing with specified name by calling the same method that incoming RabbitMQ messages would access.") - public void createThingWithName() { + void createThingWithName() { final String knownThingId = "2"; final String knownThingName = "NonDefaultTargetName"; @@ -185,7 +186,7 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests the creation of a target/thing with specified type name by calling the same method that incoming RabbitMQ messages would access.") - public void createThingWithType() { + void createThingWithType() { final String knownThingId = "2"; final String knownThingTypeName = "TargetTypeName"; @@ -201,19 +202,17 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests not allowed body in message") - public void createThingWithWrongBody() { - final String knownThingId = "3"; - + void createThingWithWrongBody() { + final Message message = createMessage("Not allowed Body".getBytes(), getThingCreatedMessageProperties("3")); + final String type = MessageType.THING_CREATED.name(); assertThatExceptionOfType(MessageConversionException.class) .as("MessageConversionException was excepeted due to wrong body") - .isThrownBy(() -> amqpMessageHandlerService.onMessage( - createMessage("Not allowed Body".getBytes(), getThingCreatedMessageProperties(knownThingId)), - MessageType.THING_CREATED.name(), TENANT, VIRTUAL_HOST)); + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); } @Test @Description("Tests the creation of a target/thing with specified attributes by calling the same method that incoming RabbitMQ messages would access.") - public void createThingWithAttributes() { + void createThingWithAttributes() { final String knownThingId = "4"; final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate(); @@ -232,7 +231,7 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests the creation of a target/thing with specified name and attributes by calling the same method that incoming RabbitMQ messages would access.") - public void createThingWithNameAndAttributes() { + void createThingWithNameAndAttributes() { final String knownThingId = "5"; final String knownThingName = "NonDefaultTargetName"; @@ -255,7 +254,7 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests the target attribute update by calling the same method that incoming RabbitMQ messages would access.") - public void updateAttributes() { + void updateAttributes() { final String knownThingId = "1"; final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId); @@ -277,7 +276,7 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Verifies that the update mode is retrieved from the UPDATE_ATTRIBUTES message and passed to the controller management.") - public void attributeUpdateModes() { + void attributeUpdateModes() { final String knownThingId = "1"; final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId); @@ -320,32 +319,30 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests the creation of a thing without a 'reply to' header in message.") - public void createThingWithoutReplyTo() { + void createThingWithoutReplyTo() { final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED, null); messageProperties.setHeader(MessageHeaderKey.THING_ID, "1"); final Message message = createMessage("", messageProperties); - + final String type = MessageType.THING_CREATED.name(); assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class) .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no replyTo header was set") - .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, - VIRTUAL_HOST)); + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); } @Test @Description("Tests the creation of a target/thing without a thingID by calling the same method that incoming RabbitMQ messages would access.") - public void createThingWithoutID() { + void createThingWithoutID() { final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED); final Message message = createMessage(new byte[0], messageProperties); - + final String type = MessageType.THING_CREATED.name(); assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class) .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no thingId was set") - .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, - VIRTUAL_HOST)); + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); } @Test @Description("Tests the call of the same method that incoming RabbitMQ messages would access with an unknown message type.") - public void unknownMessageType() { + void unknownMessageType() { final String type = "bumlux"; final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED); messageProperties.setHeader(MessageHeaderKey.THING_ID, ""); @@ -358,7 +355,7 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests a invalid message without event topic") - public void invalidEventTopic() { + void invalidEventTopic() { final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); final Message message = new Message(new byte[0], messageProperties); @@ -366,52 +363,51 @@ public class AmqpMessageHandlerServiceTest { .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "due to unknown message type").isThrownBy( () -> amqpMessageHandlerService.onMessage(message, "unknownMessageType", TENANT, VIRTUAL_HOST)); + final String type = MessageType.EVENT.name(); messageProperties.setHeader(MessageHeaderKey.TOPIC, "wrongTopic"); assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class) - .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "due to unknown topic").isThrownBy(() -> amqpMessageHandlerService - .onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST)); + .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "due to unknown topic") + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.CANCEL_DOWNLOAD.name()); assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class) .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "because there was no event topic") - .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, - VIRTUAL_HOST)); + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); } @Test @Description("Tests the update of an action of a target without a exist action id") - public void updateActionStatusWithoutActionId() { + void updateActionStatusWithoutActionId() { when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.empty()); final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name()); final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.DOWNLOAD); final Message message = createMessage(actionUpdateStatus, messageProperties); - + final String type = MessageType.EVENT.name(); assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class) .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no action id was set") - .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, - VIRTUAL_HOST)); + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); } @Test @Description("Tests the update of an action of a target without a exist action id") - public void updateActionStatusWithoutExistActionId() { + void updateActionStatusWithoutExistActionId() { final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name()); when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.empty()); final DmfActionUpdateStatus actionUpdateStatus = createActionUpdateStatus(DmfActionStatus.DOWNLOAD); final Message message = createMessage(actionUpdateStatus, messageProperties); - + final String type = MessageType.EVENT.name(); assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class) .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no action id was set") - .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); } @Test @Description("Tests that messages which cause quota violations are not re-added to message queue so they would block other communication.") - public void quotaExceeded() { + void quotaExceeded() { final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name()); @@ -429,14 +425,14 @@ public class AmqpMessageHandlerServiceTest { when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.of(action)); when(controllerManagementMock.addUpdateActionStatus(any())).thenThrow(new AssignmentQuotaExceededException()); + final String type = MessageType.EVENT.name(); assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class) - .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, - VIRTUAL_HOST)); + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); } @Test @Description("Test next update is provided on finished action") - public void lookupNextUpdateActionAfterFinished() throws IllegalAccessException { + void lookupNextUpdateActionAfterFinished() throws IllegalAccessException { // Mock final Action action = createActionWithTarget(22L); @@ -473,7 +469,7 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Test feedback code is persisted in messages when provided with DmfActionUpdateStatus") - public void feedBackCodeIsPersistedInMessages() throws IllegalAccessException { + void feedBackCodeIsPersistedInMessages() throws IllegalAccessException { // Mock final Action action = createActionWithTarget(22L); @@ -509,7 +505,7 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests the deletion of a target/thing, requested by the target itself.") - public void deleteThing() { + void deleteThing() { // prepare valid message final String knownThingId = "1"; final MessageProperties messageProperties = createMessageProperties(MessageType.THING_REMOVED); @@ -525,15 +521,15 @@ public class AmqpMessageHandlerServiceTest { @Test @Description("Tests the deletion of a target/thing with missing thingId") - public void deleteThingWithoutThingId() { + void deleteThingWithoutThingId() { // prepare invalid message final MessageProperties messageProperties = createMessageProperties(MessageType.THING_REMOVED); final Message message = createMessage(new byte[0], messageProperties); + final String type = MessageType.THING_REMOVED.name(); assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class) .as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no thingId was set") - .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.THING_REMOVED.name(), TENANT, - VIRTUAL_HOST)); + .isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST)); } @Test diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java index d3d3f5541..26c796b97 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java @@ -382,9 +382,9 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio createConditionFactory().untilAsserted(() -> { try { - final Map controllerAttributes = SecurityContextSwitch - .runAsPrivileged(() -> targetManagement.getControllerAttributes(controllerId)); - assertThat(controllerAttributes.size()).isEqualTo(attributes.size()); + final Map controllerAttributes = SecurityContextSwitch.runAsPrivileged( + () -> targetManagement.getControllerAttributes(controllerId)); + assertThat(controllerAttributes).hasSameSizeAs(attributes); assertThat(controllerAttributes).containsAllEntriesOf(attributes); } catch (final Exception e) { throw new RuntimeException(e); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java index af8fc7120..ea658da64 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java @@ -227,12 +227,12 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt registerAndAssertTargetWithExistingTenant(controllerId); final Long actionId1 = assignNewDsToTarget(controllerId, 450); - final Entry action1Install = new SimpleEntry<>(actionId1, EventTopic.DOWNLOAD_AND_INSTALL); + final SimpleEntry action1Install = new SimpleEntry<>(actionId1, EventTopic.DOWNLOAD_AND_INSTALL); waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION); assertLatestMultiActionMessage(controllerId, Collections.singletonList(action1Install)); final Long actionId2 = assignNewDsToTarget(controllerId, 111); - final Entry action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL); + final SimpleEntry action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL); waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION); assertLatestMultiActionMessage(controllerId, Arrays.asList(action1Install, action2Install)); } @@ -315,8 +315,8 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt deploymentManagement.cancelAction(actionId1); waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION); - final Entry action1Cancel = new SimpleEntry<>(actionId1, EventTopic.CANCEL_DOWNLOAD); - final Entry action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL); + final SimpleEntry action1Cancel = new SimpleEntry<>(actionId1, EventTopic.CANCEL_DOWNLOAD); + final SimpleEntry action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL); assertLatestMultiActionMessage(controllerId, Arrays.asList(action1Cancel, action2Install)); updateActionViaDmfClient(controllerId, actionId1, DmfActionStatus.CANCELED); @@ -349,7 +349,7 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt final long actionId1 = assignNewDsToTarget(controllerId, 66); final long actionId2 = assignNewDsToTarget(controllerId, 767); - final Entry action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL); + final SimpleEntry action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL); waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION, EventTopic.MULTI_ACTION); updateActionViaDmfClient(controllerId, actionId1, DmfActionStatus.FINISHED); @@ -385,8 +385,8 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt final Long actionId2 = getFirstAssignedAction(assignDistributionSet(dsId, controllerId, 775)).getId(); waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION); - final Entry action1Install = new SimpleEntry<>(actionId1, EventTopic.DOWNLOAD_AND_INSTALL); - final Entry action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL); + final SimpleEntry action1Install = new SimpleEntry<>(actionId1, EventTopic.DOWNLOAD_AND_INSTALL); + final SimpleEntry action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL); assertLatestMultiActionMessage(controllerId, Arrays.asList(action1Install, action2Install)); } @@ -567,9 +567,10 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt assertThat(message).isNotNull(); final Map headers = message.getMessageProperties().getHeaders(); - assertThat(headers).containsEntry("thingId", controllerId); - assertThat(headers).containsEntry("type", EVENT.toString()); - assertThat(headers).containsEntry("topic", DOWNLOAD.toString()); + assertThat(headers) + .containsEntry("thingId", controllerId) + .containsEntry("type", EVENT.toString()) + .containsEntry("topic", DOWNLOAD.toString()); final Optional target = controllerManagement.getByControllerId(controllerId); assertThat(target).isPresent(); @@ -596,11 +597,11 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt final List controllerIds) { assertSoftwareModules(softwareModules, request.getSoftwareModules()); - final List tokens = controllerIds.stream().map(controllerId -> { + final List tokens = controllerIds.stream().map(controllerId -> { final Optional target = controllerManagement.getByControllerId(controllerId); assertThat(target).isPresent(); return target.get().getSecurityToken(); - }).collect(Collectors.toList()); + }).toList(); final List requestTargets = request.getTargets(); @@ -700,7 +701,7 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt private static List getDownloadAndUpdateRequests(final DmfMultiActionRequest request) { return request.getElements().stream() .filter(AmqpMessageDispatcherServiceIntegrationTest::isDownloadAndUpdateRequest) - .map(multiAction -> (DmfDownloadAndUpdateRequest) multiAction.getAction()).collect(Collectors.toList()); + .map(multiAction -> (DmfDownloadAndUpdateRequest) multiAction.getAction()).toList(); } private static boolean isDownloadAndUpdateRequest(final DmfMultiActionElement multiActionElement) { @@ -767,20 +768,20 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt .fromMessage(multiactionMessage); final List> smIdsOfActionsFound = getDownloadAndUpdateRequests(multiActionRequest).stream() - .map(AmqpMessageDispatcherServiceIntegrationTest::getSmIds).collect(Collectors.toList()); + .map(AmqpMessageDispatcherServiceIntegrationTest::getSmIds).toList(); assertThat(smIdsOfActionsFound).containsExactlyInAnyOrderElementsOf(smIdsOfActionsExpected); } private void assertLatestMultiActionMessage(final String controllerId, - final List> actionsExpected) { - final List> actionsFromMessage = getLatestMultiActionMessageActions(controllerId); + final List> actionsExpected) { + final List> actionsFromMessage = getLatestMultiActionMessageActions(controllerId); assertThat(actionsFromMessage).containsExactlyInAnyOrderElementsOf(actionsExpected); } - private List> getLatestMultiActionMessageActions(final String expectedControllerId) { + private List> getLatestMultiActionMessageActions(final String expectedControllerId) { final List multiActionRequest = getLatestMultiActionMessages(expectedControllerId); return multiActionRequest.stream() .map(request -> new SimpleEntry<>(request.getAction().getActionId(), request.getTopic())) - .collect(Collectors.toList()); + .toList(); } } diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java index 2636cd9e5..e87dfb185 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.UUID; -import java.util.stream.Collectors; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -32,7 +31,6 @@ import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Step; import io.qameta.allure.Story; -import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.amqp.AmqpMessageHandlerService; import org.eclipse.hawkbit.amqp.AmqpProperties; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; @@ -199,7 +197,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Description("Tests register invalid target with too long controller id") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) void registerInvalidTargetWithTooLongControllerId() { - createAndSendThingCreated(RandomStringUtils.randomAlphabetic(Target.CONTROLLER_ID_MAX_SIZE + 1)); + createAndSendThingCreated(randomString(Target.CONTROLLER_ID_MAX_SIZE + 1)); assertAllTargetsCount(0); verifyOneDeadLetterMessage(); } @@ -1171,13 +1169,13 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr .filter(Objects::nonNull) .filter(message -> message .startsWith(RepositoryConstants.SERVER_MESSAGE_PREFIX + "DMF message")) - .collect(Collectors.toList()); + .toList(); assertThat(messagesFromServer).hasSize(messages) .allMatch(message -> message.endsWith(CORRELATION_ID)); final List status = actionStatusList.stream().map(ActionStatus::getStatus) - .collect(Collectors.toList()); + .toList(); assertThat(status).containsOnly(expectedActionStates); return null; @@ -1204,7 +1202,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr assertThat(actionStatusList).hasSize(statusListCount); final List status = actionStatusList.stream().map(ActionStatus::getStatus) - .collect(Collectors.toList()); + .toList(); assertThat(status).containsOnly(expectedActionStates); return null; diff --git a/hawkbit-mgmt/hawkbit-mgmt-api/src/test/java/org/eclipse/hawkbit/mgmt/json/model/AuditFieldSerializationTest.java b/hawkbit-mgmt/hawkbit-mgmt-api/src/test/java/org/eclipse/hawkbit/mgmt/json/model/AuditFieldSerializationTest.java index 0932535fc..6c2a8f1b3 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-api/src/test/java/org/eclipse/hawkbit/mgmt/json/model/AuditFieldSerializationTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-api/src/test/java/org/eclipse/hawkbit/mgmt/json/model/AuditFieldSerializationTest.java @@ -20,10 +20,10 @@ import org.junit.jupiter.api.Test; @Feature("Unit Tests - Management API") @Story("Serialization") -public class AuditFieldSerializationTest { +class AuditFieldSerializationTest { @Test - public void assertAuditingFields() throws JsonProcessingException { + void assertAuditingFields() throws JsonProcessingException { final MgmtTarget mgmtTarget = new MgmtTarget(); mgmtTarget.setCreatedBy("user"); mgmtTarget.setCreatedAt(System.currentTimeMillis() - 1_000_000); diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index e072ae4eb..76b4ed429 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -43,7 +43,6 @@ import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Story; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.RandomStringUtils; import org.awaitility.Awaitility; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; @@ -142,14 +141,13 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes public void getArtifactsWithParameters() throws Exception { final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - final byte[] random = RandomStringUtils.random(5).getBytes(); + final byte[] random = randomBytes(5); artifactManagement.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, 0)); - mvc.perform( - get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts", sm.getId()) - .param("representation", MgmtRepresentationMode.FULL.toString()) - .param("useartifacturlhandler", Boolean.TRUE.toString())) + mvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts", sm.getId()) + .param("representation", MgmtRepresentationMode.FULL.toString()) + .param("useartifacturlhandler", Boolean.TRUE.toString())) .andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)); @@ -933,7 +931,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); final int artifactSize = 5 * 1024; - final byte[] random = RandomStringUtils.random(artifactSize).getBytes(); + final byte[] random = randomBytes(artifactSize); // Create 2 artifacts final Artifact artifact = artifactManagement.create( @@ -994,7 +992,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes .andExpect(status().isBadRequest()); final SoftwareModule toLongName = entityFactory.softwareModule().create().type(osType) - .name(RandomStringUtils.randomAlphanumeric(80)).build(); + .name(randomString(80)).build(); mvc.perform(post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Collections.singletonList(toLongName))) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()) @@ -1298,7 +1296,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); final int artifactSize = 5 * 1024; - final byte[] random = RandomStringUtils.random(artifactSize).getBytes(); + final byte[] random = randomBytes(artifactSize); artifactManagement.create( new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize)); @@ -1321,7 +1319,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes final DistributionSet ds1 = testdataFactory.createDistributionSet("a"); final int artifactSize = 5 * 1024; - final byte[] random = RandomStringUtils.random(artifactSize).getBytes(); + final byte[] random = randomBytes(artifactSize); final Long appTypeSmId = ds1.findFirstModuleByType(appType).get().getId(); @@ -1506,10 +1504,6 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes .andExpect(jsonPath("content[0].value", equalTo("knownValue1"))); } - private static byte[] randomBytes(final int len) { - return RandomStringUtils.randomAlphanumeric(len).getBytes(); - } - private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException { // check result in db... // repo diff --git a/hawkbit-mgmt/hawkbit-mgmt-server/src/test/java/org/eclipse/hawkbit/app/mgmt/AllowedHostNamesTest.java b/hawkbit-mgmt/hawkbit-mgmt-server/src/test/java/org/eclipse/hawkbit/app/mgmt/AllowedHostNamesTest.java index 1ee779c05..bc341d353 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-server/src/test/java/org/eclipse/hawkbit/app/mgmt/AllowedHostNamesTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-server/src/test/java/org/eclipse/hawkbit/app/mgmt/AllowedHostNamesTest.java @@ -19,27 +19,28 @@ import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.test.context.TestPropertySource; -@TestPropertySource(properties = { "hawkbit.server.security.allowedHostNames=localhost", +@TestPropertySource(properties = { + "hawkbit.server.security.allowedHostNames=localhost", "hawkbit.server.security.httpFirewallIgnoredPaths=/index.html" }) @Feature("Integration Test - Security") @Story("Allowed Host Names") -public class AllowedHostNamesTest extends AbstractSecurityTest { +class AllowedHostNamesTest extends AbstractSecurityTest { @Test @Description("Tests whether a RequestRejectedException is thrown when not allowed host is used") - public void allowedHostNameWithNotAllowedHost() throws Exception { + void allowedHostNameWithNotAllowedHost() throws Exception { mvc.perform(get("/").header(HttpHeaders.HOST, "www.google.com")).andExpect(status().isBadRequest()); } @Test @Description("Tests whether request is redirected when allowed host is used") - public void allowedHostNameWithAllowedHost() throws Exception { + void allowedHostNameWithAllowedHost() throws Exception { mvc.perform(get("/").header(HttpHeaders.HOST, "localhost")).andExpect(status().is3xxRedirection()); } @Test @Description("Tests whether request without allowed host name and with ignored path end up with a client error") - public void notAllowedHostnameWithIgnoredPath() throws Exception { + void notAllowedHostnameWithIgnoredPath() throws Exception { mvc.perform(get("/index.html").header(HttpHeaders.HOST, "www.google.com")) .andExpect(status().is4xxClientError()); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactEncryptionFailedException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactEncryptionFailedException.java index 365c52192..8c6524cb2 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactEncryptionFailedException.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactEncryptionFailedException.java @@ -11,18 +11,21 @@ package org.eclipse.hawkbit.repository.exception; import java.io.Serial; +import lombok.EqualsAndHashCode; +import lombok.Getter; import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.SpServerError; /** - * Exception being thrown in case of error while generating encryption secrets, - * encrypting or decrypting artifacts. + * Exception being thrown in case of error while generating encryption secrets, encrypting or decrypting artifacts. */ +@EqualsAndHashCode(callSuper = true) public final class ArtifactEncryptionFailedException extends AbstractServerRtException { @Serial private static final long serialVersionUID = 1L; + @Getter private final EncryptionOperation encryptionOperation; public ArtifactEncryptionFailedException(final EncryptionOperation encryptionOperation) { @@ -33,21 +36,15 @@ public final class ArtifactEncryptionFailedException extends AbstractServerRtExc this(encryptionOperation, message, null); } - public ArtifactEncryptionFailedException(final EncryptionOperation encryptionOperation, final String message, - final Throwable cause) { + public ArtifactEncryptionFailedException(final EncryptionOperation encryptionOperation, final String message, final Throwable cause) { super(message, SpServerError.SP_ARTIFACT_ENCRYPTION_FAILED, cause); this.encryptionOperation = encryptionOperation; } - public EncryptionOperation getEncryptionOperation() { - return encryptionOperation; - } - /** * Encryption operation that caused the exception. */ public enum EncryptionOperation { GENERATE_SECRETS, ENCRYPT, DECRYPT; } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractBaseEntityBuilder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractBaseEntityBuilder.java index e0622ec6e..c32ac848d 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractBaseEntityBuilder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractBaseEntityBuilder.java @@ -19,4 +19,8 @@ public abstract class AbstractBaseEntityBuilder implements Identifiable { public Long getId() { return id; } + + static String strip(final String value) { + return value == null ? null : value.strip(); + } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractDistributionSetUpdateCreate.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractDistributionSetUpdateCreate.java index 97e1f135c..814b89158 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractDistributionSetUpdateCreate.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractDistributionSetUpdateCreate.java @@ -12,8 +12,8 @@ package org.eclipse.hawkbit.repository.builder; import java.util.Collection; import java.util.Optional; +import lombok.Getter; import org.eclipse.hawkbit.repository.ValidString; -import org.springframework.util.StringUtils; /** * Create and update builder DTO. @@ -25,6 +25,7 @@ public abstract class AbstractDistributionSetUpdateCreate extends AbstractNam @ValidString protected String version; protected Boolean requiredMigrationStep; + @Getter protected Collection modules; public T modules(final Collection modules) { @@ -32,10 +33,6 @@ public abstract class AbstractDistributionSetUpdateCreate extends AbstractNam return (T) this; } - public Collection getModules() { - return modules; - } - public T requiredMigrationStep(final Boolean requiredMigrationStep) { this.requiredMigrationStep = requiredMigrationStep; return (T) this; @@ -46,7 +43,7 @@ public abstract class AbstractDistributionSetUpdateCreate extends AbstractNam } public T version(final String version) { - this.version = StringUtils.trimWhitespace(version); + this.version = strip(version); return (T) this; } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractMetadataUpdateCreate.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractMetadataUpdateCreate.java index 644f88c6f..787601948 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractMetadataUpdateCreate.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractMetadataUpdateCreate.java @@ -13,7 +13,6 @@ import java.util.Optional; import lombok.Getter; import org.eclipse.hawkbit.repository.ValidString; -import org.springframework.util.StringUtils; /** * Create and update builder DTO. @@ -29,12 +28,12 @@ public abstract class AbstractMetadataUpdateCreate { protected String value; public T key(final String key) { - this.key = StringUtils.trimWhitespace(key); + this.key = AbstractBaseEntityBuilder.strip(key); return (T) this; } public T value(final String value) { - this.value = StringUtils.trimWhitespace(value); + this.value = AbstractBaseEntityBuilder.strip(value); return (T) this; } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractNamedEntityBuilder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractNamedEntityBuilder.java index 008197e47..a1ef731c0 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractNamedEntityBuilder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractNamedEntityBuilder.java @@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.builder; import java.util.Optional; import org.eclipse.hawkbit.repository.ValidString; -import org.springframework.util.StringUtils; public abstract class AbstractNamedEntityBuilder extends AbstractBaseEntityBuilder { @@ -22,12 +21,12 @@ public abstract class AbstractNamedEntityBuilder extends AbstractBaseEntityBu protected String description; public T name(final String name) { - this.name = StringUtils.trimWhitespace(name); + this.name = AbstractBaseEntityBuilder.strip(name); return (T) this; } public T description(final String description) { - this.description = StringUtils.trimWhitespace(description); + this.description = AbstractBaseEntityBuilder.strip(description); return (T) this; } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractRolloutGroupCreate.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractRolloutGroupCreate.java index 57d87b1bb..9ae1a3f0b 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractRolloutGroupCreate.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractRolloutGroupCreate.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository.builder; import org.eclipse.hawkbit.repository.ValidString; import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; -import org.springframework.util.StringUtils; /** * Create builder DTO. @@ -27,7 +26,7 @@ public abstract class AbstractRolloutGroupCreate extends AbstractNamedEntityB protected boolean confirmationRequired; public T targetFilterQuery(final String targetFilterQuery) { - this.targetFilterQuery = StringUtils.trimWhitespace(targetFilterQuery); + this.targetFilterQuery = AbstractBaseEntityBuilder.strip(targetFilterQuery); return (T) this; } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractSoftwareModuleUpdateCreate.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractSoftwareModuleUpdateCreate.java index 586c6ac11..3a2176e7f 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractSoftwareModuleUpdateCreate.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractSoftwareModuleUpdateCreate.java @@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.builder; import java.util.Optional; import org.eclipse.hawkbit.repository.ValidString; -import org.springframework.util.StringUtils; /** * Create and update builder DTO. @@ -29,7 +28,7 @@ public abstract class AbstractSoftwareModuleUpdateCreate extends AbstractName protected String type; public T type(final String type) { - this.type = StringUtils.trimWhitespace(type); + this.type = AbstractBaseEntityBuilder.strip(type); return (T) this; } @@ -38,7 +37,7 @@ public abstract class AbstractSoftwareModuleUpdateCreate extends AbstractName } public T vendor(final String vendor) { - this.vendor = StringUtils.trimWhitespace(vendor); + this.vendor = AbstractBaseEntityBuilder.strip(vendor); return (T) this; } @@ -47,7 +46,7 @@ public abstract class AbstractSoftwareModuleUpdateCreate extends AbstractName } public T version(final String version) { - this.version = StringUtils.trimWhitespace(version); + this.version = AbstractBaseEntityBuilder.strip(version); return (T) this; } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTagUpdateCreate.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTagUpdateCreate.java index 6b58c09a5..1ed0ffd5c 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTagUpdateCreate.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTagUpdateCreate.java @@ -25,7 +25,7 @@ public class AbstractTagUpdateCreate extends AbstractNamedEntityBuilder { protected String colour; public T colour(final String colour) { - this.colour = StringUtils.trimWhitespace(colour); + this.colour = AbstractBaseEntityBuilder.strip(colour); return (T) this; } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTargetFilterQueryUpdateCreate.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTargetFilterQueryUpdateCreate.java index fe52fbf22..4f6a156f4 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTargetFilterQueryUpdateCreate.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTargetFilterQueryUpdateCreate.java @@ -18,7 +18,6 @@ import org.eclipse.hawkbit.repository.ValidString; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; -import org.springframework.util.StringUtils; /** * Create and update builder DTO. @@ -91,7 +90,7 @@ public abstract class AbstractTargetFilterQueryUpdateCreate extends AbstractB * @return this builder */ public T name(final String name) { - this.name = StringUtils.trimWhitespace(name); + this.name = AbstractBaseEntityBuilder.strip(name); return (T) this; } @@ -106,7 +105,7 @@ public abstract class AbstractTargetFilterQueryUpdateCreate extends AbstractB * @return this builder */ public T query(final String query) { - this.query = StringUtils.trimWhitespace(query); + this.query = AbstractBaseEntityBuilder.strip(query); return (T) this; } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTargetUpdateCreate.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTargetUpdateCreate.java index a0a7134d3..0aec44887 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTargetUpdateCreate.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTargetUpdateCreate.java @@ -16,7 +16,6 @@ import lombok.ToString; import org.eclipse.hawkbit.repository.ValidString; import org.eclipse.hawkbit.repository.exception.InvalidTargetAddressException; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.springframework.util.StringUtils; /** * Create and update builder DTO. @@ -37,7 +36,7 @@ public class AbstractTargetUpdateCreate extends AbstractNamedEntityBuilder protected Long targetTypeId; protected AbstractTargetUpdateCreate(final String controllerId) { - this.controllerId = StringUtils.trimWhitespace(controllerId); + this.controllerId = AbstractBaseEntityBuilder.strip(controllerId); } public T status(final TargetUpdateStatus status) { @@ -49,7 +48,7 @@ public class AbstractTargetUpdateCreate extends AbstractNamedEntityBuilder // check if this is a real URI if (address != null) { try { - URI.create(StringUtils.trimWhitespace(address)); + URI.create(AbstractBaseEntityBuilder.strip(address)); } catch (final IllegalArgumentException e) { throw new InvalidTargetAddressException( "The given address " + address + " violates the RFC-2396 specification", e); @@ -60,7 +59,7 @@ public class AbstractTargetUpdateCreate extends AbstractNamedEntityBuilder } public T securityToken(final String securityToken) { - this.securityToken = StringUtils.trimWhitespace(securityToken); + this.securityToken = AbstractBaseEntityBuilder.strip(securityToken); return (T) this; } @@ -75,7 +74,7 @@ public class AbstractTargetUpdateCreate extends AbstractNamedEntityBuilder } public TargetCreate controllerId(final String controllerId) { - this.controllerId = StringUtils.trimWhitespace(controllerId); + this.controllerId = AbstractBaseEntityBuilder.strip(controllerId); return (TargetCreate) this; } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTypeUpdateCreate.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTypeUpdateCreate.java index 0d1422b79..813307b1f 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTypeUpdateCreate.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractTypeUpdateCreate.java @@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.builder; import java.util.Optional; import org.eclipse.hawkbit.repository.ValidString; -import org.springframework.util.StringUtils; /** * Create and update builder DTO. @@ -27,7 +26,7 @@ public abstract class AbstractTypeUpdateCreate extends AbstractNamedEntityBui protected String key; public T colour(final String colour) { - this.colour = StringUtils.trimWhitespace(colour); + this.colour = AbstractBaseEntityBuilder.strip(colour); return (T) this; } @@ -36,7 +35,7 @@ public abstract class AbstractTypeUpdateCreate extends AbstractNamedEntityBui } public T key(final String key) { - this.key = StringUtils.trimWhitespace(key); + this.key = AbstractBaseEntityBuilder.strip(key); return (T) this; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java index 00103e281..56272582d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -85,8 +85,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest protected static final String NOT_EXIST_ID = "12345678990"; protected static final long NOT_EXIST_IDL = Long.parseLong(NOT_EXIST_ID); - protected static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.insecure(); - private static final List REPOSITORY_AND_TARGET_PERMISSIONS = List.of(SpPermission.READ_REPOSITORY, SpPermission.CREATE_REPOSITORY, SpPermission.UPDATE_REPOSITORY, SpPermission.DELETE_REPOSITORY, SpPermission.READ_TARGET, SpPermission.CREATE_TARGET, SpPermission.UPDATE_TARGET, SpPermission.DELETE_TARGET); @PersistenceContext @@ -177,14 +175,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest ((JpaSoftwareModule) module).setOptLockRevision(module.getOptLockRevision() + 1); } - protected static String randomString(final int len) { - return RANDOM_STRING_UTILS.next(len, true, false); - } - - protected static byte[] randomBytes(final int len) { - return randomString(len).getBytes(); - } - protected Database getDatabase() { return jpaProperties.getDatabase(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerIntTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerIntTest.java index f3c882051..fb7e94167 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerIntTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerIntTest.java @@ -25,6 +25,7 @@ import io.qameta.allure.Feature; import io.qameta.allure.Step; import io.qameta.allure.Story; import org.eclipse.hawkbit.repository.DeploymentManagement; +import org.eclipse.hawkbit.repository.builder.AutoAssignDistributionSetUpdate; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications; @@ -248,15 +249,13 @@ class AutoAssignCheckerIntTest extends AbstractJpaIntegrationTest { final String targetDsAIdPref = "targA"; final String targetDsFIdPref = "targB"; - // target filter query that matches first bunch of targets, that should - // fail - assertThatExceptionOfType(IncompleteDistributionSetException.class).isThrownBy(() -> { - final Long filterId = targetFilterQueryManagement.create( - entityFactory.targetFilterQuery().create().name("filterA").query("id==" + targetDsFIdPref + "*")) - .getId(); - targetFilterQueryManagement - .updateAutoAssignDS(entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(setF.getId())); - }); + final Long filterId = targetFilterQueryManagement.create( + entityFactory.targetFilterQuery().create().name("filterA").query("id==" + targetDsFIdPref + "*")) + .getId(); + final AutoAssignDistributionSetUpdate targetFilterQuery = entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(setF.getId()); + // target filter query that matches first bunch of targets, that should fail + assertThatExceptionOfType(IncompleteDistributionSetException.class).isThrownBy( + () -> targetFilterQueryManagement.updateAutoAssignDS(targetFilterQuery)); // target filter query that matches failed bunch of targets targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name("filterB") .query("id==" + targetDsAIdPref + "*").autoAssignDistributionSet(setA.getId())); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ArtifactManagementTest.java index 3be740c3f..339d4284d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ArtifactManagementTest.java @@ -30,7 +30,6 @@ import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Story; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; import org.eclipse.hawkbit.im.authentication.SpPermission; diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index f42eb0159..e2f570377 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -116,6 +116,8 @@ public abstract class AbstractIntegrationTest { protected static final URI LOCALHOST = URI.create("http://127.0.0.1"); protected static final int DEFAULT_TEST_WEIGHT = 500; + protected static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.secure(); + /** * Number of {@link DistributionSetType}s that exist in every test case. One * generated by using @@ -292,6 +294,14 @@ public abstract class AbstractIntegrationTest { return Comparator.comparing(Target::getControllerId); } + protected static String randomString(final int len) { + return RANDOM_STRING_UTILS.next(len, true, false); + } + + protected static byte[] randomBytes(final int len) { + return randomString(len).getBytes(); + } + protected DistributionSetAssignmentResult assignDistributionSet(final long dsID, final String controllerId) { return assignDistributionSet(dsID, controllerId, ActionType.FORCED); } @@ -477,7 +487,7 @@ public abstract class AbstractIntegrationTest { private static String createTempDir() { try { - return Files.createTempDirectory(null).toString() + "/" + RandomStringUtils.randomAlphanumeric(20); + return Files.createTempDirectory(null).toString() + "/" + randomString(20); } catch (final IOException e) { throw new IllegalStateException("Failed to create temp directory"); } diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractSqlTestDatabase.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractSqlTestDatabase.java index 8cf2dde37..90cd2457e 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractSqlTestDatabase.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractSqlTestDatabase.java @@ -31,7 +31,7 @@ public abstract class AbstractSqlTestDatabase extends AbstractTestExecutionListe protected final DatasourceContext context; - public AbstractSqlTestDatabase(final DatasourceContext context) { + protected AbstractSqlTestDatabase(final DatasourceContext context) { this.context = context; } diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java index 915f29b34..ea4a86923 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java @@ -44,7 +44,7 @@ public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTes private CharacterEncodingFilter characterEncodingFilter; @BeforeEach - public void before() throws Exception { + public void before() { mvc = createMvcWebAppContext(webApplicationContext).build(); } diff --git a/hawkbit-sdk/hawkbit-sdk-dmf/src/main/java/org/eclipse/hawkbit/sdk/dmf/amqp/Amqp.java b/hawkbit-sdk/hawkbit-sdk-dmf/src/main/java/org/eclipse/hawkbit/sdk/dmf/amqp/Amqp.java index 409409bef..bd846ab3b 100644 --- a/hawkbit-sdk/hawkbit-sdk-dmf/src/main/java/org/eclipse/hawkbit/sdk/dmf/amqp/Amqp.java +++ b/hawkbit-sdk/hawkbit-sdk-dmf/src/main/java/org/eclipse/hawkbit/sdk/dmf/amqp/Amqp.java @@ -58,11 +58,9 @@ public class Amqp { } } connectionFactory.setUsername( - dmf == null || ObjectUtils.isEmpty(dmf.getUsername()) ? - rabbitProperties.getUsername() : dmf.getUsername()); + dmf == null || ObjectUtils.isEmpty(dmf.getUsername()) ? rabbitProperties.getUsername() : dmf.getUsername()); connectionFactory.setPassword( - dmf == null || ObjectUtils.isEmpty(dmf.getPassword()) ? - rabbitProperties.getPassword() : dmf.getPassword()); + dmf == null || ObjectUtils.isEmpty(dmf.getPassword()) ? rabbitProperties.getPassword() : dmf.getPassword()); connectionFactory.setVirtualHost(vHost); return connectionFactory; }