Merge pull request #279 from bsinno/fix_negative_max_assignments
Fix negative max assignments of softwareModuleTypes
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* the {@link ConstraintViolationException} is thrown when an entity is tried to
|
||||
* be saved which has constraint violations
|
||||
*/
|
||||
public class ConstraintViolationException extends AbstractServerRtException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String MESSAGE_FORMATTER_SEPARATOR = " ";
|
||||
|
||||
/**
|
||||
* Constructor for {@link ConstraintViolationException}
|
||||
*
|
||||
* @param ex
|
||||
* the javax.validation.ConstraintViolationException which is
|
||||
* thrown
|
||||
*/
|
||||
public ConstraintViolationException(final javax.validation.ConstraintViolationException ex) {
|
||||
super(getExceptionMessage(ex), SpServerError.SP_REPO_CONSTRAINT_VIOLATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the information of
|
||||
* {@link javax.validation.ConstraintViolationException} to provide a proper
|
||||
* error message for {@link ConstraintViolationException}
|
||||
*
|
||||
* @param ex
|
||||
* javax.validation.ConstraintViolationException which is thrown
|
||||
* @return message String with proper error information
|
||||
*/
|
||||
public static String getExceptionMessage(final javax.validation.ConstraintViolationException ex) {
|
||||
return ex
|
||||
.getConstraintViolations().stream().map(violation -> violation.getPropertyPath()
|
||||
+ MESSAGE_FORMATTER_SEPARATOR + violation.getMessage() + ".")
|
||||
.collect(Collectors.joining(MESSAGE_FORMATTER_SEPARATOR));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,15 +8,12 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* the {@link EntityAlreadyExistsException} is thrown when a entity is tried to
|
||||
* the {@link EntityAlreadyExistsException} is thrown when an entity is tried to
|
||||
* be saved which already exists or which violates unique key constraints.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class EntityAlreadyExistsException extends AbstractServerRtException {
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import javax.validation.constraints.Min;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
|
||||
@@ -36,6 +37,7 @@ public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements Sof
|
||||
private String key;
|
||||
|
||||
@Column(name = "max_ds_assignments", nullable = false)
|
||||
@Min(1)
|
||||
private int maxAssignments;
|
||||
|
||||
@Column(name = "colour", nullable = true, length = 16)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Update sp_software_module_type set max_ds_assignments = 1 where max_ds_assignments < 1;
|
||||
@@ -0,0 +1 @@
|
||||
Update sp_software_module_type set max_ds_assignments = 1 where max_ds_assignments < 1;
|
||||
@@ -19,6 +19,8 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
@@ -785,9 +787,20 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the creation of a softwareModuleType is failing because of invalid max assignment")
|
||||
public void createSoftwareModuleTypesFailsWithInvalidMaxAssignment() {
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(new JpaSoftwareModuleType("type", "name", "desc", 0));
|
||||
fail("should not have worked as max assignment is invalid. Should be greater than 0.");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that multiple types are created as requested.")
|
||||
public void createMultipleoftwareModuleTypes() {
|
||||
public void createMultipleSoftwareModuleTypes() {
|
||||
final List<SoftwareModuleType> created = softwareManagement.createSoftwareModuleType(
|
||||
Lists.newArrayList(new JpaSoftwareModuleType("thetype", "thename", "desc", 100),
|
||||
new JpaSoftwareModuleType("thetype2", "thename2", "desc2", 100)));
|
||||
@@ -797,7 +810,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that sofwtare modules are resturned that are assigned to given DS.")
|
||||
@Description("Verfies that software modules are resturned that are assigned to given DS.")
|
||||
public void findSoftwareModuleByAssignedTo() {
|
||||
// test meta data
|
||||
final SoftwareModuleType testType = softwareManagement
|
||||
@@ -810,8 +823,6 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(testType, "asis", "found", null, ""));
|
||||
final SoftwareModule one = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "found", "b", null, ""));
|
||||
final SoftwareModule two = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "found", "c", null, ""));
|
||||
|
||||
// one soft deleted
|
||||
final SoftwareModule deleted = softwareManagement
|
||||
|
||||
Reference in New Issue
Block a user