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

View File

@@ -130,7 +130,9 @@ public class DistributionSet extends NamedVersionedEntity {
if (moduleList != null) { if (moduleList != null) {
moduleList.forEach(this::addModule); moduleList.forEach(this::addModule);
} }
complete = type.checkComplete(this); if (this.type != null) {
complete = this.type.checkComplete(this);
}
} }
public Set<DistributionSetTag> getTags() { 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 * A distribution set type defines which software module types can or have to be
* {@link DistributionSet}. * {@link DistributionSet}.
* *
*
*
*
*/ */
@Entity @Entity
@Table(name = "sp_distribution_set_type", indexes = { @Table(name = "sp_distribution_set_type", indexes = {
@@ -55,7 +52,7 @@ public class DistributionSetType extends NamedEntity {
private boolean deleted = false; private boolean deleted = false;
public DistributionSetType() { public DistributionSetType() {
// default public constructor // default public constructor for JPA
} }
/** /**
@@ -307,7 +304,7 @@ public class DistributionSetType extends NamedEntity {
if (!super.equals(obj)) { if (!super.equals(obj)) {
return false; return false;
} }
if (getClass() != obj.getClass()) { if (!(obj instanceof DistributionSetType)) {
return false; return false;
} }
final DistributionSetType other = (DistributionSetType) obj; final DistributionSetType other = (DistributionSetType) obj;
@@ -337,4 +334,5 @@ public class DistributionSetType extends NamedEntity {
} }
return true; return true;
} }
} }

View File

@@ -25,17 +25,10 @@ import javax.persistence.Table;
* Relation element between a {@link DistributionSetType} and its * Relation element between a {@link DistributionSetType} and its
* {@link SoftwareModuleType} elements. * {@link SoftwareModuleType} elements.
* *
*
*
*
*/ */
@Entity @Entity
@Table(name = "sp_ds_type_element") @Table(name = "sp_ds_type_element")
public class DistributionSetTypeElement implements Serializable { public class DistributionSetTypeElement implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@EmbeddedId @EmbeddedId
@@ -54,10 +47,8 @@ public class DistributionSetTypeElement implements Serializable {
@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; private SoftwareModuleType smType;
/**
* Default constructor.
*/
public DistributionSetTypeElement() { public DistributionSetTypeElement() {
// Default constructor for JPA
} }
/** /**
@@ -108,4 +99,38 @@ public class DistributionSetTypeElement implements Serializable {
return key; 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}. * Composite key for {@link DistributionSetTypeElement}.
*
*
*
*
*/ */
@Embeddable @Embeddable
public class DistributionSetTypeElementCompositeKey implements Serializable { public class DistributionSetTypeElementCompositeKey implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Column(name = "distribution_set_type", nullable = false) @Column(name = "distribution_set_type", nullable = false)
@@ -54,34 +46,58 @@ public class DistributionSetTypeElementCompositeKey implements Serializable {
this.smType = smType.getId(); this.smType = smType.getId();
} }
/**
* @return the dsType
*/
public Long getDsType() { public Long getDsType() {
return dsType; return dsType;
} }
/**
* @param dsType
* the dsType to set
*/
public void setDsType(final Long dsType) { public void setDsType(final Long dsType) {
this.dsType = dsType; this.dsType = dsType;
} }
/**
* @return the smType
*/
public Long getSmType() { public Long getSmType() {
return smType; return smType;
} }
/**
* @param smType
* the smType to set
*/
public void setSmType(final Long smType) { public void setSmType(final Long smType) {
this.smType = 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.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.fest.assertions.core.Condition;
import org.junit.Test; import org.junit.Test;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
@@ -149,8 +150,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.createDistributionSetType(new DistributionSetType("softdeleted", "to be deletd", "")); .createDistributionSetType(new DistributionSetType("softdeleted", "to be deletd", ""));
assertThat(distributionSetTypeRepository.findAll()).contains(softDelete); assertThat(distributionSetTypeRepository.findAll()).contains(softDelete);
final DistributionSet dsNewType = distributionSetManagement distributionSetManagement.createDistributionSet(new DistributionSet("newtypesoft", "1", "", softDelete, null));
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", softDelete, null));
distributionSetManagement.deleteDistributionSetType(softDelete); distributionSetManagement.deleteDistributionSetType(softDelete);
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true); 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 @Test
@Description("Checks that metadata for a distribution set can be created.") @Description("Checks that metadata for a distribution set can be created.")
public void createDistributionSetMetadata() { public void createDistributionSetMetadata() {
@@ -725,7 +765,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
dsAssigned.getVersion()); dsAssigned.getVersion());
final Target target = new Target("4712"); final Target target = new Target("4712");
final Target savedTarget = targetManagement.createTarget(target); final Target savedTarget = targetManagement.createTarget(target);
final List<Target> toAssign = new ArrayList<Target>(); final List<Target> toAssign = new ArrayList<>();
toAssign.add(savedTarget); toAssign.add(savedTarget);
deploymentManagement.assignDistributionSet(dsAssigned, toAssign); deploymentManagement.assignDistributionSet(dsAssigned, toAssign);
@@ -739,38 +779,6 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.getTotalElements()).isEqualTo(2); .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, private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t,
final String... msgs) { final String... msgs) {
updActA.setStatus(status); updActA.setStatus(status);