[FEAT] add @Size @Min @Max @parttern @email unit test for JPAChecker
This commit is contained in:
parent
b5fcc3e20c
commit
24c226e92c
30
test/src/test/kar/archidata/checker/TestJPACheckerEMail.java
Normal file
30
test/src/test/kar/archidata/checker/TestJPACheckerEMail.java
Normal file
@ -0,0 +1,30 @@
|
||||
package test.kar.archidata.checker;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.kar.archidata.exception.InputException;
|
||||
|
||||
import test.kar.archidata.checker.model.JpaBaseModel;
|
||||
import test.kar.archidata.checker.model.JpaBaseModel.JpaBaseModelChecker;
|
||||
|
||||
public class TestJPACheckerEMail {
|
||||
|
||||
@Test
|
||||
public void testEMail() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testEMail = "s@s.ds";
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testEMail = "yuio.sdf@sqdf.com";
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testEMail = "s@s.s";
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testEMail = "sq@qsd";
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testEMail = "sqsdfsdf";
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testEMail = "56465456";
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
}
|
123
test/src/test/kar/archidata/checker/TestJPACheckerMax.java
Normal file
123
test/src/test/kar/archidata/checker/TestJPACheckerMax.java
Normal file
@ -0,0 +1,123 @@
|
||||
package test.kar.archidata.checker;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.kar.archidata.exception.InputException;
|
||||
|
||||
import test.kar.archidata.checker.model.JpaBaseModel;
|
||||
import test.kar.archidata.checker.model.JpaBaseModel.JpaBaseModelChecker;
|
||||
|
||||
public class TestJPACheckerMax {
|
||||
|
||||
@Test
|
||||
public void testMaxInteger() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMaxInteger = 75;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxInteger = 74;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxInteger = 76;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMaxInteger = 100;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxIntegerObject() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMaxIntegerObject = 75;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxIntegerObject = 74;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxIntegerObject = 76;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMaxIntegerObject = 100;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxLong() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMaxLong = 75;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxLong = 74;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxLong = 76;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMaxLong = 100;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxLongObject() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMaxLongObject = 75L;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxLongObject = 74L;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxLongObject = 76L;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMaxLongObject = 100L;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxFloat() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMaxFloat = 75f;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxFloat = 74.99f;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxFloat = 75.01f;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMaxFloat = 100f;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxFloatObject() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMaxFloatObject = 75f;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxFloatObject = 74.99f;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxFloatObject = 75.01f;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMaxFloatObject = 100f;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxDouble() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMaxDouble = 75d;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxDouble = 74.99d;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxDouble = 75.01d;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMaxDouble = 100d;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxDoubleObject() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMaxDoubleObject = 75d;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxDoubleObject = 74.99d;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMaxDoubleObject = 75.01d;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMaxDoubleObject = 100d;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
}
|
123
test/src/test/kar/archidata/checker/TestJPACheckerMin.java
Normal file
123
test/src/test/kar/archidata/checker/TestJPACheckerMin.java
Normal file
@ -0,0 +1,123 @@
|
||||
package test.kar.archidata.checker;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.kar.archidata.exception.InputException;
|
||||
|
||||
import test.kar.archidata.checker.model.JpaBaseModel;
|
||||
import test.kar.archidata.checker.model.JpaBaseModel.JpaBaseModelChecker;
|
||||
|
||||
public class TestJPACheckerMin {
|
||||
|
||||
@Test
|
||||
public void testMinInteger() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMinInteger = -75;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinInteger = -74;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinInteger = -76;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMinInteger = -100;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinIntegerObject() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMinIntegerObject = -75;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinIntegerObject = -74;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinIntegerObject = -76;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMinIntegerObject = -100;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinLong() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMinLong = -75;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinLong = -74;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinLong = -76;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMinLong = -100;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinLongObject() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMinLongObject = -75L;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinLongObject = -74L;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinLongObject = -76L;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMinLongObject = -100L;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinFloat() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMinFloat = -75f;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinFloat = -74.99f;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinFloat = -75.01f;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMinFloat = -100f;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinFloatObject() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMinFloatObject = -75f;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinFloatObject = -74.99f;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinFloatObject = -75.01f;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMinFloatObject = -100f;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinDouble() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMinDouble = -75d;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinDouble = -74.99d;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinDouble = -75.01d;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMinDouble = -100d;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinDoubleObject() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testMinDoubleObject = -75d;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinDoubleObject = -74.99d;
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testMinDoubleObject = -75.01d;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testMinDoubleObject = -100d;
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package test.kar.archidata.checker;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.kar.archidata.exception.InputException;
|
||||
|
||||
import test.kar.archidata.checker.model.JpaBaseModel;
|
||||
import test.kar.archidata.checker.model.JpaBaseModel.JpaBaseModelChecker;
|
||||
|
||||
public class TestJPACheckerPattern {
|
||||
|
||||
@Test
|
||||
public void testPattern() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testPattern = "0";
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testPattern = "1234567890";
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testPattern = "q";
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testPattern = "qsdf4653";
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
}
|
26
test/src/test/kar/archidata/checker/TestJPACheckerSize.java
Normal file
26
test/src/test/kar/archidata/checker/TestJPACheckerSize.java
Normal file
@ -0,0 +1,26 @@
|
||||
package test.kar.archidata.checker;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.kar.archidata.exception.InputException;
|
||||
|
||||
import test.kar.archidata.checker.model.JpaBaseModel;
|
||||
import test.kar.archidata.checker.model.JpaBaseModel.JpaBaseModelChecker;
|
||||
|
||||
public class TestJPACheckerSize {
|
||||
|
||||
@Test
|
||||
public void testSize() throws Exception {
|
||||
final JpaBaseModelChecker checker = new JpaBaseModelChecker();
|
||||
final JpaBaseModel data = new JpaBaseModel();
|
||||
data.testSize = "000";
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testSize = "00000000";
|
||||
Assertions.assertDoesNotThrow(() -> checker.check(data));
|
||||
data.testSize = "00";
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
data.testSize = "000000000";
|
||||
Assertions.assertThrows(InputException.class, () -> checker.check(data));
|
||||
}
|
||||
|
||||
}
|
132
test/src/test/kar/archidata/checker/model/JpaBaseModel.java
Normal file
132
test/src/test/kar/archidata/checker/model/JpaBaseModel.java
Normal file
@ -0,0 +1,132 @@
|
||||
package test.kar.archidata.checker.model;
|
||||
|
||||
import org.kar.archidata.dataAccess.options.CheckJPA;
|
||||
|
||||
import jakarta.validation.constraints.DecimalMax;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public class JpaBaseModel {
|
||||
// Simple checker declaration
|
||||
public static class JpaBaseModelChecker extends CheckJPA<JpaBaseModel> {
|
||||
public JpaBaseModelChecker() {
|
||||
super(JpaBaseModel.class);
|
||||
}
|
||||
}
|
||||
|
||||
// Simple data to verify if the checker is active
|
||||
@Size(min = 3, max = 8)
|
||||
public String testSize;
|
||||
|
||||
@Pattern(regexp = "^[0-9]+$")
|
||||
public String testPattern;
|
||||
|
||||
@Email
|
||||
public String testEMail;
|
||||
|
||||
@Min(-75)
|
||||
public int testMinInteger;
|
||||
@Min(-75)
|
||||
public Integer testMinIntegerObject;
|
||||
@Min(-75)
|
||||
public long testMinLong;
|
||||
@Min(-75)
|
||||
public Long testMinLongObject;
|
||||
@Min(-75)
|
||||
public float testMinFloat;
|
||||
@Min(-75)
|
||||
public Float testMinFloatObject;
|
||||
@Min(-75)
|
||||
public double testMinDouble;
|
||||
@Min(-75)
|
||||
public Double testMinDoubleObject;
|
||||
|
||||
@Max(75)
|
||||
public int testMaxInteger;
|
||||
@Max(75)
|
||||
public Integer testMaxIntegerObject;
|
||||
@Max(75)
|
||||
public long testMaxLong;
|
||||
@Max(75)
|
||||
public Long testMaxLongObject;
|
||||
@Max(75)
|
||||
public float testMaxFloat;
|
||||
@Max(75)
|
||||
public Float testMaxFloatObject;
|
||||
@Max(75)
|
||||
public double testMaxDouble;
|
||||
@Max(75)
|
||||
public Double testMaxDoubleObject;
|
||||
|
||||
@DecimalMin("-75")
|
||||
public int testDecimalMinIncludeInteger;
|
||||
@DecimalMin("-75")
|
||||
public Integer testDecimalMinIncludeIntegerObject;
|
||||
@DecimalMin("-75")
|
||||
public long testDecimalMinIncludeLong;
|
||||
@DecimalMin("-75")
|
||||
public Long testDecimalMinIncludeLongObject;
|
||||
@DecimalMin("-75.56")
|
||||
public float testDecimalMinIncludeFloat;
|
||||
@DecimalMin("-75.56")
|
||||
public Float testDecimalMinIncludeFloatObject;
|
||||
@DecimalMin("-75.56")
|
||||
public double testDecimalMinIncludeDouble;
|
||||
@DecimalMin("-75.56")
|
||||
public Double testDecimalMinIncludeDoubleObject;
|
||||
|
||||
@DecimalMax("75")
|
||||
public int testDecimalMaxIncludeInteger;
|
||||
@DecimalMax("75")
|
||||
public Integer testDecimalMaxIncludeIntegerObject;
|
||||
@DecimalMax("75")
|
||||
public long testDecimalMaxIncludeLong;
|
||||
@DecimalMax("75")
|
||||
public Long testDecimalMaxIncludeLongObject;
|
||||
@DecimalMax("75.56")
|
||||
public float testDecimalMaxIncludeFloat;
|
||||
@DecimalMax("75.56")
|
||||
public Float testDecimalMaxIncludeFloatObject;
|
||||
@DecimalMax("75.56")
|
||||
public double testDecimalMaxIncludeDouble;
|
||||
@DecimalMax("75.56")
|
||||
public Double testDecimalMaxIncludeDoubleObject;
|
||||
|
||||
@DecimalMin(value = "-75", inclusive = false)
|
||||
public int testDecimalMinExcludeInteger;
|
||||
@DecimalMin(value = "-75", inclusive = false)
|
||||
public Integer testDecimalMinExcludeIntegerObject;
|
||||
@DecimalMin(value = "-75", inclusive = false)
|
||||
public long testDecimalMinExcludeLong;
|
||||
@DecimalMin(value = "-75", inclusive = false)
|
||||
public Long testDecimalMinExcludeLongObject;
|
||||
@DecimalMin(value = "-75.56", inclusive = false)
|
||||
public float testDecimalMinExcludeFloat;
|
||||
@DecimalMin(value = "-75.56", inclusive = false)
|
||||
public Float testDecimalMinExcludeFloatObject;
|
||||
@DecimalMin(value = "-75.56", inclusive = false)
|
||||
public double testDecimalMinExcludeDouble;
|
||||
@DecimalMin(value = "-75.56", inclusive = false)
|
||||
public Double testDecimalMinExcludeDoubleObject;
|
||||
|
||||
@DecimalMax(value = "75", inclusive = false)
|
||||
public int testDecimalMaxExcludeInteger;
|
||||
@DecimalMax(value = "75", inclusive = false)
|
||||
public Integer testDecimalMaxExcludeIntegerObject;
|
||||
@DecimalMax(value = "75", inclusive = false)
|
||||
public long testDecimalMaxExcludeLong;
|
||||
@DecimalMax(value = "75", inclusive = false)
|
||||
public Long testDecimalMaxExcludeLongObject;
|
||||
@DecimalMax(value = "75.56", inclusive = false)
|
||||
public float testDecimalMaxExcludeFloat;
|
||||
@DecimalMax(value = "75.56", inclusive = false)
|
||||
public Float testDecimalMaxExcludeFloatObject;
|
||||
@DecimalMax(value = "75.56", inclusive = false)
|
||||
public double testDecimalMaxExcludeDouble;
|
||||
@DecimalMax(value = "75.56", inclusive = false)
|
||||
public Double testDecimalMaxExcludeDoubleObject;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user