Remove unnecessary JsonProperty annotations (#2296)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -187,14 +188,10 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
protected DmfDownloadAndUpdateRequest createDownloadAndUpdateRequest(
|
||||
final Target target, final Long actionId,
|
||||
final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModules) {
|
||||
final DmfDownloadAndUpdateRequest request = new DmfDownloadAndUpdateRequest();
|
||||
request.setActionId(actionId);
|
||||
request.setTargetSecurityToken(systemSecurityContext.runAsSystem(target::getSecurityToken));
|
||||
|
||||
if (softwareModules != null) {
|
||||
softwareModules.entrySet().forEach(entry -> request.addSoftwareModule(convertToAmqpSoftwareModule(target, entry)));
|
||||
}
|
||||
return request;
|
||||
return new DmfDownloadAndUpdateRequest(
|
||||
actionId,
|
||||
systemSecurityContext.runAsSystem(target::getSecurityToken),
|
||||
convertToAmqpSoftwareModules(target, softwareModules));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,9 +261,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
return;
|
||||
}
|
||||
|
||||
final DmfActionRequest actionRequest = new DmfActionRequest();
|
||||
actionRequest.setActionId(actionId);
|
||||
|
||||
final DmfActionRequest actionRequest = new DmfActionRequest(actionId);
|
||||
final Message message = getMessageConverter().toMessage(
|
||||
actionRequest,
|
||||
createConnectorMessagePropertiesEvent(tenant, controllerId, EventTopic.CANCEL_DOWNLOAD));
|
||||
@@ -275,25 +270,15 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
protected DmfTarget convertToDmfTarget(final Target target, final Long actionId) {
|
||||
final DmfTarget dmfTarget = new DmfTarget();
|
||||
dmfTarget.setActionId(actionId);
|
||||
dmfTarget.setControllerId(target.getControllerId());
|
||||
dmfTarget.setTargetSecurityToken(systemSecurityContext.runAsSystem(target::getSecurityToken));
|
||||
return dmfTarget;
|
||||
return new DmfTarget(actionId, target.getControllerId(), systemSecurityContext.runAsSystem(target::getSecurityToken));
|
||||
}
|
||||
|
||||
protected DmfConfirmRequest createConfirmRequest(
|
||||
final Target target, final Long actionId, final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModules) {
|
||||
final DmfConfirmRequest request = new DmfConfirmRequest();
|
||||
request.setActionId(actionId);
|
||||
request.setTargetSecurityToken(systemSecurityContext.runAsSystem(target::getSecurityToken));
|
||||
|
||||
//Software modules can be filtered in the future exposing only the needed.
|
||||
if (softwareModules != null) {
|
||||
softwareModules.entrySet().forEach(entry ->
|
||||
request.addSoftwareModule(convertToAmqpSoftwareModule(target, entry)));
|
||||
}
|
||||
return request;
|
||||
return new DmfConfirmRequest(
|
||||
actionId,
|
||||
systemSecurityContext.runAsSystem(target::getSecurityToken),
|
||||
convertToAmqpSoftwareModules(target, softwareModules));
|
||||
}
|
||||
|
||||
void sendMultiActionRequestToTarget(
|
||||
@@ -304,18 +289,21 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
return;
|
||||
}
|
||||
|
||||
final DmfMultiActionRequest multiActionRequest = new DmfMultiActionRequest();
|
||||
actions.forEach(action -> {
|
||||
final DmfActionRequest actionRequest = createDmfActionRequest(
|
||||
target, action,
|
||||
action.getDistributionSet().getModules().stream()
|
||||
.collect(Collectors.toMap(Function.identity(), module -> {
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = getSoftwareModuleMetaData.apply(module);
|
||||
return softwareModuleMetadata == null ? Collections.emptyList() : softwareModuleMetadata;
|
||||
})));
|
||||
final int weight = deploymentManagement.getWeightConsideringDefault(action);
|
||||
multiActionRequest.addElement(getEventTypeForAction(action), actionRequest, weight);
|
||||
});
|
||||
final DmfMultiActionRequest multiActionRequest = new DmfMultiActionRequest(
|
||||
actions.stream()
|
||||
.map(action -> {
|
||||
final DmfActionRequest actionRequest = createDmfActionRequest(
|
||||
target, action,
|
||||
action.getDistributionSet().getModules().stream()
|
||||
.collect(Collectors.toMap(Function.identity(), module -> {
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = getSoftwareModuleMetaData.apply(
|
||||
module);
|
||||
return softwareModuleMetadata == null ? Collections.emptyList() : softwareModuleMetadata;
|
||||
})));
|
||||
final int weight = deploymentManagement.getWeightConsideringDefault(action);
|
||||
return new DmfMultiActionRequest.DmfMultiActionElement(getEventTypeForAction(action), actionRequest, weight);
|
||||
})
|
||||
.toList());
|
||||
|
||||
final Message message = getMessageConverter().toMessage(
|
||||
multiActionRequest,
|
||||
@@ -323,12 +311,6 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
amqpSenderService.sendMessage(message, targetAddress);
|
||||
}
|
||||
|
||||
private static DmfActionRequest createPlainActionRequest(final Action action) {
|
||||
final DmfActionRequest actionRequest = new DmfActionRequest();
|
||||
actionRequest.setActionId(action.getId());
|
||||
return actionRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the type of event depending on whether the action is a DOWNLOAD_ONLY action or if it has a 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,
|
||||
@@ -488,7 +470,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
final Target target, final Action action,
|
||||
final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModules) {
|
||||
if (action.isCancelingOrCanceled()) {
|
||||
return createPlainActionRequest(action);
|
||||
return new DmfActionRequest(action.getId());
|
||||
} else if (action.isWaitingConfirmation()) {
|
||||
return createConfirmRequest(target, action.getId(), softwareModules);
|
||||
}
|
||||
@@ -553,21 +535,24 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
amqpSenderService.sendMessage(message, URI.create(targetAddress));
|
||||
}
|
||||
|
||||
private List<DmfSoftwareModule> convertToAmqpSoftwareModules(
|
||||
final Target target, final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModules) {
|
||||
return Optional.ofNullable(softwareModules)
|
||||
.map(Map::entrySet)
|
||||
.map(Set::stream)
|
||||
.map(stream -> stream.map(entry -> convertToAmqpSoftwareModule(target, entry)).toList())
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private DmfSoftwareModule convertToAmqpSoftwareModule(
|
||||
final Target target,
|
||||
final Entry<SoftwareModule, List<SoftwareModuleMetadata>> entry) {
|
||||
final DmfSoftwareModule amqpSoftwareModule = new DmfSoftwareModule();
|
||||
amqpSoftwareModule.setModuleId(entry.getKey().getId());
|
||||
amqpSoftwareModule.setModuleType(entry.getKey().getType().getKey());
|
||||
amqpSoftwareModule.setModuleVersion(entry.getKey().getVersion());
|
||||
amqpSoftwareModule.setEncrypted(entry.getKey().isEncrypted() ? Boolean.TRUE : null);
|
||||
amqpSoftwareModule.setArtifacts(convertArtifacts(target, entry.getKey().getArtifacts()));
|
||||
|
||||
if (!CollectionUtils.isEmpty(entry.getValue())) {
|
||||
amqpSoftwareModule.setMetadata(convertMetadata(entry.getValue()));
|
||||
}
|
||||
|
||||
return amqpSoftwareModule;
|
||||
final Target target, final Entry<SoftwareModule, List<SoftwareModuleMetadata>> entry) {
|
||||
return new DmfSoftwareModule(
|
||||
entry.getKey().getId(),
|
||||
entry.getKey().getType().getKey(),
|
||||
entry.getKey().getVersion(),
|
||||
entry.getKey().isEncrypted() ? Boolean.TRUE : null,
|
||||
convertArtifacts(target, entry.getKey().getArtifacts()),
|
||||
CollectionUtils.isEmpty(entry.getValue()) ? null :convertMetadata(entry.getValue()));
|
||||
}
|
||||
|
||||
private List<DmfMetadata> convertMetadata(final List<SoftwareModuleMetadata> metadata) {
|
||||
@@ -584,24 +569,22 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
private DmfArtifact convertArtifact(final Target target, final Artifact localArtifact) {
|
||||
final DmfArtifact artifact = new DmfArtifact();
|
||||
|
||||
final TenantMetaData tenantMetadata = systemManagement.getTenantMetadataWithoutDetails();
|
||||
artifact.setUrls(artifactUrlHandler
|
||||
.getUrls(new URLPlaceholder(
|
||||
tenantMetadata.getTenant(), tenantMetadata.getId(), target.getControllerId(), target.getId(),
|
||||
new SoftwareData(
|
||||
localArtifact.getSoftwareModule().getId(), localArtifact.getFilename(), localArtifact.getId(),
|
||||
localArtifact.getSha1Hash())),
|
||||
ApiType.DMF)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(ArtifactUrl::getProtocol, ArtifactUrl::getRef)));
|
||||
|
||||
artifact.setFilename(localArtifact.getFilename());
|
||||
artifact.setHashes(new DmfArtifactHash(localArtifact.getSha1Hash(), localArtifact.getMd5Hash()));
|
||||
artifact.setSize(localArtifact.getSize());
|
||||
artifact.setLastModified(localArtifact.getLastModifiedAt());
|
||||
return artifact;
|
||||
return new DmfArtifact(
|
||||
localArtifact.getFilename(),
|
||||
new DmfArtifactHash(localArtifact.getSha1Hash(), localArtifact.getMd5Hash()),
|
||||
localArtifact.getSize(),
|
||||
localArtifact.getLastModifiedAt(),
|
||||
artifactUrlHandler
|
||||
.getUrls(new URLPlaceholder(
|
||||
tenantMetadata.getTenant(), tenantMetadata.getId(), target.getControllerId(), target.getId(),
|
||||
new SoftwareData(
|
||||
localArtifact.getSoftwareModule().getId(), localArtifact.getFilename(), localArtifact.getId(),
|
||||
localArtifact.getSha1Hash())),
|
||||
ApiType.DMF)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(ArtifactUrl::getProtocol, ArtifactUrl::getRef))
|
||||
);
|
||||
}
|
||||
|
||||
private Map<SoftwareModule, List<SoftwareModuleMetadata>> getSoftwareModulesWithMetadata(final DistributionSet distributionSet) {
|
||||
@@ -622,18 +605,16 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
.map(t -> convertToDmfTarget(t, actions.get(t.getControllerId()).getId()))
|
||||
.toList();
|
||||
|
||||
final DmfBatchDownloadAndUpdateRequest batchRequest = new DmfBatchDownloadAndUpdateRequest();
|
||||
batchRequest.setTimestamp(System.currentTimeMillis());
|
||||
batchRequest.addTargets(dmfTargets);
|
||||
|
||||
// due to the fact that all targets in a batch use the same set of
|
||||
// software modules we don't generate
|
||||
// target-specific urls
|
||||
// due to the fact that all targets in a batch use the same set of software modules we don't generate target-specific urls
|
||||
final Target firstTarget = targets.get(0);
|
||||
if (modules != null) {
|
||||
modules.entrySet().forEach(entry ->
|
||||
batchRequest.addSoftwareModule(convertToAmqpSoftwareModule(firstTarget, entry)));
|
||||
}
|
||||
final DmfBatchDownloadAndUpdateRequest batchRequest = new DmfBatchDownloadAndUpdateRequest(
|
||||
System.currentTimeMillis(),
|
||||
dmfTargets,
|
||||
Optional.ofNullable(modules)
|
||||
.map(Map::entrySet)
|
||||
.map(Set::stream)
|
||||
.map(stream -> stream.map(entry -> convertToAmqpSoftwareModule(firstTarget, entry)).toList())
|
||||
.orElse(null));
|
||||
|
||||
// we use only the first action when constructing message as Tenant and action type are the same
|
||||
// since all actions have the same trigger
|
||||
|
||||
@@ -454,17 +454,16 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
|
||||
final Action updatedAction;
|
||||
if (actionUpdateStatus.getActionStatus() == DmfActionStatus.CONFIRMED) {
|
||||
updatedAction = confirmationManagement.confirmAction(action.getId(),
|
||||
actionUpdateStatus.getCode().orElse(null), messages);
|
||||
updatedAction = confirmationManagement.confirmAction(action.getId(), actionUpdateStatus.getCode(), messages);
|
||||
} else if (actionUpdateStatus.getActionStatus() == DmfActionStatus.DENIED) {
|
||||
updatedAction = confirmationManagement.denyAction(action.getId(), actionUpdateStatus.getCode().orElse(null), messages);
|
||||
updatedAction = confirmationManagement.denyAction(action.getId(), actionUpdateStatus.getCode(), messages);
|
||||
} else {
|
||||
final ActionStatusCreate actionStatus = entityFactory.actionStatus().create(action.getId()).status(status).messages(messages);
|
||||
actionUpdateStatus.getCode().ifPresent(code -> {
|
||||
Optional.ofNullable(actionUpdateStatus.getCode()).ifPresent(code -> {
|
||||
actionStatus.code(code);
|
||||
actionStatus.message("Device reported status code: " + code);
|
||||
});
|
||||
updatedAction = ((Status.CANCELED == status) || (Status.CANCEL_REJECTED == status))
|
||||
updatedAction = Status.CANCELED == status || Status.CANCEL_REJECTED == status
|
||||
? controllerManagement.addCancelActionStatus(actionStatus)
|
||||
: controllerManagement.addUpdateActionStatus(actionStatus);
|
||||
}
|
||||
|
||||
@@ -174,8 +174,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final String knownThingId = "2";
|
||||
final String knownThingName = "NonDefaultTargetName";
|
||||
|
||||
final DmfCreateThing payload = new DmfCreateThing();
|
||||
payload.setName(knownThingName);
|
||||
final DmfCreateThing payload = new DmfCreateThing(knownThingName, null, null);
|
||||
|
||||
processThingCreatedMessage(knownThingId, payload);
|
||||
|
||||
@@ -190,8 +189,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final String knownThingId = "2";
|
||||
final String knownThingTypeName = "TargetTypeName";
|
||||
|
||||
final DmfCreateThing payload = new DmfCreateThing();
|
||||
payload.setType(knownThingTypeName);
|
||||
final DmfCreateThing payload = new DmfCreateThing(null, knownThingTypeName, null);
|
||||
|
||||
processThingCreatedMessage(knownThingId, payload);
|
||||
|
||||
@@ -215,12 +213,9 @@ class AmqpMessageHandlerServiceTest {
|
||||
void createThingWithAttributes() {
|
||||
final String knownThingId = "4";
|
||||
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().put("testKey1", "testValue1");
|
||||
attributeUpdate.getAttributes().put("testKey2", "testValue2");
|
||||
final DmfAttributeUpdate attributeUpdate = dmfAttributeUpdate();
|
||||
|
||||
final DmfCreateThing payload = new DmfCreateThing();
|
||||
payload.setAttributeUpdate(attributeUpdate);
|
||||
final DmfCreateThing payload = new DmfCreateThing(null, null, attributeUpdate);
|
||||
|
||||
processThingCreatedMessage(knownThingId, payload);
|
||||
|
||||
@@ -235,14 +230,9 @@ class AmqpMessageHandlerServiceTest {
|
||||
final String knownThingId = "5";
|
||||
final String knownThingName = "NonDefaultTargetName";
|
||||
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().put("testKey1", "testValue1");
|
||||
attributeUpdate.getAttributes().put("testKey2", "testValue2");
|
||||
attributeUpdate.setMode(DmfUpdateMode.REPLACE);
|
||||
|
||||
final DmfCreateThing payload = new DmfCreateThing();
|
||||
payload.setName(knownThingName);
|
||||
payload.setAttributeUpdate(attributeUpdate);
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate(
|
||||
Map.of("testKey1", "testValue1", "testKey2", "testValue2"), DmfUpdateMode.REPLACE);
|
||||
final DmfCreateThing payload = new DmfCreateThing(knownThingName, null, attributeUpdate);
|
||||
|
||||
processThingCreatedMessage(knownThingId, payload);
|
||||
|
||||
@@ -259,9 +249,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_ATTRIBUTES");
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().put("testKey1", "testValue1");
|
||||
attributeUpdate.getAttributes().put("testKey2", "testValue2");
|
||||
final DmfAttributeUpdate attributeUpdate = dmfAttributeUpdate();
|
||||
|
||||
final Message message = createMessage(attributeUpdate, messageProperties);
|
||||
|
||||
@@ -281,9 +269,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_ATTRIBUTES");
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().put("testKey1", "testValue1");
|
||||
attributeUpdate.getAttributes().put("testKey2", "testValue2");
|
||||
DmfAttributeUpdate attributeUpdate = dmfAttributeUpdate();
|
||||
|
||||
when(controllerManagementMock.updateControllerAttributes(targetIdCaptor.capture(), attributesCaptor.capture(),
|
||||
modeCaptor.capture())).thenReturn(null);
|
||||
@@ -296,27 +282,36 @@ class AmqpMessageHandlerServiceTest {
|
||||
assertThingAttributesModeCapturedField(null);
|
||||
|
||||
// send a message which specifies update mode MERGE
|
||||
attributeUpdate.setMode(DmfUpdateMode.MERGE);
|
||||
attributeUpdate = dmfAttributeUpdate(DmfUpdateMode.MERGE);
|
||||
message = createMessage(attributeUpdate, messageProperties);
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST);
|
||||
// verify that the update mode is converted and forwarded as expected
|
||||
assertThingAttributesModeCapturedField(UpdateMode.MERGE);
|
||||
|
||||
// send a message which specifies update mode REPLACE
|
||||
attributeUpdate.setMode(DmfUpdateMode.REPLACE);
|
||||
attributeUpdate = dmfAttributeUpdate(DmfUpdateMode.REPLACE);
|
||||
message = createMessage(attributeUpdate, messageProperties);
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST);
|
||||
// verify that the update mode is converted and forwarded as expected
|
||||
assertThingAttributesModeCapturedField(UpdateMode.REPLACE);
|
||||
|
||||
// send a message which specifies update mode REMOVE
|
||||
attributeUpdate.setMode(DmfUpdateMode.REMOVE);
|
||||
attributeUpdate = dmfAttributeUpdate(DmfUpdateMode.REMOVE);
|
||||
message = createMessage(attributeUpdate, messageProperties);
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST);
|
||||
// verify that the update mode is converted and forwarded as expected
|
||||
assertThingAttributesModeCapturedField(UpdateMode.REMOVE);
|
||||
}
|
||||
|
||||
private static DmfAttributeUpdate dmfAttributeUpdate() {
|
||||
return dmfAttributeUpdate(null);
|
||||
}
|
||||
|
||||
private static DmfAttributeUpdate dmfAttributeUpdate(final DmfUpdateMode mode) {
|
||||
return new DmfAttributeUpdate(
|
||||
Map.of("testKey1", "testValue1", "testKey2", "testValue2"), mode);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the creation of a thing without a 'reply to' header in message.")
|
||||
void createThingWithoutReplyTo() {
|
||||
@@ -470,7 +465,6 @@ class AmqpMessageHandlerServiceTest {
|
||||
@Test
|
||||
@Description("Test feedback code is persisted in messages when provided with DmfActionUpdateStatus")
|
||||
void feedBackCodeIsPersistedInMessages() throws IllegalAccessException {
|
||||
|
||||
// Mock
|
||||
final Action action = createActionWithTarget(22L);
|
||||
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.of(action));
|
||||
@@ -483,23 +477,22 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
|
||||
|
||||
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(23L, DmfActionStatus.RUNNING);
|
||||
actionUpdateStatus.setSoftwareModuleId(Long.valueOf(2));
|
||||
actionUpdateStatus.setCode(12);
|
||||
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(
|
||||
23L, DmfActionStatus.RUNNING, null, 2L, null, 12);
|
||||
|
||||
final Message message = createMessage(actionUpdateStatus, messageProperties);
|
||||
|
||||
// test
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST);
|
||||
|
||||
final ArgumentCaptor<ActionStatusCreate> actionPropertiesCaptor = ArgumentCaptor
|
||||
.forClass(ActionStatusCreate.class);
|
||||
final ArgumentCaptor<ActionStatusCreate> actionPropertiesCaptor = ArgumentCaptor.forClass(ActionStatusCreate.class);
|
||||
|
||||
verify(controllerManagementMock, times(1)).addUpdateActionStatus(actionPropertiesCaptor.capture());
|
||||
|
||||
final JpaActionStatus jpaActionStatus = (JpaActionStatus) actionPropertiesCaptor.getValue().build();
|
||||
assertThat(jpaActionStatus.getCode()).as("Action status for reported code is missing").contains(12);
|
||||
assertThat(jpaActionStatus.getMessages()).as("Action status message for reported code is missing")
|
||||
assertThat(jpaActionStatus.getMessages())
|
||||
.as("Action status message for reported code is missing")
|
||||
.contains("Device reported status code: 12");
|
||||
}
|
||||
|
||||
@@ -542,10 +535,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_AUTO_CONFIRM");
|
||||
final DmfAutoConfirmation autoConfirmation = new DmfAutoConfirmation();
|
||||
autoConfirmation.setEnabled(true);
|
||||
autoConfirmation.setInitiator(initiator);
|
||||
autoConfirmation.setRemark(remark);
|
||||
final DmfAutoConfirmation autoConfirmation = new DmfAutoConfirmation(true, initiator, remark);
|
||||
|
||||
final Message message = createMessage(autoConfirmation, messageProperties);
|
||||
|
||||
@@ -569,7 +559,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_AUTO_CONFIRM");
|
||||
final DmfAutoConfirmation autoConfirmation = new DmfAutoConfirmation();
|
||||
final DmfAutoConfirmation autoConfirmation = new DmfAutoConfirmation(false, null, null);
|
||||
|
||||
final Message message = createMessage(autoConfirmation, messageProperties);
|
||||
|
||||
@@ -649,9 +639,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
}
|
||||
|
||||
private DmfActionUpdateStatus createActionUpdateStatus(final DmfActionStatus status, final Long id) {
|
||||
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(id, status);
|
||||
actionUpdateStatus.setSoftwareModuleId(Long.valueOf(2));
|
||||
return actionUpdateStatus;
|
||||
return new DmfActionUpdateStatus(id, status, null, 2L, null, null);
|
||||
}
|
||||
|
||||
private MessageProperties createMessageProperties(final MessageType type) {
|
||||
|
||||
@@ -13,6 +13,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
@@ -100,12 +102,7 @@ class BaseAmqpServiceTest {
|
||||
}
|
||||
|
||||
private DmfActionUpdateStatus createActionStatus() {
|
||||
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.RUNNING);
|
||||
actionUpdateStatus.setCode(2);
|
||||
actionUpdateStatus.setSoftwareModuleId(2L);
|
||||
actionUpdateStatus.addMessage("Message 1");
|
||||
actionUpdateStatus.addMessage("Message 2");
|
||||
return actionUpdateStatus;
|
||||
return new DmfActionUpdateStatus(1L, DmfActionStatus.RUNNING, null, 2L, List.of("Message 1", "Message 2"), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -306,14 +306,9 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
|
||||
DmfCreateThing payload = null;
|
||||
if (!StringUtils.isEmpty(name) || !CollectionUtils.isEmpty(attributes)) {
|
||||
payload = new DmfCreateThing();
|
||||
payload.setName(name);
|
||||
|
||||
if (!CollectionUtils.isEmpty(attributes)) {
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().putAll(attributes);
|
||||
payload.setAttributeUpdate(attributeUpdate);
|
||||
}
|
||||
payload = new DmfCreateThing(
|
||||
name, null,
|
||||
CollectionUtils.isEmpty(attributes) ? null : new DmfAttributeUpdate(attributes, null));
|
||||
}
|
||||
|
||||
return createMessage(payload, messageProperties);
|
||||
@@ -330,7 +325,8 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
|
||||
protected void createAndSendActionStatusUpdateMessage(final String target, final long actionId,
|
||||
final DmfActionStatus status) {
|
||||
final DmfActionUpdateStatus dmfActionUpdateStatus = new DmfActionUpdateStatus(actionId, status, System.currentTimeMillis());
|
||||
final DmfActionUpdateStatus dmfActionUpdateStatus = new DmfActionUpdateStatus(
|
||||
actionId, status, System.currentTimeMillis(), null, null, null);
|
||||
|
||||
final Message eventMessage = createUpdateActionEventMessage(dmfActionUpdateStatus);
|
||||
eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.THING_ID, target);
|
||||
|
||||
@@ -729,9 +729,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
|
||||
// setup
|
||||
registerAndAssertTargetWithExistingTenant(controllerId);
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
|
||||
controllerAttribute.getAttributes().put("test1", "testA");
|
||||
controllerAttribute.getAttributes().put("test2", "testB");
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate(
|
||||
Map.of("test1", "testA", "test2", "testB"), null);
|
||||
final Message createUpdateAttributesMessage = createUpdateAttributesMessage(null, TENANT_EXIST,
|
||||
controllerAttribute);
|
||||
createUpdateAttributesMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.THING_ID);
|
||||
@@ -741,7 +740,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
|
||||
// verify
|
||||
verifyOneDeadLetterMessage();
|
||||
final DmfAttributeUpdate controllerAttributeEmpty = new DmfAttributeUpdate();
|
||||
final DmfAttributeUpdate controllerAttributeEmpty = new DmfAttributeUpdate(null, null);
|
||||
assertUpdateAttributes(controllerId, controllerAttributeEmpty.getAttributes());
|
||||
}
|
||||
|
||||
@@ -754,11 +753,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
void updateAttributesWithWrongBody() {
|
||||
// setup
|
||||
registerAndAssertTargetWithExistingTenant(UPDATE_ATTR_TEST_CONTROLLER_ID);
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
|
||||
controllerAttribute.getAttributes().put("test1", "testA");
|
||||
controllerAttribute.getAttributes().put("test2", "testB");
|
||||
final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody(
|
||||
UPDATE_ATTR_TEST_CONTROLLER_ID);
|
||||
final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody( UPDATE_ATTR_TEST_CONTROLLER_ID);
|
||||
|
||||
// test
|
||||
getDmfClient().send(createUpdateAttributesMessageWrongBody);
|
||||
@@ -1051,9 +1046,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
removeAttributes.put("k1", "foo");
|
||||
removeAttributes.put("k3", "bar");
|
||||
|
||||
final DmfAttributeUpdate remove = new DmfAttributeUpdate();
|
||||
remove.setMode(DmfUpdateMode.REMOVE);
|
||||
remove.getAttributes().putAll(removeAttributes);
|
||||
final DmfAttributeUpdate remove = new DmfAttributeUpdate(removeAttributes, DmfUpdateMode.REMOVE);
|
||||
sendUpdateAttributeMessage(remove);
|
||||
|
||||
// validate
|
||||
@@ -1071,9 +1064,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
mergeAttributes.put("k1", "v1_modified_again");
|
||||
mergeAttributes.put("k4", "v4");
|
||||
|
||||
final DmfAttributeUpdate merge = new DmfAttributeUpdate();
|
||||
merge.setMode(DmfUpdateMode.MERGE);
|
||||
merge.getAttributes().putAll(mergeAttributes);
|
||||
final DmfAttributeUpdate merge = new DmfAttributeUpdate(mergeAttributes, DmfUpdateMode.MERGE);
|
||||
sendUpdateAttributeMessage(merge);
|
||||
|
||||
// validate
|
||||
@@ -1091,9 +1082,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
expectedAttributes.put("k2", "v2");
|
||||
expectedAttributes.put("k3", "v3");
|
||||
|
||||
final DmfAttributeUpdate replace = new DmfAttributeUpdate();
|
||||
replace.setMode(DmfUpdateMode.REPLACE);
|
||||
replace.getAttributes().putAll(expectedAttributes);
|
||||
final DmfAttributeUpdate replace = new DmfAttributeUpdate(expectedAttributes, DmfUpdateMode.REPLACE);
|
||||
sendUpdateAttributeMessage(replace);
|
||||
|
||||
// validate
|
||||
@@ -1107,8 +1096,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
expectedAttributes.put("k0", "v0");
|
||||
expectedAttributes.put("k1", "v1");
|
||||
|
||||
final DmfAttributeUpdate defaultUpdate = new DmfAttributeUpdate();
|
||||
defaultUpdate.getAttributes().putAll(expectedAttributes);
|
||||
final DmfAttributeUpdate defaultUpdate = new DmfAttributeUpdate(expectedAttributes, null);
|
||||
sendUpdateAttributeMessage(defaultUpdate);
|
||||
|
||||
// validate
|
||||
@@ -1135,10 +1123,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
}
|
||||
|
||||
private void sendUpdateAttributesMessageWithGivenAttributes(final String key, final String value) {
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
|
||||
controllerAttribute.getAttributes().put(key, value);
|
||||
final Message message = createUpdateAttributesMessage(UPDATE_ATTR_TEST_CONTROLLER_ID, TENANT_EXIST,
|
||||
controllerAttribute);
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate(Map.of(key, value), null);
|
||||
final Message message = createUpdateAttributesMessage(UPDATE_ATTR_TEST_CONTROLLER_ID, TENANT_EXIST, controllerAttribute);
|
||||
getDmfClient().send(message);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user