From c9c36ea435c2fe2da6c5710f2de794eaad78858b Mon Sep 17 00:00:00 2001 From: SirWayne Date: Mon, 29 Feb 2016 15:34:07 +0100 Subject: [PATCH] Add description for asserts in test cases Signed-off-by: SirWayne --- .../SoftwareModuleAssigmentBuilder.java | 2 +- .../amqp/AmqpMessageHandlerServiceTest.java | 15 +- .../PropertyBasedArtifactUrlHandlerTest.java | 20 +- .../repository/DeploymentManagementTest.java | 31 ++- .../repository/TargetManagementTest.java | 103 +++++---- .../rsql/RSQLDistributionSetFieldTest.java | 4 +- .../resource/SoftwareModuleResourceTest.java | 203 ++++++++---------- .../rest/resource/model/PagedListTest.java | 13 +- .../ui/common/tagdetails/TargetTagToken.java | 4 +- .../ManangementConfirmationWindowLayout.java | 37 +--- 10 files changed, 203 insertions(+), 229 deletions(-) diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java index 840f16182..b209dbe8b 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java @@ -25,7 +25,7 @@ public class SoftwareModuleAssigmentBuilder { private final List ids; public SoftwareModuleAssigmentBuilder() { - ids = new ArrayList(); + ids = new ArrayList<>(); } /** diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 18f7b853f..cf6c26590 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -115,14 +115,16 @@ public class AmqpMessageHandlerServiceTest { } - @Test(expected = IllegalArgumentException.class) @Description("Tests not allowed content-type in message") public void testWrongContentType() { final MessageProperties messageProperties = new MessageProperties(); messageProperties.setContentType("xml"); final Message message = new Message(new byte[0], messageProperties); - amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT); - fail(); + try { + amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT); + fail("IllegalArgumentException was excepeted due to worng content type"); + } catch (final IllegalArgumentException e) { + } } @Test @@ -197,14 +199,14 @@ public class AmqpMessageHandlerServiceTest { final Message message = new Message(new byte[0], messageProperties); try { amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT); - fail(); + fail("IllegalArgumentException was excepeted due to unknown message type"); } catch (final IllegalArgumentException e) { } try { messageProperties.setHeader(MessageHeaderKey.TOPIC, "wrongTopic"); amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT); - fail(); + fail("IllegalArgumentException was excepeted due to unknown topic"); } catch (final IllegalArgumentException e) { } @@ -328,7 +330,8 @@ public class AmqpMessageHandlerServiceTest { assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong") .isEqualTo(HttpStatus.OK.value()); assertThat(downloadResponse.getArtifact().getSize()).as("Wrong artifact size in message body").isEqualTo(1L); - assertThat(downloadResponse.getDownloadUrl()).startsWith("http://localhost/api/v1/downloadserver/downloadId/"); + assertThat(downloadResponse.getDownloadUrl()).as("download url is wrong") + .startsWith("http://localhost/api/v1/downloadserver/downloadId/"); } @Test diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java index fcafb23e4..2f3a8e21b 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java @@ -53,18 +53,22 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest @Description("Tests generate the http download url") public void testHttpUrl() { final String url = urlHandlerProperties.getUrl(controllerId, localArtifact, Artifact.UrlProtocol.HTTP); - assertEquals("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId - + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" - + localArtifact.getFilename(), url); + assertEquals("http is build incorrect", + "http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId + + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" + + localArtifact.getFilename(), + url); } @Test @Description("Tests generate the https download url") public void testHttpsUrl() { final String url = urlHandlerProperties.getUrl(controllerId, localArtifact, Artifact.UrlProtocol.HTTPS); - assertEquals("https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId - + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" - + localArtifact.getFilename(), url); + assertEquals("https is build incorrect", + "https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId + + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" + + localArtifact.getFilename(), + url); } @Test @@ -72,7 +76,7 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest public void testCoapUrl() { final String url = urlHandlerProperties.getUrl(controllerId, localArtifact, Artifact.UrlProtocol.COAP); - assertEquals("coap://127.0.0.1:5683/fw/" + tenantAware.getCurrentTenant() + "/" + controllerId + "/sha1/" - + localArtifact.getSha1Hash(), url); + assertEquals("coap is build incorrect", "coap://127.0.0.1:5683/fw/" + tenantAware.getCurrentTenant() + "/" + + controllerId + "/sha1/" + localArtifact.getSha1Hash(), url); } } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index 985bc6bd9..a3071d756 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -766,12 +766,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision()); // verifying that the assignment is correct - assertEquals(1, deploymentManagement.findActiveActionsByTarget(targ).size()); - assertEquals(1, deploymentManagement.findActionsByTarget(targ).size()); - assertEquals(TargetUpdateStatus.PENDING, targ.getTargetInfo().getUpdateStatus()); - assertEquals(dsA, targ.getAssignedDistributionSet()); - assertEquals(dsA, deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet()); - assertNull(targ.getTargetInfo().getInstalledDistributionSet()); + assertEquals("Active target actions are wrong", 1, deploymentManagement.findActiveActionsByTarget(targ).size()); + assertEquals("Target actions are wrong", 1, deploymentManagement.findActionsByTarget(targ).size()); + assertEquals("Target status is wrong", TargetUpdateStatus.PENDING, targ.getTargetInfo().getUpdateStatus()); + assertEquals("Assigned ds is wrong", dsA, targ.getAssignedDistributionSet()); + assertEquals("Active ds is wrong", dsA, + deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet()); + assertNull("Installed ds should be null", targ.getTargetInfo().getInstalledDistributionSet()); final Page updAct = actionRepository.findByDistributionSet(pageReq, dsA); final Action action = updAct.getContent().get(0); @@ -782,12 +783,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { targ = targetManagement.findTargetByControllerID(targ.getControllerId()); assertEquals(0, deploymentManagement.findActiveActionsByTarget(targ).size()); - // try { assertEquals(1, deploymentManagement.findInActiveActionsByTarget(targ).size()); - // } - // catch( final LazyInitializationException ex ) { - // - // } + assertEquals(TargetUpdateStatus.IN_SYNC, targ.getTargetInfo().getUpdateStatus()); assertEquals(dsA, targ.getAssignedDistributionSet()); assertEquals(dsA, targ.getTargetInfo().getInstalledDistributionSet()); @@ -797,13 +794,15 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { targ = targs.iterator().next(); - assertEquals(1, deploymentManagement.findActiveActionsByTarget(targ).size()); - assertEquals(TargetUpdateStatus.PENDING, + assertEquals("active actions are wrong", 1, deploymentManagement.findActiveActionsByTarget(targ).size()); + assertEquals("target status is wrong", TargetUpdateStatus.PENDING, targetManagement.findTargetByControllerID(targ.getControllerId()).getTargetInfo().getUpdateStatus()); assertEquals(dsB, targ.getAssignedDistributionSet()); - assertEquals(dsA.getId(), targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId()) - .getTargetInfo().getInstalledDistributionSet().getId()); - assertEquals(dsB, deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet()); + assertEquals("Installed ds is wrong", dsA.getId(), + targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId()).getTargetInfo() + .getInstalledDistributionSet().getId()); + assertEquals("Active ds is wrong", dsB, + deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet()); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java index cdcaff25e..20dffde29 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java @@ -96,24 +96,26 @@ public class TargetManagementTest extends AbstractIntegrationTest { final TargetTag targetTag = tagManagement.createTargetTag(new TargetTag("Tag1")); final List assignedTargets = targetManagement.assignTag(assignTarget, targetTag); - assertThat(assignedTargets.size()).isEqualTo(4); + assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4); assignedTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(1)); TargetTag findTargetTag = tagManagement.findTargetTag("Tag1"); - assertThat(assignedTargets.size()).isEqualTo(findTargetTag.getAssignedToTargets().size()); + assertThat(assignedTargets.size()).as("Assigned targets are wrong") + .isEqualTo(findTargetTag.getAssignedToTargets().size()); - assertThat(targetManagement.unAssignTag("NotExist", findTargetTag)).isNull(); + assertThat(targetManagement.unAssignTag("NotExist", findTargetTag)).as("Unassign target does not work") + .isNull(); final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag); - assertThat(unAssignTarget.getControllerId()).isEqualTo("targetId123"); - assertThat(unAssignTarget.getTags().size()).isEqualTo(0); + assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123"); + assertThat(unAssignTarget.getTags()).as("Tag size is wrong").isEmpty(); findTargetTag = tagManagement.findTargetTag("Tag1"); - assertThat(findTargetTag.getAssignedToTargets().size()).isEqualTo(3); + assertThat(findTargetTag.getAssignedToTargets()).as("Assigned targets are wrong").hasSize(3); final List unAssignTargets = targetManagement.unAssignAllTargetsByTag(findTargetTag); findTargetTag = tagManagement.findTargetTag("Tag1"); - assertThat(findTargetTag.getAssignedToTargets().size()).isEqualTo(0); - assertThat(unAssignTargets.size()).isEqualTo(3); + assertThat(findTargetTag.getAssignedToTargets()).as("Unassigned targets are wrong").isEmpty(); + assertThat(unAssignTargets).as("Unassigned targets are wrong").hasSize(3); unAssignTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(0)); } @@ -121,14 +123,14 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Description("Ensures that targets can deleted e.g. test all cascades") public void deleteAndCreateTargets() { Target target = targetManagement.createTarget(new Target("targetId123")); - assertThat(targetManagement.countTargetsAll()).isEqualTo(1); + assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1); targetManagement.deleteTargets(target.getId()); - assertThat(targetManagement.countTargetsAll()).isEqualTo(0); + assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0); target = createTargetWithAttributes("4711"); - assertThat(targetManagement.countTargetsAll()).isEqualTo(1); + assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1); targetManagement.deleteTargets(target.getId()); - assertThat(targetManagement.countTargetsAll()).isEqualTo(0); + assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0); final List targets = new ArrayList(); for (int i = 0; i < 5; i++) { @@ -136,9 +138,9 @@ public class TargetManagementTest extends AbstractIntegrationTest { targets.add(target.getId()); targets.add(createTargetWithAttributes("" + (i * i + 1000)).getId()); } - assertThat(targetManagement.countTargetsAll()).isEqualTo(10); + assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(10); targetManagement.deleteTargets(targets.toArray(new Long[targets.size()])); - assertThat(targetManagement.countTargetsAll()).isEqualTo(0); + assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0); } private Target createTargetWithAttributes(final String controllerId) { @@ -150,7 +152,8 @@ public class TargetManagementTest extends AbstractIntegrationTest { target = controllerManagament.updateControllerAttributes(controllerId, testData); target = targetManagement.findTargetByControllerIDWithDetails(controllerId); - assertThat(target.getTargetInfo().getControllerAttributes()).isEqualTo(testData); + assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong") + .isEqualTo(testData); return target; } @@ -162,10 +165,14 @@ public class TargetManagementTest extends AbstractIntegrationTest { final DistributionSet set2 = TestDataUtil.generateDistributionSet("test2", softwareManagement, distributionSetManagement); - assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).isEqualTo(0); - assertThat(targetManagement.countTargetByInstalledDistributionSet(set.getId())).isEqualTo(0); - assertThat(targetManagement.countTargetByAssignedDistributionSet(set2.getId())).isEqualTo(0); - assertThat(targetManagement.countTargetByInstalledDistributionSet(set2.getId())).isEqualTo(0); + assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong") + .isEqualTo(0); + assertThat(targetManagement.countTargetByInstalledDistributionSet(set.getId())).as("Target count is wrong") + .isEqualTo(0); + assertThat(targetManagement.countTargetByAssignedDistributionSet(set2.getId())).as("Target count is wrong") + .isEqualTo(0); + assertThat(targetManagement.countTargetByInstalledDistributionSet(set2.getId())).as("Target count is wrong") + .isEqualTo(0); Target target = createTargetWithAttributes("4711"); @@ -183,13 +190,19 @@ public class TargetManagementTest extends AbstractIntegrationTest { target = targetManagement.findTargetByControllerIDWithDetails("4711"); // read data - assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).isEqualTo(0); - assertThat(targetManagement.countTargetByInstalledDistributionSet(set.getId())).isEqualTo(1); - assertThat(targetManagement.countTargetByAssignedDistributionSet(set2.getId())).isEqualTo(1); - assertThat(targetManagement.countTargetByInstalledDistributionSet(set2.getId())).isEqualTo(0); - assertThat(target.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current); - assertThat(target.getAssignedDistributionSet()).isEqualTo(set2); - assertThat(target.getTargetInfo().getInstalledDistributionSet().getId()).isEqualTo(set.getId()); + assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong") + .isEqualTo(0); + assertThat(targetManagement.countTargetByInstalledDistributionSet(set.getId())).as("Target count is wrong") + .isEqualTo(1); + assertThat(targetManagement.countTargetByAssignedDistributionSet(set2.getId())).as("Target count is wrong") + .isEqualTo(1); + assertThat(targetManagement.countTargetByInstalledDistributionSet(set2.getId())).as("Target count is wrong") + .isEqualTo(0); + assertThat(target.getTargetInfo().getLastTargetQuery()).as("Target query is not work") + .isGreaterThanOrEqualTo(current); + assertThat(target.getAssignedDistributionSet()).as("Assigned ds size is wrong").isEqualTo(set2); + assertThat(target.getTargetInfo().getInstalledDistributionSet().getId()).as("Installed ds is wrong") + .isEqualTo(set.getId()); } @@ -373,8 +386,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { assertThat(firstSaved.spliterator().getExactSizeIfKnown() - nr2Del).as("Size of splited list") .isEqualTo(allFound.spliterator().getExactSizeIfKnown()); - // verify that all undeleted are still found - assertThat(allFound).doesNotContain(deletedTargets); + assertThat(allFound).as("Not all undeleted found").doesNotContain(deletedTargets); } @Test @@ -404,7 +416,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { targetInfo = targetInfoRepository.save(targetInfo); } final Query qry = entityManager.createNativeQuery("select * from sp_target_attributes ta"); - final List result = qry.getResultList(); + final List result = qry.getResultList(); assertThat(attribs.size() * ts.spliterator().getExactSizeIfKnown()).as("Amount of all target attributes") .isEqualTo(result.size()); @@ -467,7 +479,8 @@ public class TargetManagementTest extends AbstractIntegrationTest { final Target tNoAttrib = targetManagement.findTargetByControllerID(tNoAttribl.getControllerId()); if (tNoAttrib.getControllerId().equals(target.getControllerId())) { - assertThat(target.getTargetInfo().getControllerAttributes()).isEmpty(); + assertThat(target.getTargetInfo().getControllerAttributes()) + .as("Controller attributes should be empty").isEmpty(); continue restTarget_; } } @@ -479,7 +492,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { if (tNoAttrib.getControllerId().equals(target.getControllerId())) { assertThat(target.getTargetInfo().getControllerAttributes().keySet().toArray()) - .doesNotContain(attribs2Del.toArray()); + .as("Controller attributes are wrong").doesNotContain(attribs2Del.toArray()); continue restTarget_; } } @@ -504,12 +517,14 @@ public class TargetManagementTest extends AbstractIntegrationTest { t2 = targetManagement.createTarget(t2); t1 = targetManagement.findTargetByControllerID(t1.getControllerId()); - assertThat(t1.getTags()).hasSize(noT1Tags).containsAll(t1Tags); - assertThat(t1.getTags()).hasSize(noT1Tags).doesNotContain(Iterables.toArray(t2Tags, TargetTag.class)); + assertThat(t1.getTags()).as("Tag size is wrong").hasSize(noT1Tags).containsAll(t1Tags); + assertThat(t1.getTags()).as("Tag size is wrong").hasSize(noT1Tags) + .doesNotContain(Iterables.toArray(t2Tags, TargetTag.class)); t2 = targetManagement.findTargetByControllerID(t2.getControllerId()); - assertThat(t2.getTags()).hasSize(noT2Tags).containsAll(t2Tags); - assertThat(t2.getTags()).hasSize(noT2Tags).doesNotContain(Iterables.toArray(t1Tags, TargetTag.class)); + assertThat(t2.getTags()).as("Tag size is wrong").hasSize(noT2Tags).containsAll(t2Tags); + assertThat(t2.getTags()).as("Tag size is wrong").hasSize(noT2Tags) + .doesNotContain(Iterables.toArray(t1Tags, TargetTag.class)); } @Test @@ -531,7 +546,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { final TargetTag tagA = tagManagement.createTargetTag(new TargetTag("A")); final TargetTag tagB = tagManagement.createTargetTag(new TargetTag("B")); final TargetTag tagC = tagManagement.createTargetTag(new TargetTag("C")); - final TargetTag tagX = tagManagement.createTargetTag(new TargetTag("X")); + tagManagement.createTargetTag(new TargetTag("X")); // doing different assignments targetManagement.toggleTagAssignment(tagATargets, tagA); @@ -545,7 +560,8 @@ public class TargetManagementTest extends AbstractIntegrationTest { targetManagement.toggleTagAssignment(tagABCTargets, tagB); targetManagement.toggleTagAssignment(tagABCTargets, tagC); - assertThat(targetManagement.countTargetByFilters(null, null, null, Boolean.FALSE, "X")).isEqualTo(0); + assertThat(targetManagement.countTargetByFilters(null, null, null, Boolean.FALSE, "X")) + .as("Target count is wrong").isEqualTo(0); // search for targets with tag tagA final List targetWithTagA = new ArrayList(); @@ -575,11 +591,11 @@ public class TargetManagementTest extends AbstractIntegrationTest { // check again target lists refreshed from DB assertThat(targetManagement.countTargetByFilters(null, null, null, Boolean.FALSE, "A")) - .isEqualTo(targetWithTagA.size()); + .as("Target count is wrong").isEqualTo(targetWithTagA.size()); assertThat(targetManagement.countTargetByFilters(null, null, null, Boolean.FALSE, "B")) - .isEqualTo(targetWithTagB.size()); + .as("Target count is wrong").isEqualTo(targetWithTagB.size()); assertThat(targetManagement.countTargetByFilters(null, null, null, Boolean.FALSE, "C")) - .isEqualTo(targetWithTagC.size()); + .as("Target count is wrong").isEqualTo(targetWithTagC.size()); } @Test @@ -656,14 +672,15 @@ public class TargetManagementTest extends AbstractIntegrationTest { targetManagement.toggleTagAssignment(targAs, targTagA); assertThat(targetManagement.findTargetsByControllerIDsWithTags( - targAs.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))).hasSize(25); + targAs.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))) + .as("Target count is wrong").hasSize(25); // no lazy loading exception and tag correctly assigned assertThat(targetManagement .findTargetsByControllerIDsWithTags( targAs.stream().map(target -> target.getControllerId()).collect(Collectors.toList())) .stream().map(target -> target.getTags().contains(targTagA)).collect(Collectors.toList())) - .containsOnly(true); + .as("Tags not correctly assigned").containsOnly(true); } @Test @@ -678,7 +695,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { final List findAllTargetIds = findAllTargetIdNames.stream().map(TargetIdName::getControllerId) .collect(Collectors.toList()); - assertThat(findAllTargetIds).containsOnly(createdTargetIds); + assertThat(findAllTargetIds).as("Target list has wrong content").containsOnly(createdTargetIds); } @Test diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java index 6bfdb89aa..f72c3a968 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java @@ -140,7 +140,7 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest { final Page find = distributionSetManagement.findDistributionSetsAll( RSQLUtility.parse(rsqlParam, DistributionSetFields.class), new PageRequest(0, 100), false); final long countAll = find.getTotalElements(); - assertThat(find).isNotNull(); - assertThat(countAll).isEqualTo(excpectedEntity); + assertThat(find).as("Founded entity is should not be null").isNotNull(); + assertThat(countAll).as("Founded entity size is wrong").isEqualTo(excpectedEntity); } } diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java index 8079b5d52..3a0cc3e94 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java @@ -25,6 +25,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -49,6 +50,7 @@ import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactRest; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.junit.Before; import org.junit.Test; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; @@ -69,6 +71,13 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Software Module Resource") public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongoDB { + @Before + public void assertPreparationOfRepo() { + assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("no softwaremodule should be founded") + .hasSize(0); + assertThat(artifactRepository.findAll()).as("no artifacts should be founded").hasSize(0); + } + @Test @Description("Tests the update of software module metadata. It is verfied that only the selected fields for the update are really updated and the modification values are filled (i.e. updated by and at).") @WithUser(principal = "smUpdateTester", allSpPermissions = true) @@ -81,18 +90,14 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo final String updateVendor = "newVendor1"; final String updateDescription = "newDescription1"; - final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); - final SoftwareModule os = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, "")); + softwareManagement.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + softwareManagement.createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); + softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, "")); SoftwareModule sm = new SoftwareModule(osType, knownSWName, knownSWVersion, knownSWDescription, knownSWVendor); sm = softwareManagement.createSoftwareModule(sm); - assertThat(sm.getName()).isEqualTo(knownSWName); - assertThat(sm.getName()).isEqualTo(knownSWName); + assertThat(sm.getName()).as("Wrong name of the software module").isEqualTo(knownSWName); final String body = new JSONObject().put("vendor", updateVendor).put("description", updateDescription) .put("name", "nameShouldNotBeChanged").toString(); @@ -123,9 +128,6 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo @Test @Description("Tests the uppload of an artifact binary. The upload is executed and the content checked in the repository for completenes.") public void uploadArtifact() throws Exception { - // prepare repo - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactRepository.findAll()).hasSize(0); @@ -152,36 +154,41 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .convertArtifactResponse(mvcResult.getResponse().getContentAsString()); final Long artId = ((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts() .get(0)).getId(); - assertThat(artResult.getArtifactId()).isEqualTo(artId); + assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId); assertThat(JsonPath.compile("$_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) + .as("Link contains no self url") .isEqualTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId); assertThat( JsonPath.compile("$_links.download.href").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId - + "/download"); + .as("response contains no download url ").isEqualTo("http://localhost/rest/v1/softwaremodules/" + + sm.getId() + "/artifacts/" + artId + "/download"); + assertArtifact(sm, random); + } + + private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException { // check result in db... // repo - assertThat(artifactRepository.findAll()).hasSize(1); + assertThat(artifactRepository.findAll()).as("Wrong artifact size").hasSize(1); // binary - assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(random), - artifactManagement - .loadLocalArtifactBinary((LocalArtifact) softwareManagement - .findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) - .getFileInputStream())); + assertTrue("Wrong artifact content", + IOUtils.contentEquals(new ByteArrayInputStream(random), + artifactManagement + .loadLocalArtifactBinary((LocalArtifact) softwareManagement + .findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) + .getFileInputStream())); // hashes assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getSha1Hash()) - .isEqualTo(HashGeneratorUtils.generateSHA1(random)); + .as("Wrong sha1 hash").isEqualTo(HashGeneratorUtils.generateSHA1(random)); assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getMd5Hash()) - .isEqualTo(HashGeneratorUtils.generateMD5(random)); + .as("Wrong md5 hash").isEqualTo(HashGeneratorUtils.generateMD5(random)); // metadata assertThat(((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) - .getFilename()).isEqualTo("origFilename"); - + .getFilename()).as("wrong metadata of the filename").isEqualTo("origFilename"); } @Test @@ -203,9 +210,6 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo @Test @Description("Verfies that the system does not accept identical artifacts uploads for the same software module. Expected response: CONFLICT") public void duplicateUploadArtifact() throws Exception { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); @@ -228,9 +232,6 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo @Test @Description("verfies that option to upload artifacts with a custom defined by metadata, i.e. not the file name of the binary itself.") public void uploadArtifactWithCustomName() throws Exception { - // prepare repo - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactRepository.findAll()).hasSize(0); @@ -245,22 +246,19 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$providedFilename", equalTo("customFilename"))).andExpect(status().isCreated()); - ; // check result in db... // repo - assertThat(artifactRepository.findAll()).hasSize(1); + assertThat(artifactRepository.findAll()).as("Artifact size is wring").hasSize(1); // hashes - assertThat(artifactManagement.findLocalArtifactByFilename("customFilename")).hasSize(1); + assertThat(artifactManagement.findLocalArtifactByFilename("customFilename")).as("Local artifact is wrong") + .hasSize(1); } @Test @Description("Verfies that the system refuses upload of an artifact where the provided hash sums do not match. Expected result: BAD REQUEST") public void uploadArtifactWithHashCheck() throws Exception { - // prepare repo - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactRepository.findAll()).hasSize(0); @@ -280,7 +278,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo // check error result ExceptionInfo exceptionInfo = ResourceUtility.convertException(mvcResult.getResponse().getContentAsString()); - assertThat(exceptionInfo.getErrorCode()).isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_SHA1_MATCH.getKey()); + assertThat(exceptionInfo.getErrorCode()).as("Exception contains wrong error code") + .isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_SHA1_MATCH.getKey()); // wrong md5 mvcResult = mvc @@ -290,42 +289,20 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo // check error result exceptionInfo = ResourceUtility.convertException(mvcResult.getResponse().getContentAsString()); - assertThat(exceptionInfo.getErrorCode()).isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_MD5_MATCH.getKey()); + assertThat(exceptionInfo.getErrorCode()).as("Exception contains wrong error code") + .isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_MD5_MATCH.getKey()); mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file) .param("md5sum", md5sum).param("sha1sum", sha1sum)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isCreated()); - // check result... - // repo - assertThat(artifactRepository.findAll()).hasSize(1); - - // binary - assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(random), - artifactManagement - .loadLocalArtifactBinary((LocalArtifact) softwareManagement - .findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) - .getFileInputStream())); - - // hashes - assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getSha1Hash()) - .isEqualTo(HashGeneratorUtils.generateSHA1(random)); - - assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getMd5Hash()) - .isEqualTo(md5sum); - - // metadata - assertThat(((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) - .getFilename()).isEqualTo("origFilename"); + assertArtifact(sm, random); } @Test @Description("Tests binary download of an artifact including verfication that the downloaded binary is consistent and that the etag header is as expected identical to the SHA1 hash of the file.") public void downloadArtifact() throws Exception { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); @@ -350,19 +327,16 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andExpect(header().string("ETag", artifact2.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)).andReturn(); - assertTrue(Arrays.equals(result2.getResponse().getContentAsByteArray(), random)); + assertTrue("Response has wrong response content", + Arrays.equals(result2.getResponse().getContentAsByteArray(), random)); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1); - assertThat(artifactRepository.findAll()).hasSize(2); + assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(1); + assertThat(artifactRepository.findAll()).as("Wrong artifact repostiory").hasSize(2); } @Test @Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and download links.") public void getArtifact() throws Exception { - // check baseline - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); - // prepare data for test SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); @@ -548,8 +522,6 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Test retrieval of all software modules the user has access to.") public void getSoftwareModules() throws Exception { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - SoftwareModule os = new SoftwareModule(osType, "name1", "version1", "description1", "vendor1"); os = softwareManagement.createSoftwareModule(os); @@ -612,14 +584,12 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.self.href", equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId()))); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3); + assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(3); } @Test @Description("Test the various filter parameters, e.g. filter by name or type of the module.") public void getSoftwareModulesWithFilterParameters() throws Exception { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - SoftwareModule os1 = new SoftwareModule(osType, "osName1", "1.0.0", "description1", "vendor1"); os1 = softwareManagement.createSoftwareModule(os1); @@ -712,8 +682,6 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Tests GET request on /rest/v1/softwaremodules/{smId}.") public void getSoftareModule() throws Exception { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - SoftwareModule os = new SoftwareModule(osType, "name1", "version1", "description1", "vendor1"); os = softwareManagement.createSoftwareModule(os); @@ -771,15 +739,13 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andExpect(jsonPath("$_links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/artifacts"))); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3); + assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(3); } @Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Verfies that the create request actually results in the creation of the modules in the repository.") public void createSoftwareModules() throws JSONException, Exception { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - final SoftwareModule os = new SoftwareModule(osType, "name1", "version1", "description1", "vendor1"); final SoftwareModule jvm = new SoftwareModule(runtimeType, "name2", "version1", "description1", "vendor1"); final SoftwareModule ah = new SoftwareModule(appType, "name3", "version1", "description1", "vendor1"); @@ -824,74 +790,75 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo assertThat( JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) + .as("Response contains invalid self href") .isEqualTo("http://localhost/rest/v1/softwaremodules/" + osCreated.getId()); assertThat(JsonPath.compile("[0]_links.artifacts.href").read(mvcResult.getResponse().getContentAsString()) - .toString()).isEqualTo("http://localhost/rest/v1/softwaremodules/" + osCreated.getId() + "/artifacts"); + .toString()).as("Response contains invalid artifacts href") + .isEqualTo("http://localhost/rest/v1/softwaremodules/" + osCreated.getId() + "/artifacts"); assertThat( JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) + .as("Response contains invalid self href") .isEqualTo("http://localhost/rest/v1/softwaremodules/" + jvmCreated.getId()); assertThat(JsonPath.compile("[1]_links.artifacts.href").read(mvcResult.getResponse().getContentAsString()) - .toString()).isEqualTo("http://localhost/rest/v1/softwaremodules/" + jvmCreated.getId() + "/artifacts"); + .toString()).as("Response contains invalid artfacts href") + .isEqualTo("http://localhost/rest/v1/softwaremodules/" + jvmCreated.getId() + "/artifacts"); assertThat( JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) + .as("Response contains links self href") .isEqualTo("http://localhost/rest/v1/softwaremodules/" + ahCreated.getId()); assertThat(JsonPath.compile("[2]_links.artifacts.href").read(mvcResult.getResponse().getContentAsString()) - .toString()).isEqualTo("http://localhost/rest/v1/softwaremodules/" + ahCreated.getId() + "/artifacts"); + .toString()).as("Response contains invalid artifacts href") + .isEqualTo("http://localhost/rest/v1/softwaremodules/" + ahCreated.getId() + "/artifacts"); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3); + assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Wrong softwaremodule size").hasSize(3); assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getName()) - .isEqualTo(os.getName()); + .as("Softwaremoudle name is wrong").isEqualTo(os.getName()); assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getCreatedBy()) - .isEqualTo("uploadTester"); + .as("Softwaremoudle created by is wrong").isEqualTo("uploadTester"); assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getCreatedAt()) - .isGreaterThanOrEqualTo(current); + .as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current); assertThat(softwareManagement.findSoftwareModulesByType(pageReq, runtimeType).getContent().get(0).getName()) - .isEqualTo(jvm.getName()); + .as("Softwaremoudle name is wrong").isEqualTo(jvm.getName()); assertThat(softwareManagement.findSoftwareModulesByType(pageReq, appType).getContent().get(0).getName()) - .isEqualTo(ah.getName()); + .as("Softwaremoudle name is wrong").isEqualTo(ah.getName()); } @Test @Description("Verifies successfull deletion of software modules that are not in use, i.e. assigned to a DS.") public void deleteUnassignedSoftwareModule() throws Exception { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty(); - assertThat(artifactRepository.findAll()).isEmpty(); SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), - "file1", false); + artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1); - assertThat(artifactRepository.findAll()).hasSize(1); - assertThat(softwareModuleRepository.findAll()).hasSize(1); + assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremoudle size is wrong").hasSize(1); + assertThat(artifactRepository.findAll()).as("artifact site is wrong").hasSize(1); + assertThat(softwareModuleRepository.findAll()).as("Softwaremoudle size is wrong").hasSize(1); mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty(); - assertThat(softwareModuleRepository.findAll()).isEmpty(); - assertThat(artifactRepository.findAll()).isEmpty(); + assertThat(softwareManagement.findSoftwareModulesAll(pageReq)) + .as("After delete no softwarmodule should be available").isEmpty(); + assertThat(softwareModuleRepository.findAll()).as("After delete no softwarmodule should be available") + .isEmpty(); + assertThat(artifactRepository.findAll()).as("After delete no artifact should be available").isEmpty(); } @Test @Description("Verifies successfull deletion of software modules that are in use, i.e. assigned to a DS which should result in movinf the module to the archive.") public void deleteAssignedSoftwareModule() throws Exception { - // check baseline - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty(); - assertThat(artifactRepository.findAll()).isEmpty(); - final DistributionSet ds1 = TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), ds1.findFirstModuleByType(appType).getId(), "file1", false); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3); @@ -906,17 +873,17 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); // all 3 are now marked as deleted - assertThat(softwareManagement.findSoftwareModulesAll(pageReq).getNumber()).isEqualTo(0); - assertThat(softwareModuleRepository.findAll()).hasSize(3); - assertThat(artifactRepository.findAll()).hasSize(1); + assertThat(softwareManagement.findSoftwareModulesAll(pageReq).getNumber()) + .as("After delete no softwarmodule should be available").isEqualTo(0); + assertThat(softwareModuleRepository.findAll()).as("After delete no softwarmodule should marked as deleted") + .hasSize(3); + assertThat(artifactRepository.findAll()).as("After delete artifact should available for marked as deleted sm's") + .hasSize(1); } @Test @Description("Tests the deletion of an artifact including verfication that the artifact is actually erased in the repository and removed from the software module.") public void deleteArtifact() throws Exception { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty(); - assertThat(artifactRepository.findAll()).isEmpty(); - // Create 1 SM SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); @@ -926,8 +893,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo // Create 2 artifacts final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); - final LocalArtifact artifact2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), - sm.getId(), "file2", false); + artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false); // check repo before delete assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1); @@ -940,9 +906,12 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); // check that only one artifact is still alive and still assigned - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1); - assertThat(artifactRepository.findAll()).hasSize(1); - assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()).hasSize(1); + assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("After the sm should be marked as deleted") + .hasSize(1); + assertThat(artifactRepository.findAll()).as("After delete artifact should available for marked as deleted sm's") + .hasSize(1); + assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()) + .as("After delete artifact should available for marked as deleted sm's").hasSize(1); } @@ -972,8 +941,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo final SoftwareModuleMetadata metaKey1 = softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey1)); final SoftwareModuleMetadata metaKey2 = softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey2)); - assertThat(metaKey1.getValue()).isEqualTo(knownValue1); - assertThat(metaKey2.getValue()).isEqualTo(knownValue2); + assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1); + assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2); } @Test @@ -997,7 +966,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); final SoftwareModuleMetadata assertDS = softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey)); - assertThat(assertDS.getValue()).isEqualTo(updateValue); + assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue); } @Test diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java index 0c47856dd..4a88bf43e 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java @@ -29,10 +29,13 @@ public class PagedListTest { knownContentList.add("content1"); knownContentList.add("content2"); - final PagedList pagedList = new PagedList<>(knownContentList, knownTotal); + assertListSize(knownTotal, knownContentList); + } - assertThat(pagedList.getTotal()).isEqualTo(knownTotal); - assertThat(pagedList.getSize()).isEqualTo(knownContentList.size()); + private void assertListSize(final long knownTotal, final List knownContentList) { + final PagedList pagedList = new PagedList<>(knownContentList, knownTotal); + assertThat(pagedList.getTotal()).as("total size is wrong").isEqualTo(knownTotal); + assertThat(pagedList.getSize()).as("list size is wrong").isEqualTo(knownContentList.size()); } @Test @@ -42,9 +45,7 @@ public class PagedListTest { knownContentList.add("content1"); knownContentList.add("content2"); - final PagedList pagedList = new PagedList<>(knownContentList, knownTotal); - assertThat(pagedList.getTotal()).isEqualTo(knownTotal); - assertThat(pagedList.getSize()).isEqualTo(knownContentList.size()); + assertListSize(knownTotal, knownContentList); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index 1610a2de8..8982be759 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -78,7 +78,7 @@ public class TargetTagToken extends AbstractTargetTagToken { } private TargetTagAssigmentResult toggleAssignment(final String tagNameSelected) { - final Set targetList = new HashSet(); + final Set targetList = new HashSet<>(); targetList.add(selectedTarget.getControllerId()); final TargetTagAssigmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected); uinotification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(tagNameSelected, result, i18n)); @@ -102,7 +102,7 @@ public class TargetTagToken extends AbstractTargetTagToken { /* To Be Done : this implementation will vary in views */ private List getClickedTagList() { - return new ArrayList(); + return new ArrayList<>(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java index 8f91bf336..c0f681c7a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java @@ -107,32 +107,15 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin super.inittialize(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.confirmwindow.layout. - * AbstractConfirmationWindowLayout# getConfimrationTabs() - */ @Override protected Map getConfimrationTabs() { - final Map tabs = new HashMap(); - /** - * create tab for deleted distribution. - */ - - /* Create tab for SW Module Type delete */ + final Map tabs = new HashMap<>(); if (!managementUIState.getDeletedDistributionList().isEmpty()) { tabs.put(i18n.get("caption.delete.dist.accordion.tab"), createDeletedDistributionTab()); } - /** - * create tab for deleted target. - */ if (!managementUIState.getDeletedTargetList().isEmpty()) { tabs.put(i18n.get("caption.delete.target.accordion.tab"), createDeletedTargetTab()); } - /** - * create tab for assignment. - */ if (!managementUIState.getAssignedList().isEmpty()) { tabs.put(i18n.get("caption.assign.dist.accordion.tab"), createAssignmentTab()); } @@ -196,8 +179,8 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin private void saveAllAssignments(final ConfirmationTab tab) { final Set itemIds = managementUIState.getAssignedList().keySet(); Long distId; - List targetIdSetList = null; - List tempIdList = null; + List targetIdSetList; + List tempIdList; final ActionType actionType = ((ActionTypeOptionGroupLayout.ActionTypeOption) actionTypeOptionGroupLayout .getActionTypeOptionGroup().getValue()).getActionType(); final long forcedTimeStamp = (((ActionTypeOptionGroupLayout.ActionTypeOption) actionTypeOptionGroupLayout @@ -205,7 +188,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin ? actionTypeOptionGroupLayout.getForcedTimeDateField().getValue().getTime() : Action.NO_FORCE_TIME; - final Map> saveAssignedList = new HashMap>(); + final Map> saveAssignedList = new HashMap<>(); int successAssignmentCount = 0; int duplicateAssignmentCount = 0; @@ -216,7 +199,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin if (saveAssignedList.containsKey(distId)) { targetIdSetList = saveAssignedList.get(distId); } else { - targetIdSetList = new ArrayList(); + targetIdSetList = new ArrayList<>(); } targetIdSetList.add(itemId); saveAssignedList.put(distId, (ArrayList) targetIdSetList); @@ -275,15 +258,13 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin } private String getAssigmentSuccessMessage(final int assignedCount) { - final String assignment = FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE + return FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE + i18n.get("message.target.assignment", new Object[] { assignedCount }); - return assignment; } private String getDuplicateAssignmentMessage(final int alreadyAssignedCount) { - final String alreadyAssigned = FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE + return FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE + i18n.get("message.target.alreadyAssigned", new Object[] { alreadyAssignedCount }); - return alreadyAssigned; } private void discardAllAssignments(final ConfirmationTab tab) { @@ -456,7 +437,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin } private void deleteAllDistributions(final ConfirmationTab tab) { - final Set deletedIds = new HashSet(); + final Set deletedIds = new HashSet<>(); managementUIState.getDeletedDistributionList().forEach(distIdName -> deletedIds.add(distIdName.getId())); distributionSetManagement.deleteDistributionSet(deletedIds.toArray(new Long[deletedIds.size()])); addToConsolitatedMsg(FontAwesome.TRASH_O.getHtml() + SPUILabelDefinitions.HTML_SPACE @@ -516,7 +497,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin final IndexedContainer contactContainer = new IndexedContainer(); contactContainer.addContainerProperty(TARGET_ID, String.class, ""); contactContainer.addContainerProperty(TARGET_NAME, String.class, ""); - Item item = null; + Item item; for (final TargetIdName targteId : managementUIState.getDeletedTargetList()) { item = contactContainer.addItem(targteId); item.getItemProperty(TARGET_ID).setValue(targteId.getControllerId());