Use javax annotation for validation
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -27,10 +27,8 @@ import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.Order;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.Constants;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetTagAssigmentResultEvent;
|
||||
import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor;
|
||||
@@ -933,11 +931,6 @@ public class TargetManagement {
|
||||
public Target createTarget(@NotNull final Target target, @NotNull final TargetUpdateStatus status,
|
||||
final Long lastTargetQuery, final URI address) {
|
||||
|
||||
if (StringUtils.isEmpty(target.getControllerId())) {
|
||||
throw new ConstraintViolationException("Empty string for controller id not allowed",
|
||||
Collections.emptySet());
|
||||
}
|
||||
|
||||
if (targetRepository.findByControllerId(target.getControllerId()) != null) {
|
||||
throw new EntityAlreadyExistsException(target.getControllerId());
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.model.helper.SecurityChecker;
|
||||
@@ -74,6 +76,8 @@ public class Target extends NamedEntity implements Persistable<Long> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "controller_id", length = 64)
|
||||
@Size(min = 1)
|
||||
@NotNull
|
||||
private String controllerId;
|
||||
|
||||
@Transient
|
||||
|
||||
@@ -68,13 +68,20 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that a target with empty controller id cannot be created")
|
||||
public void createTarget() {
|
||||
public void createTargetWithNoControllerId() {
|
||||
try {
|
||||
targetManagement.createTarget(new Target(""));
|
||||
fail("target with empty controller id should not be created");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// ok
|
||||
}
|
||||
|
||||
try {
|
||||
targetManagement.createTarget(new Target(null));
|
||||
fail("target with empty controller id should not be created");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user