Added tests for software management

- while at it I renamed also a few methods to fit into the overall
pattern
This commit is contained in:
Kai Zimmermann
2016-03-25 16:24:42 +01:00
parent 9ff0f00822
commit f237a1e508
11 changed files with 564 additions and 110 deletions

View File

@@ -59,11 +59,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.Sets;
/**
* Business facade for managing the deployable {@link SoftwareModule}s.
*
*
*
*
* Business facade for managing {@link SoftwareModule}s.
*
*/
@Transactional(readOnly = true)
@@ -99,7 +95,7 @@ public class SoftwareManagement {
private ArtifactManagement artifactManagement;
/**
* Updates existing {@link SoftwareModule}. Updateable values are
* Updates existing {@link SoftwareModule}. Update-able values are
* {@link SoftwareModule#getDescription()}
* {@link SoftwareModule#getVendor()}.
*
@@ -119,17 +115,21 @@ public class SoftwareManagement {
final SoftwareModule module = softwareModuleRepository.findOne(sm.getId());
boolean updated = false;
if (null == sm.getDescription() || !sm.getDescription().equals(module.getDescription())) {
module.setDescription(sm.getDescription());
updated = true;
}
if (null == sm.getVendor() || !sm.getVendor().equals(module.getVendor())) {
module.setVendor(sm.getVendor());
updated = true;
}
return softwareModuleRepository.save(module);
return updated ? softwareModuleRepository.save(module) : module;
}
/**
* Updates existing {@link SoftwareModuleType}. Updatable value is
* Updates existing {@link SoftwareModuleType}. Update-able value is
* {@link SoftwareModuleType#getDescription()} and
* {@link SoftwareModuleType#getColour()}.
*
@@ -145,13 +145,16 @@ public class SoftwareManagement {
final SoftwareModuleType type = softwareModuleTypeRepository.findOne(sm.getId());
boolean updated = false;
if (sm.getDescription() != null && !sm.getDescription().equals(type.getDescription())) {
type.setDescription(sm.getDescription());
updated = true;
}
if (sm.getColour() != null && !sm.getColour().equals(type.getColour())) {
type.setColour(sm.getColour());
updated = true;
}
return softwareModuleTypeRepository.save(type);
return updated ? softwareModuleTypeRepository.save(type) : type;
}
/**
@@ -255,6 +258,10 @@ public class SoftwareManagement {
return artifactManagement.findSoftwareModuleById(id);
}
// TODO: discuss this method, does not seem to make sense to search by name
// and version without type. It also makes no sense to return collection
// here. It should be a single result based on ytpe,name,version (like the
// constraint).
/**
* retrieves {@link SoftwareModule}s by their name AND version.
*
@@ -491,12 +498,17 @@ public class SoftwareManagement {
/**
* Filter {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
* and {@link SoftwareModule#getType()} that are not marked as deleted.
* search text and {@link SoftwareModule#getType()} that are not marked as
* deleted and sort them by means of given distribution set related modules
* on top of the list.
*
* After that the modules are sorted by {@link SoftwareModule#getName()} and
* {@link SoftwareModule#getVersion()} in ascending order.
*
* @param pageable
* page parameter
* @param orderByDistributionId
* the ID of distribution set to be order by
* the ID of distribution set to be ordered on top
* @param searchText
* to be filtered as "like" on {@link SoftwareModule#getName()}
* @param type
@@ -504,8 +516,9 @@ public class SoftwareManagement {
* @return the page of found {@link SoftwareModule}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
public Slice<CustomSoftwareModule> findSoftwareModuleOrderByDistribution(@NotNull final Pageable pageable,
@NotNull final Long orderByDistributionId, final String searchText, final SoftwareModuleType type) {
public Slice<CustomSoftwareModule> findSoftwareModuleOrderByDistributionModuleNameAscModuleVersionAsc(
@NotNull final Pageable pageable, @NotNull final Long orderByDistributionId, final String searchText,
final SoftwareModuleType type) {
final List<CustomSoftwareModule> resultList = new ArrayList<>();
final int pageSize = pageable.getPageSize();
@@ -522,7 +535,7 @@ public class SoftwareManagement {
assignedRoot, assignedQuery, cb,
cb.equal(assignedDsJoin.get(DistributionSet_.id), orderByDistributionId));
// if we have some predicates then add it to the where clause of the
// multiselect
// multi select
assignedQuery.where(specPredicate);
assignedQuery.orderBy(cb.asc(assignedRoot.get(SoftwareModule_.name)),
cb.asc(assignedRoot.get(SoftwareModule_.version)));
@@ -546,7 +559,7 @@ public class SoftwareManagement {
unassignedQuery.distinct(true);
final Root<SoftwareModule> unassignedRoot = unassignedQuery.from(SoftwareModule.class);
Predicate[] unassignedSpec = null;
Predicate[] unassignedSpec;
if (!assignedSoftwareModules.isEmpty()) {
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot,
unassignedQuery, cb, cb.not(unassignedRoot.get(SoftwareModule_.id)
@@ -709,8 +722,8 @@ public class SoftwareManagement {
@Modifying
@Transactional
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
public List<SoftwareModuleType> createSoftwareModuleTypes(@NotNull final Collection<SoftwareModuleType> types) {
return types.stream().map(type -> createSoftwareModuleType(type)).collect(Collectors.toList());
public List<SoftwareModuleType> createSoftwareModuleType(@NotNull final Collection<SoftwareModuleType> types) {
return types.stream().map(this::createSoftwareModuleType).collect(Collectors.toList());
}
/**
@@ -826,7 +839,7 @@ public class SoftwareManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
public SoftwareModuleMetadata updateSoftwareModuleMetadata(@NotNull final SoftwareModuleMetadata metadata) {
// check if exists otherwise throw entity not found exception
findOne(metadata.getId());
findSoftwareModuleMetadata(metadata.getId());
// touch it to update the lock revision because we are modifying the
// software module
// indirectly
@@ -884,7 +897,7 @@ public class SoftwareManagement {
cb) -> cb.and(
cb.equal(root.get(SoftwareModuleMetadata_.softwareModule)
.get(SoftwareModule_.id), softwareModuleId),
spec.toPredicate(root, query, cb)),
spec.toPredicate(root, query, cb)),
pageable);
}
@@ -899,7 +912,7 @@ public class SoftwareManagement {
* in case the meta data does not exists for the given key
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
public SoftwareModuleMetadata findOne(@NotNull final SwMetadataCompositeKey id) {
public SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull final SwMetadataCompositeKey id) {
final SoftwareModuleMetadata findOne = softwareModuleMetadataRepository.findOne(id);
if (findOne == null) {
throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist");

View File

@@ -81,6 +81,8 @@ public interface SoftwareModuleRepository
Page<SoftwareModule> findByAssignedTo(Pageable pageable, DistributionSet set);
/**
*
*
* @param set
* to search for
* @return all {@link SoftwareModule}s that are assigned to given

View File

@@ -310,8 +310,6 @@ public class SystemManagement {
}
private DistributionSetType createStandardSoftwareDataSetup() {
// Edge Controller Linux standard setup
final SoftwareModuleType eclApp = softwareModuleTypeRepository.save(new SoftwareModuleType("application",
"ECL Application", "Edge Controller Linux base application type", 1));
final SoftwareModuleType eclOs = softwareModuleTypeRepository

View File

@@ -52,4 +52,44 @@ public class CustomSoftwareModule implements Serializable {
public boolean isAssigned() {
return assigned;
}
@Override
public String toString() {
return "CustomSoftwareModule [softwareModule=" + softwareModule + ", assigned=" + assigned + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (assigned ? 1231 : 1237);
result = prime * result + ((softwareModule == null) ? 0 : softwareModule.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final CustomSoftwareModule other = (CustomSoftwareModule) obj;
if (assigned != other.assigned) {
return false;
}
if (softwareModule == null) {
if (other.softwareModule != null) {
return false;
}
} else if (!softwareModule.equals(other.softwareModule)) {
return false;
}
return true;
}
}

View File

@@ -43,7 +43,7 @@ import org.eclipse.persistence.annotations.CascadeOnDelete;
*/
@Entity
@Table(name = "sp_base_software_module", uniqueConstraints = @UniqueConstraint(columnNames = { "module_type", "name",
"version", "tenant" }, name = "uk_base_sw_mod") , indexes = {
"version", "tenant" }, name = "uk_base_sw_mod"), indexes = {
@Index(name = "sp_idx_base_sw_module_01", columnList = "tenant,deleted,name,version"),
@Index(name = "sp_idx_base_sw_module_02", columnList = "tenant,deleted,module_type"),
@Index(name = "sp_idx_base_sw_module_prim", columnList = "tenant,id") })
@@ -52,7 +52,7 @@ public class SoftwareModule extends NamedVersionedEntity {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "module_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_module_type") )
@JoinColumn(name = "module_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_module_type"))
private SoftwareModuleType type;
@ManyToMany(mappedBy = "modules", targetEntity = DistributionSet.class, fetch = FetchType.LAZY)
@@ -239,23 +239,12 @@ public class SoftwareModule extends NamedVersionedEntity {
return metadata;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "SoftwareModule [type=" + type + ", deleted=" + deleted + ", getVersion()=" + getVersion()
+ ", getOptLockRevision()=" + getOptLockRevision() + ", getId()=" + getId() + ", getType()="
+ getType().getName() + "]";
return "SoftwareModule [deleted=" + deleted + ", getVersion()=" + getVersion() + ", getOptLockRevision()="
+ getOptLockRevision() + ", getId()=" + getId() + ", getType()=" + getType().getName() + "]";
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() { // NOSONAR - as this is generated
final int prime = 31;
@@ -264,11 +253,6 @@ public class SoftwareModule extends NamedVersionedEntity {
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object obj) { // NOSONAR - as this is generated
if (this == obj) {

View File

@@ -24,9 +24,6 @@ import javax.persistence.Table;
/**
* Metadata for {@link SoftwareModule}.
*
*
*
*
*/
@IdClass(SwMetadataCompositeKey.class)
@Entity
@@ -50,18 +47,21 @@ public class SoftwareModuleMetadata implements Serializable {
@JoinColumn(name = "sw_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_sw"))
private SoftwareModule softwareModule;
/**
* Default constructor for JPA.
*/
public SoftwareModuleMetadata() {
// default constructor for JPA.
}
/**
* Standard constructor.
*
* @param key
* of the metadata element
* of the meta data element
* @param softwareModule
* @param value
* of the metadata element
* of the meta data element
*/
public SoftwareModuleMetadata(final String key, final SoftwareModule softwareModule, final String value) {
this.key = key;
@@ -69,56 +69,83 @@ public class SoftwareModuleMetadata implements Serializable {
this.value = value;
}
/**
* @return the id
*/
public SwMetadataCompositeKey getId() {
return new SwMetadataCompositeKey(softwareModule, key);
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value
* the value to set
*/
public void setValue(final String value) {
this.value = value;
}
/**
* @return the softwareModule
*/
public SoftwareModule getSoftwareModule() {
return softwareModule;
}
/**
* @param softwareModule
* the softwareModule to set
*/
public void setSoftwareModule(final SoftwareModule softwareModule) {
this.softwareModule = softwareModule;
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key
* the key to set
*/
public void setKey(final String key) {
this.key = key;
}
@Override
public String toString() {
return "SoftwareModuleMetadata [key=" + key + ", value=" + value + ", softwareModule=" + softwareModule + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + ((softwareModule == null) ? 0 : softwareModule.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final SoftwareModuleMetadata other = (SoftwareModuleMetadata) obj;
if (key == null) {
if (other.key != null) {
return false;
}
} else if (!key.equals(other.key)) {
return false;
}
if (softwareModule == null) {
if (other.softwareModule != null) {
return false;
}
} else if (!softwareModule.equals(other.softwareModule)) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
}