This commit is contained in:
Marcel 2021-10-17 15:44:09 +02:00
parent f461c5f3cb
commit bb1ffb8bfd
6 changed files with 35 additions and 11 deletions

View File

@ -54,12 +54,6 @@
<groupId>jakarta.validation</groupId> <groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId> <artifactId>jakarta.validation-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>ch.unisg</groupId>
<artifactId>tapas-tasks</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>javax.transaction</groupId> <groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId> <artifactId>javax.transaction-api</artifactId>

View File

@ -0,0 +1,30 @@
package ch.unisg.common;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;
public class SelfValidating<T> {
private Validator validator;
public SelfValidating() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
}
/**
* Evaluates all Bean Validations on the attributes of this
* instance.
*/
protected void validateSelf() {
@SuppressWarnings("unchecked")
Set<ConstraintViolation<T>> violations = validator.validate((T) this);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}
}

View File

@ -1,7 +1,7 @@
package ch.unisg.executorpool.application.port.in; package ch.unisg.executorpool.application.port.in;
import ch.unisg.common.SelfValidating;
import ch.unisg.executorpool.domain.ExecutorPool; import ch.unisg.executorpool.domain.ExecutorPool;
import ch.unisg.tapastasks.common.SelfValidating;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType;

View File

@ -1,7 +1,7 @@
package ch.unisg.executorpool.application.port.in; package ch.unisg.executorpool.application.port.in;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType;
import ch.unisg.tapastasks.common.SelfValidating; import ch.unisg.common.SelfValidating;
import lombok.Value; import lombok.Value;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;

View File

@ -1,7 +1,7 @@
package ch.unisg.executorpool.application.port.in; package ch.unisg.executorpool.application.port.in;
import ch.unisg.executorpool.domain.ExecutorClass; import ch.unisg.executorpool.domain.ExecutorClass;
import ch.unisg.tapastasks.common.SelfValidating; import ch.unisg.common.SelfValidating;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort;
import lombok.Value; import lombok.Value;

View File

@ -1,10 +1,10 @@
package ch.unisg.executor2; package ch.unisg.executor1;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest @SpringBootTest
class Executor2ApplicationTests { class Executor1ApplicationTests {
@Test @Test
void contextLoads() { void contextLoads() {