|
|
|
|
@@ -58,8 +58,12 @@ import org.eclipse.hawkbit.repository.model.Target;
|
|
|
|
|
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
|
|
|
|
import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
|
|
|
|
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
|
|
|
|
import org.eclipse.hawkbit.repository.test.util.TargetTestData;
|
|
|
|
|
import org.eclipse.hawkbit.repository.test.util.WithSpringAuthorityRule;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
|
import org.junit.jupiter.params.provider.NullSource;
|
|
|
|
|
import org.junit.jupiter.params.provider.ValueSource;
|
|
|
|
|
import org.mockito.Mockito;
|
|
|
|
|
import org.springframework.amqp.core.Message;
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
|
|
|
|
@@ -75,8 +79,11 @@ import io.qameta.allure.Story;
|
|
|
|
|
|
|
|
|
|
@Feature("Component Tests - Device Management Federation API")
|
|
|
|
|
@Story("Amqp Message Handler Service")
|
|
|
|
|
public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegrationTest {
|
|
|
|
|
class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegrationTest {
|
|
|
|
|
private static final String TARGET_PREFIX = "Dmf_hand_";
|
|
|
|
|
public static final String DMF_REGISTER_TEST_CONTROLLER_ID = "Dmf_hand_registerTargets_1";
|
|
|
|
|
public static final String DMF_ATTR_TEST_CONTROLLER_ID = "Dmf_hand_updateAttributes";
|
|
|
|
|
public static final String UPDATE_ATTR_TEST_CONTROLLER_ID = "ControllerAttributeTestTarget";
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AmqpProperties amqpProperties;
|
|
|
|
|
@@ -86,7 +93,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests DMF PING request and expected response.")
|
|
|
|
|
public void pingDmfInterface() {
|
|
|
|
|
void pingDmfInterface() {
|
|
|
|
|
final Message pingMessage = createPingMessage(CORRELATION_ID, TENANT_EXIST);
|
|
|
|
|
getDmfClient().send(pingMessage);
|
|
|
|
|
|
|
|
|
|
@@ -99,7 +106,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Description("Tests register target")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 2),
|
|
|
|
|
@Expect(type = TargetPollEvent.class, count = 3) })
|
|
|
|
|
public void registerTargets() {
|
|
|
|
|
void registerTargets() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "registerTargets";
|
|
|
|
|
registerAndAssertTargetWithExistingTenant(controllerId, 1);
|
|
|
|
|
|
|
|
|
|
@@ -114,7 +121,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Description("Tests register target with name")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) })
|
|
|
|
|
public void registerTargetWithName() {
|
|
|
|
|
void registerTargetWithName() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "registerTargetWithName";
|
|
|
|
|
final String name = "NonDefaultTargetName";
|
|
|
|
|
registerAndAssertTargetWithExistingTenant(controllerId, name, 1, TargetUpdateStatus.REGISTERED, CREATED_BY,
|
|
|
|
|
@@ -130,7 +137,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Description("Tests register target with attributes")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 2) })
|
|
|
|
|
public void registerTargetWithAttributes() {
|
|
|
|
|
void registerTargetWithAttributes() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "registerTargetWithAttributes";
|
|
|
|
|
final Map<String, String> attributes = new HashMap<>();
|
|
|
|
|
attributes.put("testKey1", "testValue1");
|
|
|
|
|
@@ -149,7 +156,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Description("Tests register target with name and attributes")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = TargetPollEvent.class, count = 2) })
|
|
|
|
|
public void registerTargetWithNameAndAttributes() {
|
|
|
|
|
void registerTargetWithNameAndAttributes() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "registerTargetWithAttributes";
|
|
|
|
|
final String name = "NonDefaultTargetName";
|
|
|
|
|
final Map<String, String> attributes = new HashMap<>();
|
|
|
|
|
@@ -166,46 +173,30 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
Mockito.verifyNoInteractions(getDeadletterListener());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@ValueSource(strings = {"", "Invalid Invalid"})
|
|
|
|
|
@NullSource
|
|
|
|
|
@Description("Tests register invalid target with empty controller id.")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void registerEmptyTarget() {
|
|
|
|
|
createAndSendThingCreated("", TENANT_EXIST);
|
|
|
|
|
assertAllTargetsCount(0);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests register invalid target with whitespace controller id.")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void registerWhitespaceTarget() {
|
|
|
|
|
createAndSendThingCreated("Invalid Invalid", TENANT_EXIST);
|
|
|
|
|
assertAllTargetsCount(0);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests register invalid target with null controller id.")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void registerInvalidNullTarget() {
|
|
|
|
|
createAndSendThingCreated(null, TENANT_EXIST);
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void shouldNotRegisterTargetsWithInvalidControllerIds(String controllerId) {
|
|
|
|
|
createAndSendThingCreated(controllerId);
|
|
|
|
|
assertAllTargetsCount(0);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests register invalid target with too long controller id")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void registerInvalidTargetWithTooLongControllerId() {
|
|
|
|
|
createAndSendThingCreated(RandomStringUtils.randomAlphabetic(Target.CONTROLLER_ID_MAX_SIZE + 1), TENANT_EXIST);
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void registerInvalidTargetWithTooLongControllerId() {
|
|
|
|
|
createAndSendThingCreated(RandomStringUtils.randomAlphabetic(Target.CONTROLLER_ID_MAX_SIZE + 1));
|
|
|
|
|
assertAllTargetsCount(0);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests null reply to property in message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void missingReplyToProperty() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void missingReplyToProperty() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "missingReplyToProperty";
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(controllerId, TENANT_EXIST);
|
|
|
|
|
createTargetMessage.getMessageProperties().setReplyTo(null);
|
|
|
|
|
@@ -217,8 +208,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests missing reply to property in message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void emptyReplyToProperty() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void emptyReplyToProperty() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "emptyReplyToProperty";
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(controllerId, TENANT_EXIST);
|
|
|
|
|
createTargetMessage.getMessageProperties().setReplyTo("");
|
|
|
|
|
@@ -230,8 +221,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests missing thing id property in message. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void missingThingIdProperty() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void missingThingIdProperty() {
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST);
|
|
|
|
|
createTargetMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.THING_ID);
|
|
|
|
|
getDmfClient().send(createTargetMessage);
|
|
|
|
|
@@ -242,8 +233,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests null thing id property in message. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void nullThingIdProperty() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void nullThingIdProperty() {
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST);
|
|
|
|
|
getDmfClient().send(createTargetMessage);
|
|
|
|
|
|
|
|
|
|
@@ -253,8 +244,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests missing tenant message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void missingTenantHeader() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void missingTenantHeader() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "missingTenantHeader";
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(controllerId, TENANT_EXIST);
|
|
|
|
|
createTargetMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.TENANT);
|
|
|
|
|
@@ -266,8 +257,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests null tenant message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void nullTenantHeader() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void nullTenantHeader() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "nullTenantHeader";
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(controllerId, null);
|
|
|
|
|
getDmfClient().send(createTargetMessage);
|
|
|
|
|
@@ -278,8 +269,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests empty tenant message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void emptyTenantHeader() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void emptyTenantHeader() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "emptyTenantHeader";
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(controllerId, "");
|
|
|
|
|
getDmfClient().send(createTargetMessage);
|
|
|
|
|
@@ -290,8 +281,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests tenant not exist. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void tenantNotExist() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void tenantNotExist() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "tenantNotExist";
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(controllerId, "TenantNotExist");
|
|
|
|
|
getDmfClient().send(createTargetMessage);
|
|
|
|
|
@@ -302,8 +293,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests missing type message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void missingTypeHeader() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void missingTypeHeader() {
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST);
|
|
|
|
|
createTargetMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.TYPE);
|
|
|
|
|
getDmfClient().send(createTargetMessage);
|
|
|
|
|
@@ -312,70 +303,28 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
assertAllTargetsCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@ValueSource(strings={"", "NotExist"})
|
|
|
|
|
@NullSource
|
|
|
|
|
@Description("Tests null type message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void nullTypeHeader() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void shouldNotCreateTargetsWithInvalidTypeInHeader(String type) {
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST);
|
|
|
|
|
createTargetMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TYPE, null);
|
|
|
|
|
createTargetMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TYPE, type);
|
|
|
|
|
getDmfClient().send(createTargetMessage);
|
|
|
|
|
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
assertAllTargetsCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests empty type message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void emptyTypeHeader() {
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST);
|
|
|
|
|
createTargetMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TYPE, "");
|
|
|
|
|
getDmfClient().send(createTargetMessage);
|
|
|
|
|
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
assertAllTargetsCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests invalid type message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void invalidTypeHeader() {
|
|
|
|
|
final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST);
|
|
|
|
|
createTargetMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TYPE, "NotExist");
|
|
|
|
|
getDmfClient().send(createTargetMessage);
|
|
|
|
|
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
assertAllTargetsCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@ValueSource(strings = {"", "NotExist"})
|
|
|
|
|
@NullSource
|
|
|
|
|
@Description("Tests null topic message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void nullTopicHeader() {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(TENANT_EXIST, "");
|
|
|
|
|
eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TOPIC, null);
|
|
|
|
|
getDmfClient().send(eventMessage);
|
|
|
|
|
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests null topic message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void emptyTopicHeader() {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(TENANT_EXIST, "");
|
|
|
|
|
eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TOPIC, "");
|
|
|
|
|
getDmfClient().send(eventMessage);
|
|
|
|
|
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests null topic message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void invalidTopicHeader() {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(TENANT_EXIST, "");
|
|
|
|
|
eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TOPIC, "NotExist");
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void shouldNotSendMessagesWithInvalidTopic(String topic) {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage("");
|
|
|
|
|
eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TOPIC, topic);
|
|
|
|
|
getDmfClient().send(eventMessage);
|
|
|
|
|
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
@@ -383,48 +332,32 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests missing topic message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void missingTopicHeader() {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(TENANT_EXIST, "");
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void missingTopicHeader() {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage("");
|
|
|
|
|
eventMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.TOPIC);
|
|
|
|
|
getDmfClient().send(eventMessage);
|
|
|
|
|
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@ValueSource(strings = { "", "Invalid Content"})
|
|
|
|
|
@NullSource
|
|
|
|
|
@Description("Tests invalid null message content. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void updateActionStatusWithNullContent() {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(TENANT_EXIST, null);
|
|
|
|
|
getDmfClient().send(eventMessage);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests invalid empty message content. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void updateActionStatusWithEmptyContent() {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(TENANT_EXIST, "");
|
|
|
|
|
getDmfClient().send(eventMessage);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests invalid json message content. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void updateActionStatusWithInvalidJsonContent() {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(TENANT_EXIST, "Invalid Content");
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void shouldMoveUpdateActionStatusWithInvalidPayloadIntoDeadLetter(String payload) {
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(payload);
|
|
|
|
|
getDmfClient().send(eventMessage);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Tests invalid topic message header. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void updateActionStatusWithInvalidActionId() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void updateActionStatusWithInvalidActionId() {
|
|
|
|
|
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.RUNNING);
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(TENANT_EXIST, actionUpdateStatus);
|
|
|
|
|
final Message eventMessage = createUpdateActionEventMessage(actionUpdateStatus);
|
|
|
|
|
getDmfClient().send(eventMessage);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
}
|
|
|
|
|
@@ -439,7 +372,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetAttributesRequestedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
public void finishActionStatus() {
|
|
|
|
|
void finishActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "finishActionStatus";
|
|
|
|
|
registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.FINISHED, Status.FINISHED, controllerId);
|
|
|
|
|
}
|
|
|
|
|
@@ -448,12 +381,12 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Description("Register a target and send a update action status (running). Verify 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 = ActionUpdatedEvent.class), @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 runningActionStatus() {
|
|
|
|
|
void runningActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "runningActionStatus";
|
|
|
|
|
registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.RUNNING, Status.RUNNING, controllerId);
|
|
|
|
|
}
|
|
|
|
|
@@ -462,12 +395,12 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Description("Register a target and send an update action status (downloaded). Verify 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 = ActionUpdatedEvent.class), @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() {
|
|
|
|
|
void downloadedActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "downloadedActionStatus";
|
|
|
|
|
registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.DOWNLOADED, Status.DOWNLOADED, controllerId);
|
|
|
|
|
}
|
|
|
|
|
@@ -481,7 +414,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@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 downloadActionStatus() {
|
|
|
|
|
void downloadActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "downloadActionStatus";
|
|
|
|
|
registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.DOWNLOAD, Status.DOWNLOAD, controllerId);
|
|
|
|
|
}
|
|
|
|
|
@@ -495,7 +428,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6),
|
|
|
|
|
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
public void errorActionStatus() {
|
|
|
|
|
void errorActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "errorActionStatus";
|
|
|
|
|
registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.ERROR, Status.ERROR, controllerId);
|
|
|
|
|
}
|
|
|
|
|
@@ -509,7 +442,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@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 warningActionStatus() {
|
|
|
|
|
void warningActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "warningActionStatus";
|
|
|
|
|
registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.WARNING, Status.WARNING, controllerId);
|
|
|
|
|
}
|
|
|
|
|
@@ -523,7 +456,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@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 retrievedActionStatus() {
|
|
|
|
|
void retrievedActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "retrievedActionStatus";
|
|
|
|
|
registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.RETRIEVED, Status.RETRIEVED, controllerId);
|
|
|
|
|
}
|
|
|
|
|
@@ -537,7 +470,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@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 cancelNotAllowActionStatus() {
|
|
|
|
|
void cancelNotAllowActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "cancelNotAllowActionStatus";
|
|
|
|
|
registerTargetAndSendActionStatus(DmfActionStatus.CANCELED, controllerId);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
@@ -552,7 +485,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@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 receiveDownLoadAndInstallMessageAfterAssignment() {
|
|
|
|
|
void receiveDownLoadAndInstallMessageAfterAssignment() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "receiveDownLoadAndInstallMessageAfterAssignment";
|
|
|
|
|
|
|
|
|
|
// setup
|
|
|
|
|
@@ -578,7 +511,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@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() {
|
|
|
|
|
void receiveDownloadMessageBeforeMaintenanceWindowStartTime() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "receiveDownLoadMessageBeforeMaintenanceWindowStartTime";
|
|
|
|
|
|
|
|
|
|
// setup
|
|
|
|
|
@@ -605,7 +538,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@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() {
|
|
|
|
|
void receiveDownloadAndInstallMessageDuringMaintenanceWindow() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "receiveDownLoadAndInstallMessageDuringMaintenanceWindow";
|
|
|
|
|
|
|
|
|
|
// setup
|
|
|
|
|
@@ -633,7 +566,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Expect(type = CancelTargetAssignmentEvent.class, count = 1),
|
|
|
|
|
@Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetPollEvent.class, count = 2) })
|
|
|
|
|
public void receiveCancelUpdateMessageAfterAssignmentWasCanceled() {
|
|
|
|
|
void receiveCancelUpdateMessageAfterAssignmentWasCanceled() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "receiveCancelUpdateMessageAfterAssignmentWasCanceled";
|
|
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
|
@@ -661,11 +594,11 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Expect(type = CancelTargetAssignmentEvent.class, count = 1),
|
|
|
|
|
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
public void actionNotExists() {
|
|
|
|
|
void actionNotExists() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "actionNotExists";
|
|
|
|
|
|
|
|
|
|
final Long actionId = registerTargetAndCancelActionId(controllerId);
|
|
|
|
|
final Long actionNotExist = actionId + 1;
|
|
|
|
|
final long actionNotExist = actionId + 1;
|
|
|
|
|
|
|
|
|
|
createAndSendActionStatusUpdateMessage(controllerId, actionNotExist, DmfActionStatus.CANCELED);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
@@ -680,7 +613,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@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 canceledRejectedNotAllowActionStatus() {
|
|
|
|
|
void canceledRejectedNotAllowActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "canceledRejectedNotAllowActionStatus";
|
|
|
|
|
registerTargetAndSendActionStatus(DmfActionStatus.CANCEL_REJECTED, controllerId);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
@@ -696,7 +629,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@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 canceledRejectedActionStatus() {
|
|
|
|
|
void canceledRejectedActionStatus() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "canceledRejectedActionStatus";
|
|
|
|
|
|
|
|
|
|
final Long actionId = registerTargetAndCancelActionId(controllerId);
|
|
|
|
|
@@ -709,35 +642,36 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Description("Verify that sending an update controller attribute message to an existing target works. Verify that different update modes (merge, replace, remove) can be used.")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 4), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
public void updateAttributesWithDifferentUpdateModes() {
|
|
|
|
|
void updateAttributesWithDifferentUpdateModes() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "updateAttributes";
|
|
|
|
|
|
|
|
|
|
// setup
|
|
|
|
|
registerAndAssertTargetWithExistingTenant(controllerId);
|
|
|
|
|
|
|
|
|
|
// no update mode specified
|
|
|
|
|
updateAttributesWithoutUpdateMode(controllerId);
|
|
|
|
|
updateAttributesWithoutUpdateMode();
|
|
|
|
|
|
|
|
|
|
// update mode REPLACE
|
|
|
|
|
updateAttributesWithUpdateModeReplace(controllerId);
|
|
|
|
|
updateAttributesWithUpdateModeReplace();
|
|
|
|
|
|
|
|
|
|
// update mode MERGE
|
|
|
|
|
updateAttributesWithUpdateModeMerge(controllerId);
|
|
|
|
|
updateAttributesWithUpdateModeMerge();
|
|
|
|
|
|
|
|
|
|
// update mode REMOVE
|
|
|
|
|
updateAttributesWithUpdateModeRemove(controllerId);
|
|
|
|
|
updateAttributesWithUpdateModeRemove();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Step
|
|
|
|
|
private void updateAttributesWithUpdateModeRemove(final String controllerId) {
|
|
|
|
|
private void updateAttributesWithUpdateModeRemove() {
|
|
|
|
|
|
|
|
|
|
// assemble the expected attributes
|
|
|
|
|
final Map<String, String> expectedAttributes = targetManagement.getControllerAttributes(controllerId);
|
|
|
|
|
final Map<String, String> expectedAttributes = targetManagement
|
|
|
|
|
.getControllerAttributes(DMF_ATTR_TEST_CONTROLLER_ID);
|
|
|
|
|
expectedAttributes.remove("k1");
|
|
|
|
|
expectedAttributes.remove("k3");
|
|
|
|
|
|
|
|
|
|
// send a update message with update mode
|
|
|
|
|
// send an update message with update mode
|
|
|
|
|
final Map<String, String> removeAttributes = new HashMap<>();
|
|
|
|
|
removeAttributes.put("k1", "foo");
|
|
|
|
|
removeAttributes.put("k3", "bar");
|
|
|
|
|
@@ -745,19 +679,19 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
final DmfAttributeUpdate remove = new DmfAttributeUpdate();
|
|
|
|
|
remove.setMode(DmfUpdateMode.REMOVE);
|
|
|
|
|
remove.getAttributes().putAll(removeAttributes);
|
|
|
|
|
sendUpdateAttributeMessage(controllerId, TENANT_EXIST, remove);
|
|
|
|
|
sendUpdateAttributeMessage(remove);
|
|
|
|
|
|
|
|
|
|
// validate
|
|
|
|
|
assertUpdateAttributes(controllerId, expectedAttributes);
|
|
|
|
|
assertUpdateAttributes(DMF_ATTR_TEST_CONTROLLER_ID, expectedAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Step
|
|
|
|
|
private void updateAttributesWithUpdateModeMerge(final String controllerId) {
|
|
|
|
|
|
|
|
|
|
private void updateAttributesWithUpdateModeMerge() {
|
|
|
|
|
// get the current attributes
|
|
|
|
|
final Map<String, String> attributes = new HashMap<>(targetManagement.getControllerAttributes(controllerId));
|
|
|
|
|
final Map<String, String> attributes = new HashMap<>(
|
|
|
|
|
targetManagement.getControllerAttributes(DMF_ATTR_TEST_CONTROLLER_ID));
|
|
|
|
|
|
|
|
|
|
// send a update message with update mode MERGE
|
|
|
|
|
// send an update message with update mode MERGE
|
|
|
|
|
final Map<String, String> mergeAttributes = new HashMap<>();
|
|
|
|
|
mergeAttributes.put("k1", "v1_modified_again");
|
|
|
|
|
mergeAttributes.put("k4", "v4");
|
|
|
|
|
@@ -765,19 +699,18 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
final DmfAttributeUpdate merge = new DmfAttributeUpdate();
|
|
|
|
|
merge.setMode(DmfUpdateMode.MERGE);
|
|
|
|
|
merge.getAttributes().putAll(mergeAttributes);
|
|
|
|
|
sendUpdateAttributeMessage(controllerId, TENANT_EXIST, merge);
|
|
|
|
|
sendUpdateAttributeMessage(merge);
|
|
|
|
|
|
|
|
|
|
// validate
|
|
|
|
|
final Map<String, String> expectedAttributes = new HashMap<>();
|
|
|
|
|
expectedAttributes.putAll(attributes);
|
|
|
|
|
expectedAttributes.putAll(mergeAttributes);
|
|
|
|
|
assertUpdateAttributes(controllerId, expectedAttributes);
|
|
|
|
|
assertUpdateAttributes(DMF_ATTR_TEST_CONTROLLER_ID, expectedAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Step
|
|
|
|
|
private void updateAttributesWithUpdateModeReplace(final String controllerId) {
|
|
|
|
|
|
|
|
|
|
// send a update message with update mode REPLACE
|
|
|
|
|
private void updateAttributesWithUpdateModeReplace() {
|
|
|
|
|
// send an update message with update mode REPLACE
|
|
|
|
|
final Map<String, String> expectedAttributes = new HashMap<>();
|
|
|
|
|
expectedAttributes.put("k1", "v1_modified");
|
|
|
|
|
expectedAttributes.put("k2", "v2");
|
|
|
|
|
@@ -786,33 +719,32 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
final DmfAttributeUpdate replace = new DmfAttributeUpdate();
|
|
|
|
|
replace.setMode(DmfUpdateMode.REPLACE);
|
|
|
|
|
replace.getAttributes().putAll(expectedAttributes);
|
|
|
|
|
sendUpdateAttributeMessage(controllerId, TENANT_EXIST, replace);
|
|
|
|
|
sendUpdateAttributeMessage(replace);
|
|
|
|
|
|
|
|
|
|
// validate
|
|
|
|
|
assertUpdateAttributes(controllerId, expectedAttributes);
|
|
|
|
|
assertUpdateAttributes(DMF_ATTR_TEST_CONTROLLER_ID, expectedAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Step
|
|
|
|
|
private void updateAttributesWithoutUpdateMode(final String controllerId) {
|
|
|
|
|
|
|
|
|
|
// send a update message which does not specify an update mode
|
|
|
|
|
private void updateAttributesWithoutUpdateMode() {
|
|
|
|
|
// send an update message which does not specify an update mode
|
|
|
|
|
final Map<String, String> expectedAttributes = new HashMap<>();
|
|
|
|
|
expectedAttributes.put("k0", "v0");
|
|
|
|
|
expectedAttributes.put("k1", "v1");
|
|
|
|
|
|
|
|
|
|
final DmfAttributeUpdate defaultUpdate = new DmfAttributeUpdate();
|
|
|
|
|
defaultUpdate.getAttributes().putAll(expectedAttributes);
|
|
|
|
|
sendUpdateAttributeMessage(controllerId, TENANT_EXIST, defaultUpdate);
|
|
|
|
|
sendUpdateAttributeMessage(defaultUpdate);
|
|
|
|
|
|
|
|
|
|
// validate
|
|
|
|
|
assertUpdateAttributes(controllerId, expectedAttributes);
|
|
|
|
|
assertUpdateAttributes(DMF_ATTR_TEST_CONTROLLER_ID, expectedAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Verify that sending an update controller attribute message with no thingid header to an existing target does not work.")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 0), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
public void updateAttributesWithNoThingId() {
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
void updateAttributesWithNoThingId() {
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "updateAttributesWithNoThingId";
|
|
|
|
|
|
|
|
|
|
// setup
|
|
|
|
|
@@ -836,17 +768,15 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Verify that sending an update controller attribute message with invalid body to an existing target does not work.")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 0), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
public void updateAttributesWithWrongBody() {
|
|
|
|
|
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
void updateAttributesWithWrongBody() {
|
|
|
|
|
// setup
|
|
|
|
|
final String target = "ControllerAttributeTestTarget";
|
|
|
|
|
registerAndAssertTargetWithExistingTenant(target);
|
|
|
|
|
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(target,
|
|
|
|
|
TENANT_EXIST);
|
|
|
|
|
final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody(
|
|
|
|
|
UPDATE_ATTR_TEST_CONTROLLER_ID);
|
|
|
|
|
|
|
|
|
|
// test
|
|
|
|
|
getDmfClient().send(createUpdateAttributesMessageWrongBody);
|
|
|
|
|
@@ -857,20 +787,12 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Verifies that sending an UPDATE_ATTRIBUTES message with invalid attributes is handled correctly.")
|
|
|
|
|
public void updateAttributesWithInvalidValues() {
|
|
|
|
|
// setup
|
|
|
|
|
final String target = "ControllerAttributeTestTarget";
|
|
|
|
|
registerAndAssertTargetWithExistingTenant(target);
|
|
|
|
|
final String keyTooLong = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_KEY_SIZE + 1);
|
|
|
|
|
final String keyValid = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_KEY_SIZE);
|
|
|
|
|
final String valueTooLong = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE + 1);
|
|
|
|
|
final String valueValid = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE);
|
|
|
|
|
void updateAttributesWithInvalidValues() {
|
|
|
|
|
registerAndAssertTargetWithExistingTenant(UPDATE_ATTR_TEST_CONTROLLER_ID);
|
|
|
|
|
|
|
|
|
|
sendUpdateAttributesMessageWithGivenAttributes(target, keyTooLong, valueValid);
|
|
|
|
|
|
|
|
|
|
sendUpdateAttributesMessageWithGivenAttributes(target, keyTooLong, valueTooLong);
|
|
|
|
|
|
|
|
|
|
sendUpdateAttributesMessageWithGivenAttributes(target, keyValid, valueTooLong);
|
|
|
|
|
sendUpdateAttributesMessageWithGivenAttributes(TargetTestData.ATTRIBUTE_KEY_TOO_LONG, TargetTestData.ATTRIBUTE_VALUE_VALID);
|
|
|
|
|
sendUpdateAttributesMessageWithGivenAttributes(TargetTestData.ATTRIBUTE_KEY_TOO_LONG, TargetTestData.ATTRIBUTE_VALUE_TOO_LONG);
|
|
|
|
|
sendUpdateAttributesMessageWithGivenAttributes(TargetTestData.ATTRIBUTE_KEY_VALID, TargetTestData.ATTRIBUTE_VALUE_TOO_LONG);
|
|
|
|
|
|
|
|
|
|
verifyNumberOfDeadLetterMessages(3);
|
|
|
|
|
}
|
|
|
|
|
@@ -885,7 +807,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetAttributesRequestedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
public void downloadOnlyAssignmentFinishesActionWhenTargetReportsDownloaded() throws IOException {
|
|
|
|
|
void downloadOnlyAssignmentFinishesActionWhenTargetReportsDownloaded() throws IOException {
|
|
|
|
|
// create target
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "registerTargets_1";
|
|
|
|
|
final DistributionSet distributionSet = createTargetAndDistributionSetAndAssign(controllerId, DOWNLOAD_ONLY);
|
|
|
|
|
@@ -895,14 +817,14 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
Mockito.verifyNoInteractions(getDeadletterListener());
|
|
|
|
|
|
|
|
|
|
// get actionId from Message
|
|
|
|
|
final Long actionId = Long.parseLong(getJsonFieldFromBody(message.getBody(), "actionId"));
|
|
|
|
|
final long actionId = Long.parseLong(getActionIdFromBody(message.getBody()));
|
|
|
|
|
|
|
|
|
|
// Send DOWNLOADED message
|
|
|
|
|
createAndSendActionStatusUpdateMessage(controllerId, actionId, DmfActionStatus.DOWNLOADED);
|
|
|
|
|
assertAction(actionId, 1, Status.RUNNING, Status.DOWNLOADED);
|
|
|
|
|
Mockito.verifyNoInteractions(getDeadletterListener());
|
|
|
|
|
|
|
|
|
|
verifyAssignedDsAndInstalledDs(controllerId, distributionSet.getId(), null);
|
|
|
|
|
verifyAssignedDsAndInstalledDs(distributionSet.getId(), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -915,9 +837,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
|
|
|
|
@Expect(type = TargetAttributesRequestedEvent.class, count = 2),
|
|
|
|
|
@Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = TargetPollEvent.class, count = 1) })
|
|
|
|
|
public void downloadOnlyAssignmentAllowsActionStatusUpdatesWhenTargetReportsFinishedAndUpdatesInstalledDS()
|
|
|
|
|
void downloadOnlyAssignmentAllowsActionStatusUpdatesWhenTargetReportsFinishedAndUpdatesInstalledDS()
|
|
|
|
|
throws IOException {
|
|
|
|
|
|
|
|
|
|
// create target
|
|
|
|
|
final String controllerId = TARGET_PREFIX + "registerTargets_1";
|
|
|
|
|
final DistributionSet distributionSet = createTargetAndDistributionSetAndAssign(controllerId, DOWNLOAD_ONLY);
|
|
|
|
|
@@ -927,29 +848,28 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
Mockito.verifyNoInteractions(getDeadletterListener());
|
|
|
|
|
|
|
|
|
|
// get actionId from Message
|
|
|
|
|
final Long actionId = Long.parseLong(getJsonFieldFromBody(message.getBody(), "actionId"));
|
|
|
|
|
final long actionId = Long.parseLong(getActionIdFromBody(message.getBody()));
|
|
|
|
|
|
|
|
|
|
// Send DOWNLOADED message, should result in the action being closed
|
|
|
|
|
createAndSendActionStatusUpdateMessage(controllerId, actionId, DmfActionStatus.DOWNLOADED);
|
|
|
|
|
assertAction(actionId, 1, Status.RUNNING, Status.DOWNLOADED);
|
|
|
|
|
Mockito.verifyNoInteractions(getDeadletterListener());
|
|
|
|
|
|
|
|
|
|
verifyAssignedDsAndInstalledDs(controllerId, distributionSet.getId(), null);
|
|
|
|
|
verifyAssignedDsAndInstalledDs(distributionSet.getId(), null);
|
|
|
|
|
|
|
|
|
|
// Send FINISHED message
|
|
|
|
|
createAndSendActionStatusUpdateMessage(controllerId, actionId, DmfActionStatus.FINISHED);
|
|
|
|
|
assertAction(actionId, 2, Status.RUNNING, Status.DOWNLOADED, Status.FINISHED);
|
|
|
|
|
Mockito.verifyNoInteractions(getDeadletterListener());
|
|
|
|
|
|
|
|
|
|
verifyAssignedDsAndInstalledDs(controllerId, distributionSet.getId(), distributionSet.getId());
|
|
|
|
|
verifyAssignedDsAndInstalledDs(distributionSet.getId(), distributionSet.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Messages that result into certain exceptions being raised should not be requeued. This message should forwarded to the deadletter queue")
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
|
|
|
|
public void ignoredExceptionTypesShouldNotBeRequeued() {
|
|
|
|
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
|
|
|
|
void ignoredExceptionTypesShouldNotBeRequeued() {
|
|
|
|
|
final ControllerManagement mockedControllerManagement = Mockito.mock(ControllerManagement.class);
|
|
|
|
|
|
|
|
|
|
final List<Class<? extends RuntimeException>> exceptionsThatShouldNotBeRequeued = Arrays
|
|
|
|
|
.asList(IllegalArgumentException.class, EntityAlreadyExistsException.class);
|
|
|
|
|
final String controllerId = "dummy_target";
|
|
|
|
|
@@ -960,7 +880,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
.findOrRegisterTargetIfItDoesNotExist(eq(controllerId), any());
|
|
|
|
|
|
|
|
|
|
amqpMessageHandlerService.setControllerManagement(mockedControllerManagement);
|
|
|
|
|
createAndSendThingCreated(controllerId, TENANT_EXIST);
|
|
|
|
|
createAndSendThingCreated(controllerId);
|
|
|
|
|
verifyOneDeadLetterMessage();
|
|
|
|
|
assertThat(targetManagement.getByControllerID(controllerId)).isEmpty();
|
|
|
|
|
}
|
|
|
|
|
@@ -970,9 +890,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Step
|
|
|
|
|
private void verifyAssignedDsAndInstalledDs(final String controllerId, final Long assignedDsId,
|
|
|
|
|
final Long installedDsId) {
|
|
|
|
|
final Optional<Target> target = controllerManagement.getByControllerId(controllerId);
|
|
|
|
|
private void verifyAssignedDsAndInstalledDs(final Long assignedDsId, final Long installedDsId) {
|
|
|
|
|
final Optional<Target> target = controllerManagement.getByControllerId(DMF_REGISTER_TEST_CONTROLLER_ID);
|
|
|
|
|
assertThat(target).isPresent();
|
|
|
|
|
|
|
|
|
|
// verify the DS was assigned to the Target
|
|
|
|
|
@@ -989,11 +908,11 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendUpdateAttributesMessageWithGivenAttributes(final String target, final String key,
|
|
|
|
|
final String value) {
|
|
|
|
|
private void sendUpdateAttributesMessageWithGivenAttributes(final String key, final String value) {
|
|
|
|
|
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
|
|
|
|
|
controllerAttribute.getAttributes().put(key, value);
|
|
|
|
|
final Message message = createUpdateAttributesMessage(target, TENANT_EXIST, controllerAttribute);
|
|
|
|
|
final Message message = createUpdateAttributesMessage(UPDATE_ATTR_TEST_CONTROLLER_ID, TENANT_EXIST,
|
|
|
|
|
controllerAttribute);
|
|
|
|
|
getDmfClient().send(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1041,9 +960,9 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendUpdateAttributeMessage(final String target, final String tenant,
|
|
|
|
|
final DmfAttributeUpdate attributeUpdate) {
|
|
|
|
|
final Message updateMessage = createUpdateAttributesMessage(target, tenant, attributeUpdate);
|
|
|
|
|
private void sendUpdateAttributeMessage(final DmfAttributeUpdate attributeUpdate) {
|
|
|
|
|
final Message updateMessage = createUpdateAttributesMessage(DMF_ATTR_TEST_CONTROLLER_ID,
|
|
|
|
|
AbstractAmqpServiceIntegrationTest.TENANT_EXIST, attributeUpdate);
|
|
|
|
|
getDmfClient().send(updateMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1068,10 +987,10 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
|
|
|
|
Mockito.reset(getDeadletterListener());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getJsonFieldFromBody(final byte[] body, final String fieldName) throws IOException {
|
|
|
|
|
private static String getActionIdFromBody(final byte[] body) throws IOException {
|
|
|
|
|
final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
final ObjectNode node = objectMapper.readValue(new String(body, Charset.defaultCharset()), ObjectNode.class);
|
|
|
|
|
assertThat(node.has(fieldName)).isTrue();
|
|
|
|
|
return node.get(fieldName).asText();
|
|
|
|
|
assertThat(node.has("actionId")).isTrue();
|
|
|
|
|
return node.get("actionId").asText();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|