From a9c337af6ae5dfb7ac51e3a5596dc6ed97676fa1 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Mon, 9 Jan 2017 09:38:25 +0100 Subject: [PATCH] Add test for target attributes update Signed-off-by: kaizimmerm --- .../repository/jpa/TargetManagementTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java index df3d65891..303d3ff26 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java @@ -54,9 +54,11 @@ import org.springframework.data.domain.PageRequest; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Step; import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @@ -243,6 +245,54 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0); } + @Test + @Description("Ensures that target attribute update is reflected by the repository.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 3) }) + public void updateTargetAttributes() { + final String controllerId = "test123"; + testdataFactory.createTarget(controllerId); + addAttributeAndVerify(controllerId); + addSecondAttributeAndVerify(controllerId); + updateAttributeAndVerify(controllerId); + } + + @Step + private void addAttributeAndVerify(final String controllerId) { + final Map testData = Maps.newHashMapWithExpectedSize(1); + testData.put("test1", "testdata1"); + controllerManagament.updateControllerAttributes(controllerId, testData); + + final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId); + assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong") + .isEqualTo(testData); + } + + @Step + private void addSecondAttributeAndVerify(final String controllerId) { + final Map testData = Maps.newHashMapWithExpectedSize(2); + testData.put("test2", "testdata20"); + controllerManagament.updateControllerAttributes(controllerId, testData); + + final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId); + testData.put("test1", "testdata1"); + assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong") + .isEqualTo(testData); + } + + @Step + private void updateAttributeAndVerify(final String controllerId) { + final Map testData = Maps.newHashMapWithExpectedSize(2); + testData.put("test1", "testdata12"); + + controllerManagament.updateControllerAttributes(controllerId, testData); + + final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId); + testData.put("test2", "testdata20"); + assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong") + .isEqualTo(testData); + } + private Target createTargetWithAttributes(final String controllerId) { final Map testData = new HashMap<>(); testData.put("test1", "testdata1");