Added tests for DS management. Removed boilerplate.

This commit is contained in:
Kai Zimmermann
2016-03-27 17:18:32 +02:00
parent 8a26ded4c4
commit a2a0a5697e
7 changed files with 138 additions and 85 deletions

View File

@@ -188,11 +188,12 @@ public class DistributionSetManagement {
toBeChangedDSs.add(set);
}
}
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0, toBeChangedDSs.size(),
Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs), myTag);
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0,
toBeChangedDSs.size(), Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs),
myTag);
} else {
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(), 0,
distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag);
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(),
0, distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag);
}
final DistributionSetTagAssignmentResult resultAssignment = result;
@@ -348,6 +349,9 @@ public class DistributionSetManagement {
public List<DistributionSet> createDistributionSets(@NotNull final Iterable<DistributionSet> distributionSets) {
for (final DistributionSet ds : distributionSets) {
prepareDsSave(ds);
if (ds.getType() == null) {
ds.setType(systemManagement.getTenantMetadata().getDefaultDsType());
}
}
return distributionSetRepository.save(distributionSets);
}

View File

@@ -150,7 +150,7 @@ public class TenantConfigurationManagement implements EnvironmentAware {
* @param configurationKey
* the key of the configuration
* @return the converted configuration value either from the tenant specific
* configuration stored or from the fallback default values or
* configuration stored or from the fall back default values or
* {@code null} in case key has not been configured and not default
* value exists
* @throws TenantConfigurationValidatorException

View File

@@ -67,14 +67,14 @@ public class DistributionSet extends NamedVersionedEntity {
@ManyToMany(targetEntity = SoftwareModule.class, fetch = FetchType.LAZY)
@JoinTable(name = "sp_ds_module", joinColumns = {
@JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_ds") ) }, inverseJoinColumns = {
@JoinColumn(name = "module_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_module") ) })
@JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_ds")) }, inverseJoinColumns = {
@JoinColumn(name = "module_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_module")) })
private final Set<SoftwareModule> modules = new HashSet<>();
@ManyToMany(targetEntity = DistributionSetTag.class)
@JoinTable(name = "sp_ds_dstag", joinColumns = {
@JoinColumn(name = "ds", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_ds") ) }, inverseJoinColumns = {
@JoinColumn(name = "TAG", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_tag") ) })
@JoinColumn(name = "ds", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_ds")) }, inverseJoinColumns = {
@JoinColumn(name = "TAG", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_tag")) })
private Set<DistributionSetTag> tags = new HashSet<>();
@Column(name = "deleted")
@@ -95,7 +95,7 @@ public class DistributionSet extends NamedVersionedEntity {
private final List<DistributionSetMetadata> metadata = new ArrayList<>();
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ds_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstype_ds") )
@JoinColumn(name = "ds_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstype_ds"))
private DistributionSetType type;
@Column(name = "complete")
@@ -130,7 +130,9 @@ public class DistributionSet extends NamedVersionedEntity {
if (moduleList != null) {
moduleList.forEach(this::addModule);
}
complete = type.checkComplete(this);
if (this.type != null) {
complete = this.type.checkComplete(this);
}
}
public Set<DistributionSetTag> getTags() {

View File

@@ -27,9 +27,6 @@ import javax.persistence.UniqueConstraint;
* A distribution set type defines which software module types can or have to be
* {@link DistributionSet}.
*
*
*
*
*/
@Entity
@Table(name = "sp_distribution_set_type", indexes = {
@@ -55,7 +52,7 @@ public class DistributionSetType extends NamedEntity {
private boolean deleted = false;
public DistributionSetType() {
// default public constructor
// default public constructor for JPA
}
/**
@@ -307,7 +304,7 @@ public class DistributionSetType extends NamedEntity {
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
if (!(obj instanceof DistributionSetType)) {
return false;
}
final DistributionSetType other = (DistributionSetType) obj;
@@ -337,4 +334,5 @@ public class DistributionSetType extends NamedEntity {
}
return true;
}
}

View File

@@ -25,17 +25,10 @@ import javax.persistence.Table;
* Relation element between a {@link DistributionSetType} and its
* {@link SoftwareModuleType} elements.
*
*
*
*
*/
@Entity
@Table(name = "sp_ds_type_element")
public class DistributionSetTypeElement implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@EmbeddedId
@@ -46,18 +39,16 @@ public class DistributionSetTypeElement implements Serializable {
@MapsId("dsType")
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "distribution_set_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_dstype") )
@JoinColumn(name = "distribution_set_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_dstype"))
private DistributionSetType dsType;
@MapsId("smType")
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "software_module_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_smtype") )
@JoinColumn(name = "software_module_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_smtype"))
private SoftwareModuleType smType;
/**
* Default constructor.
*/
public DistributionSetTypeElement() {
// Default constructor for JPA
}
/**
@@ -108,4 +99,38 @@ public class DistributionSetTypeElement implements Serializable {
return key;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + (mandatory ? 1231 : 1237);
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof DistributionSetTypeElement)) {
return false;
}
final DistributionSetTypeElement other = (DistributionSetTypeElement) obj;
if (key == null) {
if (other.key != null) {
return false;
}
} else if (!key.equals(other.key)) {
return false;
}
if (mandatory != other.mandatory) {
return false;
}
return true;
}
}

View File

@@ -15,17 +15,9 @@ import javax.persistence.Embeddable;
/**
* Composite key for {@link DistributionSetTypeElement}.
*
*
*
*
*/
@Embeddable
public class DistributionSetTypeElementCompositeKey implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Column(name = "distribution_set_type", nullable = false)
@@ -54,34 +46,58 @@ public class DistributionSetTypeElementCompositeKey implements Serializable {
this.smType = smType.getId();
}
/**
* @return the dsType
*/
public Long getDsType() {
return dsType;
}
/**
* @param dsType
* the dsType to set
*/
public void setDsType(final Long dsType) {
this.dsType = dsType;
}
/**
* @return the smType
*/
public Long getSmType() {
return smType;
}
/**
* @param smType
* the smType to set
*/
public void setSmType(final Long smType) {
this.smType = smType;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((dsType == null) ? 0 : dsType.hashCode());
result = prime * result + ((smType == null) ? 0 : smType.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof DistributionSetTypeElementCompositeKey)) {
return false;
}
final DistributionSetTypeElementCompositeKey other = (DistributionSetTypeElementCompositeKey) obj;
if (dsType == null) {
if (other.dsType != null) {
return false;
}
} else if (!dsType.equals(other.dsType)) {
return false;
}
if (smType == null) {
if (other.smType != null) {
return false;
}
} else if (!smType.equals(other.smType)) {
return false;
}
return true;
}
}

View File

@@ -33,6 +33,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.fest.assertions.core.Condition;
import org.junit.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -149,8 +150,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.createDistributionSetType(new DistributionSetType("softdeleted", "to be deletd", ""));
assertThat(distributionSetTypeRepository.findAll()).contains(softDelete);
final DistributionSet dsNewType = distributionSetManagement
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", softDelete, null));
distributionSetManagement.createDistributionSet(new DistributionSet("newtypesoft", "1", "", softDelete, null));
distributionSetManagement.deleteDistributionSetType(softDelete);
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true);
@@ -165,6 +165,46 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
}
@Test
@Description("Verfies that a DS is of default type if not specified explicitly at creation time.")
public void createDistributionSetWithImplicitType() {
final DistributionSet set = distributionSetManagement
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", null, null));
assertThat(set.getType()).as("Type should be equal to default type of tenant")
.isEqualTo(systemManagement.getTenantMetadata().getDefaultDsType());
}
@Test
@Description("Verfies that multiple DS are of default type if not specified explicitly at creation time.")
public void createMultipleDistributionSetsWithImplicitType() {
List<DistributionSet> sets = new ArrayList<>();
for (int i = 0; i < 10; i++) {
sets.add(new DistributionSet("another DS" + i, "X" + i, "", null, null));
}
sets = distributionSetManagement.createDistributionSets(sets);
assertThat(sets).as("Type should be equal to default type of tenant").are(new Condition<DistributionSet>() {
@Override
public boolean matches(final DistributionSet value) {
return value.getType().equals(systemManagement.getTenantMetadata().getDefaultDsType());
}
});
}
@Test(expected = EntityAlreadyExistsException.class)
@Description("Verfies that a DS entity cannot be used for creation.")
public void createDistributionSetFailsOnExistingEntity() {
final DistributionSet set = distributionSetManagement
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", null, null));
distributionSetManagement.createDistributionSet(set);
}
@Test
@Description("Checks that metadata for a distribution set can be created.")
public void createDistributionSetMetadata() {
@@ -725,7 +765,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
dsAssigned.getVersion());
final Target target = new Target("4712");
final Target savedTarget = targetManagement.createTarget(target);
final List<Target> toAssign = new ArrayList<Target>();
final List<Target> toAssign = new ArrayList<>();
toAssign.add(savedTarget);
deploymentManagement.assignDistributionSet(dsAssigned, toAssign);
@@ -739,38 +779,6 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.getTotalElements()).isEqualTo(2);
}
/**
* helper method which re-orders a list as expected. Re-orders the given
* distribution set in the order as given and returns a new list with the
* new order.
*
* @param dsThree
* @param buildDistributionSets
* @return
*/
private List<DistributionSet> reOrderDSList(final Iterable<DistributionSet> buildDistributionSets,
final DistributionSet... ds) {
final List<DistributionSet> reOrderedList = new ArrayList<>();
final Iterator<DistributionSet> iterator = buildDistributionSets.iterator();
while (iterator.hasNext()) {
final DistributionSet next = iterator.next();
int reorder = -1;
for (int index = 0; index < ds.length; index++) {
if (next.equals(ds[index])) {
reorder = index;
}
}
if (reorder >= 0) {
reOrderedList.add(reorder, next);
} else {
reOrderedList.add(next);
}
}
return reOrderedList;
}
private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t,
final String... msgs) {
updActA.setStatus(status);