Consolidated equals and hashcode for all BaseEntities.
This commit is contained in:
@@ -18,6 +18,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.Constants;
|
||||
@@ -386,7 +387,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(10, myCtrlIDPref, "first description"));
|
||||
|
||||
final String myDeployedCtrlIDPref = "myDeployedCtrlID";
|
||||
final List<Target> savedDeployedTargets = targetManagement
|
||||
List<Target> savedDeployedTargets = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(20, myDeployedCtrlIDPref, "first description"));
|
||||
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
@@ -399,6 +400,10 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
final Iterable<Target> allFoundTargets = targetManagement.findTargetsAll(pageReq).getContent();
|
||||
|
||||
// get final updated version of targets
|
||||
savedDeployedTargets = targetManagement.findTargetByControllerID(
|
||||
savedDeployedTargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
|
||||
assertThat(allFoundTargets).as("founded targets are wrong").containsAll(savedDeployedTargets)
|
||||
.containsAll(savedNakedTargets);
|
||||
assertThat(savedDeployedTargets).as("saved target are wrong")
|
||||
@@ -602,6 +607,10 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
.assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets()).getAssignedTargets();
|
||||
actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(1);
|
||||
|
||||
// get final updated version of targets
|
||||
final List<Target> deployResWithDsBTargets = targetManagement.findTargetByControllerID(deployResWithDsB
|
||||
.getDeployedTargets().stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsB.getDeployedTargets());
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsB.getDeployedTargets());
|
||||
|
||||
|
||||
@@ -109,6 +109,14 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
both.add(TargetUpdateStatus.UNKNOWN);
|
||||
both.add(TargetUpdateStatus.PENDING);
|
||||
|
||||
// get final updated version of targets
|
||||
targAs = targetManagement.findTargetByControllerID(
|
||||
targAs.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
targBs = targetManagement.findTargetByControllerID(
|
||||
targBs.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
targCs = targetManagement.findTargetByControllerID(
|
||||
targCs.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
|
||||
// try to find several targets with different filter settings
|
||||
verifyThatRepositoryContains400Targets();
|
||||
verifyThat200TargetsHaveTagD(targTagW, concat(targBs, targCs));
|
||||
@@ -708,11 +716,14 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
final List<Target> assignedtargets = targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
List<Target> assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
|
||||
deploymentManagement.assignDistributionSet(assignedSet, assignedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
assignedtargets = targetManagement.findTargetByControllerID(
|
||||
assignedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
|
||||
assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), pageReq))
|
||||
.as("Contains the assigned targets").containsAll(assignedtargets)
|
||||
.as("and that means the following expected amount").hasSize(10);
|
||||
@@ -727,8 +738,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
final List<Target> assignedtargets = targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
List<Target> assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
|
||||
// set on installed and assign another one
|
||||
deploymentManagement.assignDistributionSet(installedSet, assignedtargets).getActions().forEach(actionId -> {
|
||||
@@ -739,11 +749,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
});
|
||||
deploymentManagement.assignDistributionSet(assignedSet, assignedtargets);
|
||||
|
||||
assignedtargets = targetManagement.findTargetByControllerID(
|
||||
assignedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
|
||||
assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(),
|
||||
TargetSpecifications.hasInstalledDistributionSet(installedSet.getId()), pageReq))
|
||||
.as("Contains the assigned targets").containsAll(assignedtargets)
|
||||
.as("and that means the following expected amount").hasSize(10);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -754,8 +766,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
final List<Target> installedtargets = targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
List<Target> installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
|
||||
// set on installed and assign another one
|
||||
deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> {
|
||||
@@ -766,6 +777,10 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
});
|
||||
deploymentManagement.assignDistributionSet(assignedSet, installedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
installedtargets = targetManagement.findTargetByControllerID(
|
||||
installedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
|
||||
assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), pageReq))
|
||||
.as("Contains the assigned targets").containsAll(installedtargets)
|
||||
.as("and that means the following expected amount").hasSize(10);
|
||||
@@ -780,8 +795,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
final List<Target> installedtargets = targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
List<Target> installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
|
||||
// set on installed and assign another one
|
||||
deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> {
|
||||
@@ -792,6 +806,10 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
});
|
||||
deploymentManagement.assignDistributionSet(assignedSet, installedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
installedtargets = targetManagement.findTargetByControllerID(
|
||||
installedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
|
||||
assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(),
|
||||
TargetSpecifications.hasAssignedDistributionSet(assignedSet.getId()), pageReq))
|
||||
.as("Contains the assigned targets").containsAll(installedtargets)
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Unit Tests - Repository")
|
||||
@Stories("Repository Model")
|
||||
public class ModelEqualsHashcodeTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Verfies that different objects even with identical primary key, version and tenant "
|
||||
+ "return different hash codes.")
|
||||
public void differentEntitiesReturnDifferentHashCodes() {
|
||||
assertThat(new Action().hashCode()).as("action should have different hashcode than action status")
|
||||
.isNotEqualTo(new ActionStatus().hashCode());
|
||||
assertThat(new DistributionSet().hashCode())
|
||||
.as("Distribution set should have different hashcode than software module")
|
||||
.isNotEqualTo(new SoftwareModule().hashCode());
|
||||
assertThat(new DistributionSet().hashCode())
|
||||
.as("Distribution set should have different hashcode than action status")
|
||||
.isNotEqualTo(new ActionStatus().hashCode());
|
||||
assertThat(new DistributionSetType().hashCode())
|
||||
.as("Distribution set type should have different hashcode than action status")
|
||||
.isNotEqualTo(new ActionStatus().hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that different object even with identical primary key, version and tenant "
|
||||
+ "are not equal.")
|
||||
public void differentEntitiesAreNotEqual() {
|
||||
assertThat(new Action().equals(new ActionStatus())).as("action equals action status").isFalse();
|
||||
assertThat(new DistributionSet().equals(new SoftwareModule())).as("Distribution set equals software module")
|
||||
.isFalse();
|
||||
assertThat(new DistributionSet().equals(new ActionStatus())).as("Distribution set equals action status")
|
||||
.isFalse();
|
||||
assertThat(new DistributionSetType().equals(new ActionStatus()))
|
||||
.as("Distribution set type equals action status").isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that updated entities are not equal.")
|
||||
public void changedEntitiesAreNotEqual() {
|
||||
final SoftwareModuleType type = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("test", "test", "test", 1));
|
||||
assertThat(type).isNotEqualTo(new SoftwareModuleType("test", "test", "test", 1));
|
||||
|
||||
type.setDescription("another");
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(type);
|
||||
assertThat(type).as("Changed entity is not equal to the previous version").isNotEqualTo(updated);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that no proxy of the entity manager has an influence on the equals or hashcode result.")
|
||||
public void managedEntityIsEqualToUnamangedObjectWithSameKey() {
|
||||
final SoftwareModuleType type = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("test", "test", "test", 1));
|
||||
|
||||
final SoftwareModuleType mock = new SoftwareModuleType("test", "test", "test", 1);
|
||||
mock.setId(type.getId());
|
||||
mock.setOptLockRevision(type.getOptLockRevision());
|
||||
mock.setTenant(type.getTenant());
|
||||
|
||||
assertThat(type).as("managed entity is equal to regular object with same content").isEqualTo(mock);
|
||||
assertThat(type.hashCode()).as("managed entity has same hash code as regular object with same content")
|
||||
.isEqualTo(mock.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that updated entities do not have the same hashcode.")
|
||||
public void updatedEntitiesHaveDifferentHashcodes() {
|
||||
final SoftwareModuleType type = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("test", "test", "test", 1));
|
||||
assertThat(type.hashCode()).isNotEqualTo(new SoftwareModuleType("test", "test", "test", 1).hashCode());
|
||||
|
||||
final int beforeChange = type.hashCode();
|
||||
type.setDescription("another");
|
||||
assertThat(type.hashCode())
|
||||
.as("Changed entity has no different hashcode than the previous version until updated in repository")
|
||||
.isEqualTo(beforeChange);
|
||||
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(type);
|
||||
assertThat(type.hashCode()).as("Updated entity has different hashcode than the previous version")
|
||||
.isNotEqualTo(updated.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user