Fix sonar issues and add DMF tests for maintenance window feature (#655)

* Fix sonar issues.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* POM cleanup and more sonar issues fixed.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove unneeded JavaDocs.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* More sonar issues.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* More issues.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Adapt maintenance window to naming.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Add DMF tests.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Readibility.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Typos fixed.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2018-03-08 10:42:25 +01:00
committed by GitHub
parent f4278c45ef
commit b4414438b0
32 changed files with 411 additions and 364 deletions

View File

@@ -312,12 +312,11 @@ public class AmqpConfiguration {
AmqpMessageDispatcherService amqpMessageDispatcherService(final RabbitTemplate rabbitTemplate,
final AmqpMessageSenderService amqpSenderService, final ArtifactUrlHandler artifactUrlHandler,
final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement,
final ControllerManagement controllerManagement, final TargetManagement targetManagement,
final DistributionSetManagement distributionSetManagement,
final TargetManagement targetManagement, final DistributionSetManagement distributionSetManagement,
final SoftwareModuleManagement softwareModuleManagement) {
return new AmqpMessageDispatcherService(rabbitTemplate, amqpSenderService, artifactUrlHandler,
systemSecurityContext, systemManagement, controllerManagement, targetManagement, serviceMatcher,
distributionSetManagement, softwareModuleManagement);
systemSecurityContext, systemManagement, targetManagement, serviceMatcher, distributionSetManagement,
softwareModuleManagement);
}
private static Map<String, Object> getTTLMaxArgsAuthenticationQueue() {

View File

@@ -13,7 +13,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.api.ApiType;
@@ -30,7 +29,6 @@ import org.eclipse.hawkbit.dmf.json.model.DmfArtifactHash;
import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest;
import org.eclipse.hawkbit.dmf.json.model.DmfMetadata;
import org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
@@ -42,7 +40,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignment
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.util.IpUtil;
@@ -76,7 +73,6 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
private final AmqpMessageSenderService amqpSenderService;
private final SystemSecurityContext systemSecurityContext;
private final SystemManagement systemManagement;
private final ControllerManagement controllerManagement;
private final TargetManagement targetManagement;
private final ServiceMatcher serviceMatcher;
private final DistributionSetManagement distributionSetManagement;
@@ -95,8 +91,6 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
* for execution with system permissions
* @param systemManagement
* the systemManagement
* @param controllerManagement
* for target repository access
* @param targetManagement
* to access target information
* @param serviceMatcher
@@ -108,15 +102,14 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
protected AmqpMessageDispatcherService(final RabbitTemplate rabbitTemplate,
final AmqpMessageSenderService amqpSenderService, final ArtifactUrlHandler artifactUrlHandler,
final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement,
final ControllerManagement controllerManagement, final TargetManagement targetManagement,
final ServiceMatcher serviceMatcher, final DistributionSetManagement distributionSetManagement,
final TargetManagement targetManagement, final ServiceMatcher serviceMatcher,
final DistributionSetManagement distributionSetManagement,
final SoftwareModuleManagement softwareModuleManagement) {
super(rabbitTemplate);
this.artifactUrlHandler = artifactUrlHandler;
this.amqpSenderService = amqpSenderService;
this.systemSecurityContext = systemSecurityContext;
this.systemManagement = systemManagement;
this.controllerManagement = controllerManagement;
this.targetManagement = targetManagement;
this.serviceMatcher = serviceMatcher;
this.distributionSetManagement = distributionSetManagement;
@@ -151,7 +144,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
targetManagement.getByControllerID(assignedEvent.getActions().keySet())
.forEach(target -> sendUpdateMessageToTarget(assignedEvent.getTenant(), target,
assignedEvent.getActions().get(target.getControllerId()), modules));
assignedEvent.getActions().get(target.getControllerId()), modules,
assignedEvent.isMaintenanceWindowAvailable()));
});
}
@@ -161,25 +155,15 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
* valid maintenance window available or not based on defined maintenance
* schedule. In case of no maintenance schedule or if there is a valid
* window available, the topic {@link EventTopic#DOWNLOAD_AND_INSTALL} is
* returned else {@link EventTopic#DOWNLOAD_AND_SKIP} is returned.
* returned else {@link EventTopic#DOWNLOAD} is returned.
*
* @param target
* for which to find the event type
*
* @return {@link EventTopic} to use for message.
*/
EventTopic getEventTypeForTarget(Target target) {
Optional<Action> action = controllerManagement.findOldestActiveActionByTarget(target.getControllerId());
if (action.isPresent()) {
if (action.get().isMaintenanceWindowAvailable()) {
return EventTopic.DOWNLOAD_AND_INSTALL;
} else {
return EventTopic.DOWNLOAD_AND_SKIP;
}
}
return EventTopic.DOWNLOAD_AND_INSTALL;
private static EventTopic getEventTypeForTarget(final boolean maintenanceWindowAvailable) {
return maintenanceWindowAvailable ? EventTopic.DOWNLOAD_AND_INSTALL : EventTopic.DOWNLOAD;
}
/**
@@ -216,7 +200,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
}
protected void sendUpdateMessageToTarget(final String tenant, final Target target, final Long actionId,
final Map<SoftwareModule, List<SoftwareModuleMetadata>> modules) {
final Map<SoftwareModule, List<SoftwareModuleMetadata>> modules, final boolean maintenanceWindowAvailable) {
final URI targetAdress = target.getAddress();
if (!IpUtil.isAmqpUri(targetAdress)) {
@@ -236,7 +220,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
});
final Message message = getMessageConverter().toMessage(downloadAndUpdateRequest,
createConnectorMessagePropertiesEvent(tenant, target.getControllerId(), getEventTypeForTarget(target)));
createConnectorMessagePropertiesEvent(tenant, target.getControllerId(),
getEventTypeForTarget(maintenanceWindowAvailable)));
amqpSenderService.sendMessage(message, targetAdress);
}

View File

@@ -102,8 +102,9 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
* @return a message if <null> no message is send back to sender
*/
@RabbitListener(queues = "${hawkbit.dmf.rabbitmq.receiverQueue:dmf_receiver}", containerFactory = "listenerContainerFactory")
public Message onMessage(final Message message, @Header(MessageHeaderKey.TYPE) final String type,
@Header(MessageHeaderKey.TENANT) final String tenant) {
public Message onMessage(final Message message,
@Header(name = MessageHeaderKey.TYPE, required = false) final String type,
@Header(name = MessageHeaderKey.TENANT, required = false) final String tenant) {
return onMessage(message, type, tenant, getRabbitTemplate().getConnectionFactory().getVirtualHost());
}
@@ -121,6 +122,9 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
* @return the rpc message back to supplier.
*/
public Message onMessage(final Message message, final String type, final String tenant, final String virtualHost) {
if (StringUtils.isEmpty(type) || StringUtils.isEmpty(tenant)) {
throw new AmqpRejectAndDontRequeueException("Invalid message! tenant and type header are mandatory!");
}
final SecurityContext oldContext = SecurityContextHolder.getContext();
try {
@@ -215,7 +219,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
action.getDistributionSet().getModules().forEach(module -> modules.put(module, metadata.get(module.getId())));
amqpMessageDispatcherService.sendUpdateMessageToTarget(action.getTenant(), action.getTarget(), action.getId(),
modules);
modules, action.isMaintenanceWindowAvailable());
}
/**
@@ -282,6 +286,9 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
&& message.getMessageProperties().getCorrelationId().length > 0;
}
// Exception squid:MethodCyclomaticComplexity - false positive, is a simple
// mapping
@SuppressWarnings("squid:MethodCyclomaticComplexity")
private Status mapStatus(final Message message, final DmfActionUpdateStatus actionUpdateStatus,
final Action action) {
Status status = null;
@@ -311,7 +318,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
status = Status.DOWNLOADED;
break;
case CANCEL_REJECTED:
status = hanldeCancelRejectedState(message, action);
status = handleCancelRejectedState(message, action);
break;
default:
logAndThrowMessageError(message, "Status for action does not exisit.");
@@ -320,14 +327,13 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
return status;
}
private Status hanldeCancelRejectedState(final Message message, final Action action) {
private Status handleCancelRejectedState(final Message message, final Action action) {
if (action.isCancelingOrCanceled()) {
return Status.CANCEL_REJECTED;
}
logAndThrowMessageError(message,
"Cancel rejected message is not allowed, if action is on state: " + action.getStatus());
return null;
}
private static String convertCorrelationId(final Message message) {

View File

@@ -111,8 +111,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
when(systemManagement.getTenantMetadata()).thenReturn(tenantMetaData);
amqpMessageDispatcherService = new AmqpMessageDispatcherService(rabbitTemplate, senderService,
artifactUrlHandlerMock, systemSecurityContext, systemManagement, controllerManagement, targetManagement,
serviceMatcher, distributionSetManagement, softwareModuleManagement);
artifactUrlHandlerMock, systemSecurityContext, systemManagement, targetManagement, serviceMatcher,
distributionSetManagement, softwareModuleManagement);
}

View File

@@ -11,6 +11,7 @@ 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.Mockito.mock;
@@ -420,7 +421,7 @@ public class AmqpMessageHandlerServiceTest {
final ArgumentCaptor<Long> actionIdCaptor = ArgumentCaptor.forClass(Long.class);
verify(amqpMessageDispatcherServiceMock, times(1)).sendUpdateMessageToTarget(tenantCaptor.capture(),
targetCaptor.capture(), actionIdCaptor.capture(), any(Map.class));
targetCaptor.capture(), actionIdCaptor.capture(), any(Map.class), anyBoolean());
final String tenant = tenantCaptor.getValue();
final String controllerId = targetCaptor.getValue().getControllerId();
final Long actionId = actionIdCaptor.getValue();

View File

@@ -48,16 +48,59 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AmqpServiceInte
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) })
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void sendDownloadAndInstallStatus() {
final String controllerId = TARGET_PREFIX + "sendDownloadAndInstallStatus";
registerTargetAndAssignDistributionSet(controllerId);
createAndSendTarget(controllerId, TENANT_EXIST);
waitUntilTargetStatusIsPending(controllerId);
assertDownloadAndInstallMessage(getDistributionSet().getModules(), controllerId);
}
@Test
@Description("Verify that a distribution assignment sends a download message with window configured but before maintenance window start time.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void sendDownloadStatusBeforeMaintenanceWindowStartTime() {
final String controllerId = TARGET_PREFIX + "sendDownloadStatusBeforeWindowStartTime";
registerAndAssertTargetWithExistingTenant(controllerId);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
testdataFactory.addSoftwareModuleMetadata(distributionSet);
assignDistributionSetWithMaintenanceWindow(distributionSet.getId(), controllerId, getTestSchedule(2),
getTestDuration(10), getTestTimeZone());
waitUntilTargetStatusIsPending(controllerId);
assertDownloadMessage(distributionSet.getModules(), controllerId);
}
@Test
@Description("Verify that a distribution assignment sends a download and install message with window configured and during maintenance window start time.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void sendDownloadAndInstallStatusMessageDuringMaintenanceWindow() {
final String controllerId = TARGET_PREFIX + "sendDAndIStatusMessageDuringWindow";
registerAndAssertTargetWithExistingTenant(controllerId);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
testdataFactory.addSoftwareModuleMetadata(distributionSet);
assignDistributionSetWithMaintenanceWindow(distributionSet.getId(), controllerId, getTestSchedule(-5),
getTestDuration(10), getTestTimeZone());
waitUntilTargetStatusIsPending(controllerId);
assertDownloadAndInstallMessage(distributionSet.getModules(), controllerId);
}
@Test
@Description("Verify that a distribution assignment multiple times send cancel and assign events with right softwaremodules")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@@ -111,7 +154,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AmqpServiceInte
public void sendDeleteMessage() {
final String controllerId = TARGET_PREFIX + "sendDeleteMessage";
registerAndAssertTargetWithExistingTenant(controllerId, 1);
registerAndAssertTargetWithExistingTenant(controllerId);
targetManagement.deleteByControllerID(controllerId);
assertDeleteMessage(controllerId);
}
@@ -125,8 +168,6 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AmqpServiceInte
}
private void waitUntil(final Callable<Boolean> callable) {
createConditionFactory().until(() -> {
return securityRule.runAsPrivileged(callable);
});
createConditionFactory().until(() -> securityRule.runAsPrivileged(callable));
}
}

View File

@@ -386,6 +386,20 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.RUNNING, Status.RUNNING, controllerId);
}
@Test
@Description("Register a target and send an update action status (downloaded). Verfiy if the updated action status is correct.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionUpdatedEvent.class, count = 0), @Expect(type = ActionCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void downloadedActionStatus() {
final String controllerId = TARGET_PREFIX + "downloadedActionStatus";
registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.DOWNLOADED, Status.DOWNLOADED, controllerId);
}
@Test
@Description("Register a target and send a update action status (download). Verfiy if the updated action status is correct.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@@ -470,7 +484,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
final String controllerId = TARGET_PREFIX + "receiveDownLoadAndInstallMessageAfterAssignment";
// setup
createAndSendTarget(controllerId, TENANT_EXIST);
registerAndAssertTargetWithExistingTenant(controllerId);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
testdataFactory.addSoftwareModuleMetadata(distributionSet);
assignDistributionSet(distributionSet.getId(), controllerId);
@@ -483,6 +497,60 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
Mockito.verifyZeroInteractions(getDeadletterListener());
}
@Test
@Description("Verfiy receiving a download message if a deployment is done with window configured but before maintenance window start time.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) })
public void receiveDownloadMessageBeforeMaintenanceWindowStartTime() {
final String controllerId = TARGET_PREFIX + "receiveDownLoadMessageBeforeMaintenanceWindowStartTime";
// setup
registerAndAssertTargetWithExistingTenant(controllerId);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
testdataFactory.addSoftwareModuleMetadata(distributionSet);
assignDistributionSetWithMaintenanceWindow(distributionSet.getId(), controllerId, getTestSchedule(2),
getTestDuration(1), getTestTimeZone());
// test
registerSameTargetAndAssertBasedOnVersion(controllerId, 1, TargetUpdateStatus.PENDING);
// verify
assertDownloadMessage(distributionSet.getModules(), controllerId);
Mockito.verifyZeroInteractions(getDeadletterListener());
}
@Test
@Description("Verify receiving a download_and_install message if a deployment is done with window configured and during maintenance window start time.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) })
public void receiveDownloadAndInstallMessageDuringMaintenanceWindow() {
final String controllerId = TARGET_PREFIX + "receiveDownLoadAndInstallMessageDuringMaintenanceWindow";
// setup
registerAndAssertTargetWithExistingTenant(controllerId);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
testdataFactory.addSoftwareModuleMetadata(distributionSet);
assignDistributionSetWithMaintenanceWindow(distributionSet.getId(), controllerId, getTestSchedule(-5),
getTestDuration(10), getTestTimeZone());
// test
registerSameTargetAndAssertBasedOnVersion(controllerId, 1, TargetUpdateStatus.PENDING);
// verify
assertDownloadAndInstallMessage(distributionSet.getModules(), controllerId);
Mockito.verifyZeroInteractions(getDeadletterListener());
}
@Test
@Description("Verfiy receiving a cancel update message if a deployment is canceled before the target has polled the first time.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@@ -497,7 +565,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
final String controllerId = TARGET_PREFIX + "receiveCancelUpdateMessageAfterAssignmentWasCanceled";
// Setup
createAndSendTarget(controllerId, TENANT_EXIST);
registerAndAssertTargetWithExistingTenant(controllerId);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
final DistributionSetAssignmentResult distributionSetAssignmentResult = assignDistributionSet(
distributionSet.getId(), controllerId);
@@ -573,7 +641,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
final String controllerId = TARGET_PREFIX + "updateAttributes";
// setup
registerAndAssertTargetWithExistingTenant(controllerId, 1);
registerAndAssertTargetWithExistingTenant(controllerId);
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
controllerAttribute.getAttributes().put("test1", "testA");
controllerAttribute.getAttributes().put("test2", "testB");
@@ -593,7 +661,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
final String controllerId = TARGET_PREFIX + "updateAttributesWithNoThingId";
// setup
registerAndAssertTargetWithExistingTenant(controllerId, 1);
registerAndAssertTargetWithExistingTenant(controllerId);
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
controllerAttribute.getAttributes().put("test1", "testA");
controllerAttribute.getAttributes().put("test2", "testB");
@@ -618,7 +686,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
// setup
final String target = "ControllerAttributeTestTarget";
registerAndAssertTargetWithExistingTenant(target, 1);
registerAndAssertTargetWithExistingTenant(target);
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
controllerAttribute.getAttributes().put("test1", "testA");
controllerAttribute.getAttributes().put("test2", "testB");
@@ -707,8 +775,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
private void verifyOneDeadLetterMessage() {
assertEmptyReceiverQueueCount();
createConditionFactory().until(() -> {
Mockito.verify(getDeadletterListener(), Mockito.times(1)).handleMessage(Mockito.any());
});
createConditionFactory()
.until(() -> Mockito.verify(getDeadletterListener(), Mockito.times(1)).handleMessage(Mockito.any()));
}
}

View File

@@ -161,8 +161,9 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
}
protected void assertDownloadAndInstallMessage(final Set<SoftwareModule> dsModules, final String controllerId) {
final Message replyMessage = assertReplyMessageHeader(EventTopic.DOWNLOAD_AND_INSTALL, controllerId);
private void assertAssignmentMessage(final Set<SoftwareModule> dsModules, final String controllerId,
final EventTopic topic) {
final Message replyMessage = assertReplyMessageHeader(topic, controllerId);
assertAllTargetsCount(1);
final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = (DmfDownloadAndUpdateRequest) getDmfClient()
@@ -180,6 +181,14 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
assertThat(updatedTarget.getSecurityToken()).isEqualTo(downloadAndUpdateRequest.getTargetSecurityToken());
}
protected void assertDownloadAndInstallMessage(final Set<SoftwareModule> dsModules, final String controllerId) {
assertAssignmentMessage(dsModules, controllerId, EventTopic.DOWNLOAD_AND_INSTALL);
}
protected void assertDownloadMessage(final Set<SoftwareModule> dsModules, final String controllerId) {
assertAssignmentMessage(dsModules, controllerId, EventTopic.DOWNLOAD);
}
protected void createAndSendTarget(final String target, final String tenant) {
final Message message = createTargetMessage(target, tenant);
getDmfClient().send(message);
@@ -224,6 +233,10 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
return replyMessage;
}
protected void registerAndAssertTargetWithExistingTenant(final String controllerId) {
registerAndAssertTargetWithExistingTenant(controllerId, 1);
}
protected void registerAndAssertTargetWithExistingTenant(final String target,
final int existingTargetsAfterCreation) {