Spring Boot 2.0 (#721)
* Migration to Boot 2.0. Signed-off-by: Kai Zimmermann <kai.zimmermann@microsoft.com>
This commit is contained in:
@@ -59,9 +59,9 @@
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-json</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.google.common.collect.Maps;
|
||||
* Bean which holds the necessary properties for configuring the AMQP deadletter
|
||||
* queue.
|
||||
*/
|
||||
@ConfigurationProperties("hawkbit.dmf.rabbitmq.deadLetter")
|
||||
@ConfigurationProperties("hawkbit.dmf.rabbitmq.dead-letter")
|
||||
public class AmqpDeadletterProperties {
|
||||
private static final int THREE_WEEKS = 21;
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -140,7 +140,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
.forEach(
|
||||
module -> modules.put(module,
|
||||
softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(
|
||||
new PageRequest(0, RepositoryConstants.MAX_META_DATA_COUNT), module.getId())
|
||||
PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT), module.getId())
|
||||
.getContent()));
|
||||
|
||||
targetManagement.getByControllerID(assignedEvent.getActions().keySet())
|
||||
|
||||
@@ -9,11 +9,9 @@
|
||||
package org.eclipse.hawkbit.amqp;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -43,7 +41,6 @@ import org.springframework.amqp.AmqpRejectAndDontRequeueException;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.messaging.converter.MessageConversionException;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -271,7 +268,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
|
||||
if (isCorrelationIdNotEmpty(message)) {
|
||||
messages.add(RepositoryConstants.SERVER_MESSAGE_PREFIX + "DMF message correlation-id "
|
||||
+ convertCorrelationId(message));
|
||||
+ message.getMessageProperties().getCorrelationId());
|
||||
}
|
||||
|
||||
final Status status = mapStatus(message, actionUpdateStatus, action);
|
||||
@@ -287,8 +284,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
private static boolean isCorrelationIdNotEmpty(final Message message) {
|
||||
return message.getMessageProperties().getCorrelationId() != null
|
||||
&& message.getMessageProperties().getCorrelationId().length > 0;
|
||||
return StringUtils.hasLength(message.getMessageProperties().getCorrelationId());
|
||||
}
|
||||
|
||||
// Exception squid:MethodCyclomaticComplexity - false positive, is a simple
|
||||
@@ -341,10 +337,6 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String convertCorrelationId(final Message message) {
|
||||
return new String(message.getMessageProperties().getCorrelationId(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private Action getUpdateActionStatus(final Status status, final ActionStatusCreate actionStatus) {
|
||||
if (Status.CANCELED.equals(status)) {
|
||||
return controllerManagement.addCancelActionStatus(actionStatus);
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.amqp;
|
||||
|
||||
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpoint;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
@@ -44,8 +45,9 @@ public class ConfigurableRabbitListenerContainerFactory extends SimpleRabbitList
|
||||
// Exception squid:UnusedProtectedMethod - called by
|
||||
// AbstractRabbitListenerContainerFactory
|
||||
@SuppressWarnings("squid:UnusedProtectedMethod")
|
||||
protected void initializeContainer(final SimpleMessageListenerContainer instance) {
|
||||
super.initializeContainer(instance);
|
||||
protected void initializeContainer(final SimpleMessageListenerContainer instance,
|
||||
final RabbitListenerEndpoint endpoint) {
|
||||
super.initializeContainer(instance, endpoint);
|
||||
instance.setDeclarationRetries(declarationRetries);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
package org.eclipse.hawkbit.amqp;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.hawkbit.util.IpUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.support.CorrelationData;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A default implementation for the sender service. The service sends all amqp
|
||||
@@ -47,7 +47,7 @@ public class DefaultAmqpMessageSenderService extends BaseAmqpService implements
|
||||
final String correlationId = UUID.randomUUID().toString();
|
||||
|
||||
if (isCorrelationIdEmpty(message)) {
|
||||
message.getMessageProperties().setCorrelationId(correlationId.getBytes(StandardCharsets.UTF_8));
|
||||
message.getMessageProperties().setCorrelationId(correlationId);
|
||||
}
|
||||
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
@@ -60,8 +60,7 @@ public class DefaultAmqpMessageSenderService extends BaseAmqpService implements
|
||||
}
|
||||
|
||||
protected static boolean isCorrelationIdEmpty(final Message message) {
|
||||
return message.getMessageProperties().getCorrelationId() == null
|
||||
|| message.getMessageProperties().getCorrelationId().length <= 0;
|
||||
return !StringUtils.hasLength(message.getMessageProperties().getCorrelationId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ package org.eclipse.hawkbit.amqp;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
@@ -164,7 +164,6 @@ public class AmqpControllerAuthenticationTest {
|
||||
|
||||
final AbstractDbArtifact artifact = new ArtifactFilesystem(new File("does not exist"), SHA1,
|
||||
new DbArtifactHash(SHA1, "md5 test"), ARTIFACT_SIZE, null);
|
||||
when(artifactManagementMock.loadArtifactBinary(SHA1)).thenReturn(Optional.of(artifact));
|
||||
|
||||
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate,
|
||||
mock(AmqpMessageDispatcherService.class), controllerManagementMock, new JpaEntityFactory());
|
||||
|
||||
@@ -12,9 +12,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyObject;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
@@ -59,7 +59,7 @@ import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
@@ -69,7 +69,7 @@ import io.qameta.allure.Story;
|
||||
@ActiveProfiles({ "test" })
|
||||
@Feature("Component Tests - Device Management Federation API")
|
||||
@Story("AmqpMessage Dispatcher Service Test")
|
||||
@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class })
|
||||
@SpringBootTest(classes = { RepositoryApplicationConfiguration.class })
|
||||
public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
|
||||
private static final String TENANT = "default";
|
||||
@@ -214,7 +214,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Description("Verifies that sending update controller attributes event works.")
|
||||
public void sendUpdateAttributesRequest() {
|
||||
|
||||
@@ -10,10 +10,10 @@ package org.eclipse.hawkbit.amqp;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -43,7 +43,6 @@ import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.UpdateMode;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -60,7 +59,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
@@ -392,8 +391,6 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
final Artifact localArtifactMock = mock(Artifact.class);
|
||||
when(artifactManagementMock.findFirstBySHA1(anyString())).thenReturn(Optional.of(localArtifactMock));
|
||||
when(controllerManagementMock.getActionForDownloadByTargetAndSoftwareModule(anyString(), anyLong()))
|
||||
.thenThrow(EntityNotFoundException.class);
|
||||
|
||||
// test
|
||||
final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message);
|
||||
@@ -515,15 +512,11 @@ public class AmqpMessageHandlerServiceTest {
|
||||
final Target targetMock = mock(Target.class);
|
||||
final DistributionSet distributionSetMock = mock(DistributionSet.class);
|
||||
|
||||
when(distributionSetMock.getId()).thenReturn(1L);
|
||||
when(actionMock.getDistributionSet()).thenReturn(distributionSetMock);
|
||||
when(actionMock.getId()).thenReturn(targetId);
|
||||
when(actionMock.getStatus()).thenReturn(status);
|
||||
when(actionMock.getTenant()).thenReturn("DEFAULT");
|
||||
when(actionMock.getTarget()).thenReturn(targetMock);
|
||||
when(targetMock.getControllerId()).thenReturn("target1");
|
||||
when(targetMock.getSecurityToken()).thenReturn("securityToken");
|
||||
when(targetMock.getAddress()).thenReturn(null);
|
||||
return actionMock;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.test.TestConfiguration;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.eclipse.hawkbit.util.IpUtil;
|
||||
import org.junit.Assert;
|
||||
@@ -49,7 +50,8 @@ import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.test.RabbitListenerTestHarness;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import io.qameta.allure.Step;
|
||||
|
||||
@@ -58,9 +60,10 @@ import io.qameta.allure.Step;
|
||||
* Common class for {@link AmqpMessageHandlerServiceIntegrationTest} and
|
||||
* {@link AmqpMessageDispatcherServiceIntegrationTest}.
|
||||
*/
|
||||
@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class, AmqpTestConfiguration.class,
|
||||
DmfApiConfiguration.class, DmfTestConfiguration.class })
|
||||
public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegrationTest {
|
||||
@ContextConfiguration(classes = { DmfApiConfiguration.class, DmfTestConfiguration.class,
|
||||
RepositoryApplicationConfiguration.class, AmqpTestConfiguration.class, TestConfiguration.class,
|
||||
TestSupportBinderAutoConfiguration.class })
|
||||
public abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegrationTest {
|
||||
|
||||
protected static final String TENANT_EXIST = "DEFAULT";
|
||||
protected static final String CREATED_BY = "CONTROLLER_PLUG_AND_PLAY";
|
||||
@@ -99,7 +102,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
|
||||
}
|
||||
|
||||
protected void verifyDeadLetterMessages(final int expectedMessages) {
|
||||
createConditionFactory().until(() -> {
|
||||
createConditionFactory().untilAsserted(() -> {
|
||||
Mockito.verify(getDeadletterListener(), Mockito.times(expectedMessages)).handleMessage(Mockito.any());
|
||||
});
|
||||
}
|
||||
@@ -165,8 +168,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
|
||||
final Map<String, Object> headers = replyMessage.getMessageProperties().getHeaders();
|
||||
|
||||
assertThat(headers.get(MessageHeaderKey.TENANT)).isEqualTo(TENANT_EXIST);
|
||||
assertThat(correlationId)
|
||||
.isEqualTo(new String(replyMessage.getMessageProperties().getCorrelationId(), StandardCharsets.UTF_8));
|
||||
assertThat(correlationId).isEqualTo(replyMessage.getMessageProperties().getCorrelationId());
|
||||
assertThat(headers.get(MessageHeaderKey.TYPE)).isEqualTo(MessageType.PING_RESPONSE.toString());
|
||||
assertThat(Long.valueOf(new String(replyMessage.getBody(), StandardCharsets.UTF_8)))
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
@@ -213,7 +215,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
|
||||
}
|
||||
|
||||
protected void verifyReplyToListener() {
|
||||
createConditionFactory().until(() -> {
|
||||
createConditionFactory().untilAsserted(() -> {
|
||||
Mockito.verify(replyToListener, Mockito.atLeast(1)).handleMessage(Mockito.any());
|
||||
});
|
||||
}
|
||||
@@ -306,7 +308,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
|
||||
protected Message createPingMessage(final String correlationId, final String tenant) {
|
||||
final MessageProperties messageProperties = createMessagePropertiesWithTenant(tenant);
|
||||
messageProperties.getHeaders().put(MessageHeaderKey.TYPE, MessageType.PING.toString());
|
||||
messageProperties.setCorrelationId(correlationId.getBytes());
|
||||
messageProperties.setCorrelationId(correlationId);
|
||||
messageProperties.setReplyTo(DmfTestConfiguration.REPLY_TO_EXCHANGE);
|
||||
|
||||
return createMessage(null, messageProperties);
|
||||
@@ -354,7 +356,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
|
||||
protected void assertUpdateAttributes(final String controllerId, final Map<String, String> attributes) {
|
||||
waitUntilIsPresent(() -> controllerManagement.getByControllerId(controllerId));
|
||||
|
||||
createConditionFactory().until(() -> {
|
||||
createConditionFactory().untilAsserted(() -> {
|
||||
try {
|
||||
final Map<String, String> controllerAttributes = securityRule
|
||||
.runAsPrivileged(() -> targetManagement.getControllerAttributes(controllerId));
|
||||
@@ -19,8 +19,6 @@ import org.eclipse.hawkbit.amqp.DmfApiConfiguration;
|
||||
import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings;
|
||||
import org.eclipse.hawkbit.dmf.json.model.DmfDownloadResponse;
|
||||
import org.eclipse.hawkbit.rabbitmq.test.AbstractAmqpIntegrationTest;
|
||||
import org.eclipse.hawkbit.rabbitmq.test.AmqpTestConfiguration;
|
||||
import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -35,7 +33,7 @@ import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -45,8 +43,7 @@ import io.qameta.allure.Story;
|
||||
|
||||
@Feature("Component Tests - Device Management Federation API")
|
||||
@Story("Amqp Authentication Message Handler")
|
||||
@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class, AmqpTestConfiguration.class,
|
||||
DmfApiConfiguration.class })
|
||||
@SpringBootTest(classes = { DmfApiConfiguration.class })
|
||||
public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmqpIntegrationTest {
|
||||
|
||||
private static final String TARGET_SECRUITY_TOKEN = "12345";
|
||||
|
||||
@@ -40,7 +40,7 @@ import io.qameta.allure.Story;
|
||||
|
||||
@Feature("Component Tests - Device Management Federation API")
|
||||
@Story("Amqp Message Dispatcher Service")
|
||||
public class AmqpMessageDispatcherServiceIntegrationTest extends AmqpServiceIntegrationTest {
|
||||
public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceIntegrationTest {
|
||||
private static final String TARGET_PREFIX = "Dmf_disp_";
|
||||
|
||||
@Test
|
||||
|
||||
@@ -58,7 +58,7 @@ import io.qameta.allure.Story;
|
||||
|
||||
@Feature("Component Tests - Device Management Federation API")
|
||||
@Story("Amqp Message Handler Service")
|
||||
public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegrationTest {
|
||||
public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegrationTest {
|
||||
private static final String CORRELATION_ID = UUID.randomUUID().toString();
|
||||
private static final String TARGET_PREFIX = "Dmf_hand_";
|
||||
|
||||
@@ -836,7 +836,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
||||
}
|
||||
|
||||
private void assertAction(final Long actionId, final int messages, final Status... expectedActionStates) {
|
||||
createConditionFactory().await().until(() -> {
|
||||
createConditionFactory().await().untilAsserted(() -> {
|
||||
try {
|
||||
securityRule.runAsPrivileged(() -> {
|
||||
final List<ActionStatus> actionStatusList = deploymentManagement
|
||||
@@ -870,7 +870,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
||||
final MessageProperties messageProperties = createMessagePropertiesWithTenant(tenant);
|
||||
messageProperties.getHeaders().put(MessageHeaderKey.TYPE, MessageType.EVENT.toString());
|
||||
messageProperties.getHeaders().put(MessageHeaderKey.TOPIC, eventTopic.toString());
|
||||
messageProperties.setCorrelationId(CORRELATION_ID.getBytes());
|
||||
messageProperties.setCorrelationId(CORRELATION_ID);
|
||||
|
||||
return createMessage(payload, messageProperties);
|
||||
}
|
||||
@@ -896,7 +896,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
||||
|
||||
private void verifyNumberOfDeadLetterMessages(final int numberOfInvocations) {
|
||||
assertEmptyReceiverQueueCount();
|
||||
createConditionFactory().until(() -> Mockito.verify(getDeadletterListener(), Mockito.times(numberOfInvocations))
|
||||
.handleMessage(Mockito.any()));
|
||||
createConditionFactory().untilAsserted(() -> Mockito
|
||||
.verify(getDeadletterListener(), Mockito.times(numberOfInvocations)).handleMessage(Mockito.any()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.integration.listener;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -53,9 +52,7 @@ public class ReplyToListener implements TestRabbitListener {
|
||||
}
|
||||
|
||||
if (messageType == MessageType.PING_RESPONSE) {
|
||||
final String correlationId = new String(message.getMessageProperties().getCorrelationId(),
|
||||
StandardCharsets.UTF_8);
|
||||
pingResponseMessages.put(correlationId, message);
|
||||
pingResponseMessages.put(message.getMessageProperties().getCorrelationId(), message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,58 +9,74 @@
|
||||
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-dmf-parent</artifactId>
|
||||
<version>0.3.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-dmf-rabbitmq-test</artifactId>
|
||||
<name>hawkBit :: DMF :: RabbitMq Test module</name>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-dmf-parent</artifactId>
|
||||
<version>0.3.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-dmf-rabbitmq-test</artifactId>
|
||||
<name>hawkBit :: DMF :: RabbitMq Test module</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-jpa</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-dmf-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-junit</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-test</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-jpa</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-dmf-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-junit</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rabbitmq</groupId>
|
||||
<artifactId>http-client</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-test</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -8,9 +8,13 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.rabbitmq.test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.core.ConditionFactory;
|
||||
import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
|
||||
import org.eclipse.hawkbit.repository.test.TestConfiguration;
|
||||
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -22,18 +26,18 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import com.jayway.awaitility.core.ConditionFactory;
|
||||
|
||||
@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class, AmqpTestConfiguration.class })
|
||||
@ContextConfiguration(classes = { RepositoryApplicationConfiguration.class, AmqpTestConfiguration.class,
|
||||
TestConfiguration.class, TestSupportBinderAutoConfiguration.class })
|
||||
// Dirty context is necessary to create a new vhost and recreate all necessary
|
||||
// beans after every test class.
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
||||
public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest {
|
||||
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
||||
|
||||
@Rule
|
||||
@Autowired
|
||||
@@ -59,7 +63,7 @@ public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTes
|
||||
}
|
||||
|
||||
protected ConditionFactory createConditionFactory() {
|
||||
return Awaitility.await().atMost(5, TimeUnit.SECONDS);
|
||||
return Awaitility.await().atMost(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
protected Message createMessage(final Object payload, final MessageProperties messageProperties) {
|
||||
|
||||
@@ -26,8 +26,9 @@ import com.rabbitmq.http.client.domain.UserPermissions;
|
||||
* Creates and deletes a new virtual host if the rabbit mq management api is
|
||||
* available.
|
||||
*
|
||||
*
|
||||
*/
|
||||
// exception squid:S2068 - Test instance passwd
|
||||
@SuppressWarnings("squid:S2068")
|
||||
public class RabbitMqSetupService {
|
||||
|
||||
private static final String GUEST = "guest";
|
||||
@@ -44,7 +45,7 @@ public class RabbitMqSetupService {
|
||||
|
||||
private String password;
|
||||
|
||||
public RabbitMqSetupService(RabbitProperties properties) {
|
||||
public RabbitMqSetupService(final RabbitProperties properties) {
|
||||
hostname = properties.getHost();
|
||||
username = properties.getUsername();
|
||||
if (StringUtils.isEmpty(username)) {
|
||||
@@ -118,7 +119,7 @@ public class RabbitMqSetupService {
|
||||
static class AlivenessException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public AlivenessException(String hostname) {
|
||||
public AlivenessException(final String hostname) {
|
||||
super("Aliveness test failed for " + hostname
|
||||
+ ":15672 guest/quest; rabbit mq management api not available");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user