Author: dwoods
Date: Mon Jul 6 18:08:18 2009
New Revision: 791554
URL: http://svn.apache.org/viewvc?rev=791554&view=rev
Log:
OPENJPA-1157 Integration tests for Bean Validation providers - Part 2. Convert
some of the existing attribute constraints to be method/getter constraints.
Modified:
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintBoolean.java
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintDecimal.java
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintNull.java
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml
Modified:
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintBoolean.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintBoolean.java?rev=791554&r1=791553&r2=791554&view=diff
==============================================================================
---
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintBoolean.java
(original)
+++
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintBoolean.java
Mon Jul 6 18:08:18 2009
@@ -27,6 +27,7 @@
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
+import javax.validation.Valid;
import javax.validation.constraints.AssertFalse;
import javax.validation.constraints.AssertTrue;
@@ -52,8 +53,7 @@
private Boolean trueRequired;
@Basic
- @AssertFalse
- private Boolean falseRequired;
+ private Boolean falseRequired; // @AssertFalse constraint is on the getter
/*
@@ -98,7 +98,8 @@
public void setTrueRequired(Boolean b) {
trueRequired = b;
}
-
+
+ @AssertFalse
public Boolean getFalseRequired() {
return falseRequired;
}
Modified:
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintDecimal.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintDecimal.java?rev=791554&r1=791553&r2=791554&view=diff
==============================================================================
---
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintDecimal.java
(original)
+++
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintDecimal.java
Mon Jul 6 18:08:18 2009
@@ -19,6 +19,7 @@
package org.apache.openjpa.integration.validation;
import java.io.Serializable;
+import java.math.BigDecimal;
//import java.math.BigDecimal;
import javax.persistence.Basic;
@@ -47,12 +48,10 @@
private static final long serialVersionUID = 1L;
@Transient
- //private static final BigDecimal negative = new BigDecimal(-99);
- private static final long negative = -99;
+ private static final BigDecimal negative = new BigDecimal(-99.99);
@Transient
- //private static final BigDecimal positive = new BigDecimal(99);
- private static final long positive = 99;
+ private static final BigDecimal positive = new BigDecimal(99.99);
@Id
@GeneratedValue
@@ -60,13 +59,10 @@
@Basic
@DecimalMin(value = "0")
- //private BigDecimal minZero;
- private long minZero;
+ private BigDecimal minZero;
@Basic
- @DecimalMax(value = "0")
- //private BigDecimal maxZero;
- private long maxZero;
+ private BigDecimal maxZero; // @DecimalMax(value = "0") constraint is
on the getter
/*
@@ -111,19 +107,20 @@
return id;
}
- public long getMinZero() {
+ public BigDecimal getMinZero() {
return minZero;
}
- public void setMinZero(long d) {
+ public void setMinZero(BigDecimal d) {
minZero = d;
}
- public long getMaxZero() {
+ @DecimalMax(value = "0")
+ public BigDecimal getMaxZero() {
return maxZero;
}
- public void setMaxZero(long d) {
+ public void setMaxZero(BigDecimal d) {
maxZero = d;
}
}
Modified:
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintNull.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintNull.java?rev=791554&r1=791553&r2=791554&view=diff
==============================================================================
---
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintNull.java
(original)
+++
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintNull.java
Mon Jul 6 18:08:18 2009
@@ -53,8 +53,7 @@
private String nullRequired;
@Basic
- @NotNull
- private String nullInvalid;
+ private String nullInvalid; // @NotNull constraint is on the getter
/*
@@ -98,6 +97,7 @@
nullRequired = s;
}
+ @NotNull
public String getNullInvalid() {
return nullInvalid;
}
Modified:
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java?rev=791554&r1=791553&r2=791554&view=diff
==============================================================================
---
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
(original)
+++
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
Mon Jul 6 18:08:18 2009
@@ -13,6 +13,8 @@
*/
package org.apache.openjpa.integration.validation;
+import java.util.List;
+
import javax.persistence.Query;
import javax.persistence.ValidationMode;
import javax.validation.ConstraintViolationException;
@@ -38,11 +40,11 @@
*
* Basic constraint tests for violation exceptions:
* 4) Persist @Null constraint exception on variables in mode=AUTO
- * 5) Persist @NotNull constraint exception on variables in mode=AUTO
+ * 5) Persist @NotNull constraint exception on getter in mode=AUTO
* 7) Test @AssertTrue constraint exception on variables in mode=AUTO
- * 8) Test @AssertFalse constraint exception on variables in mode=AUTO
+ * 8) Test @AssertFalse constraint exception on getter in mode=AUTO
* 10) Test @DecimalMin constraint exception on variables in mode=AUTO
- * 11) Test @DecimalMax constraint exception on variables in mode=AUTO
+ * 11) Test @DecimalMax constraint exception on getter in mode=AUTO
*
* Basic constraint test for no violations:
* 6) Persist @NotNull and @Null constraints pass in mode=AUTO
@@ -108,10 +110,10 @@
em.flush();
em.getTransaction().commit();
getLog().trace("testNullUpdateConstraint() Part 2 of 2 failed");
- fail("Expected a Validation exception");
+ fail("Expected a ConstraintViolationException");
} catch (ConstraintViolationException e) {
// expected
- getLog().trace("Caught expected exception = " + e);
+ getLog().trace("Caught expected ConstraintViolationException = " +
e);
getLog().trace("testNullUpdateConstraint() Part 2 of 2 passed");
} finally {
if ((em != null) && em.isOpen()) {
@@ -155,7 +157,7 @@
} catch (Exception e) {
// unexpected
getLog().trace("testNullDeleteIgnored() Part 1 of 2 failed");
- fail("Unexpected Validation exception = " + e);
+ fail("Caught unexpected exception = " + e);
} finally {
if ((em != null) && em.isOpen()) {
if (em.getTransaction().isActive())
@@ -191,7 +193,7 @@
} catch (Exception e) {
// unexpected
getLog().trace("testNullDeleteIgnored() Part 2 of 2 failed");
- fail("Unexpected Validation exception = " + e);
+ fail("Caught unexpected exception = " + e);
} finally {
if ((em != null) && em.isOpen()) {
if (em.getTransaction().isActive())
@@ -235,7 +237,7 @@
} catch (Exception e) {
// unexpected
getLog().trace("testNullConstraintIgnored() failed");
- fail("Unexpected Validation exception = " + e);
+ fail("Caught unexpected exception = " + e);
} finally {
if ((em != null) && em.isOpen()) {
if (em.getTransaction().isActive())
@@ -270,10 +272,10 @@
em.persist(c);
em.getTransaction().commit();
getLog().trace("testNullConstraint() failed");
- fail("Expected a Validation exception");
+ fail("Expected a ConstraintViolationException");
} catch (ConstraintViolationException e) {
// expected
- getLog().trace("Caught expected exception = " + e);
+ getLog().trace("Caught expected ConstraintViolationException = " +
e);
getLog().trace("testNullConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
@@ -286,7 +288,7 @@
/**
* Scenario being tested:
- * 5) Test @NotNull constraint exception on variables in mode=AUTO
+ * 5) Test @NotNull constraint exception on getter in mode=AUTO
* Basic constraint test for a violation exception.
*/
public void testNotNullConstraint() {
@@ -306,10 +308,10 @@
em.persist(c);
em.getTransaction().commit();
getLog().trace("testNotNullConstraint() failed");
- fail("Expected a Validation exception");
+ fail("Expected a ConstraintViolationException");
} catch (ConstraintViolationException e) {
// expected
- getLog().trace("Caught expected exception = " + e);
+ getLog().trace("Caught expected ConstraintViolationException = " +
e);
getLog().trace("testNotNullConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
@@ -377,10 +379,10 @@
em.persist(c);
em.getTransaction().commit();
getLog().trace("testAssertTrueConstraint() failed");
- fail("Expected a Validation exception");
+ fail("Expected a ConstraintViolationException");
} catch (ConstraintViolationException e) {
// expected
- getLog().trace("Caught expected exception = " + e);
+ getLog().trace("Caught expected ConstraintViolationException = " +
e);
getLog().trace("testAssertTrueConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
@@ -393,7 +395,7 @@
/**
* Scenario being tested:
- * 8) Test @AssertFalse constraint exception on variables in mode=AUTO
+ * 8) Test @AssertFalse constraint exception on getter in mode=AUTO
* Basic constraint test for a violation exception.
*/
public void testAssertFalseConstraint() {
@@ -413,10 +415,10 @@
em.persist(c);
em.getTransaction().commit();
getLog().trace("testAssertFalseConstraint() failed");
- fail("Expected a Validation exception");
+ fail("Expected a ConstraintViolationException");
} catch (ConstraintViolationException e) {
// expected
- getLog().trace("Caught expected exception = " + e);
+ getLog().trace("Caught expected ConstraintViolationException = " +
e);
getLog().trace("testAssertFalseConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
@@ -484,10 +486,10 @@
em.persist(c);
em.getTransaction().commit();
getLog().trace("testDecimalMinConstraint() failed");
- fail("Expected a Validation exception");
- } catch (Exception e) {
+ fail("Expected a ConstraintViolationException");
+ } catch (ConstraintViolationException e) {
// expected
- getLog().trace("Caught expected exception = " + e);
+ getLog().trace("Caught expected ConstraintViolationException = " +
e);
getLog().trace("testDecimalMinConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
@@ -500,7 +502,7 @@
/**
* Scenario being tested:
- * 11) Test @DecimalMax constraint exception on variables in mode=AUTO
+ * 11) Test @DecimalMax constraint exception on getter in mode=AUTO
* Basic constraint test for a violation exception.
*/
public void testDecimalMaxConstraint() {
@@ -520,10 +522,10 @@
em.persist(c);
em.getTransaction().commit();
getLog().trace("testDecimalMaxConstraint() failed");
- fail("Expected a Validation exception");
+ fail("Expected a ConstraintViolationException");
} catch (Exception e) {
// expected
- getLog().trace("Caught expected exception = " + e);
+ getLog().trace("Caught expected ConstraintViolationException = " +
e);
getLog().trace("testDecimalMaxConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
@@ -569,6 +571,7 @@
}
}
+
/**
* Internal convenience method for getting the OpenJPA logger
Modified:
openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml?rev=791554&r1=791553&r2=791554&view=diff
==============================================================================
---
openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml
(original)
+++
openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml
Mon Jul 6 18:08:18 2009
@@ -40,6 +40,26 @@
<validation-mode>NONE</validation-mode>
</persistence-unit>
+ <persistence-unit name="boolean-none-mode">
+
<class>org.apache.openjpa.integration.validation.ConstraintBoolean</class>
+ <validation-mode>NONE</validation-mode>
+ </persistence-unit>
+
+ <persistence-unit name="boolean-callback-mode">
+
<class>org.apache.openjpa.integration.validation.ConstraintBoolean</class>
+ <validation-mode>CALLBACK</validation-mode>
+ </persistence-unit>
+
+ <persistence-unit name="decimal-none-mode">
+
<class>org.apache.openjpa.integration.validation.ConstraintDecimal</class>
+ <validation-mode>NONE</validation-mode>
+ </persistence-unit>
+
+ <persistence-unit name="decimal-callback-mode">
+
<class>org.apache.openjpa.integration.validation.ConstraintDecimal</class>
+ <validation-mode>CALLBACK</validation-mode>
+ </persistence-unit>
+
<persistence-unit name="null-none-mode">
<class>org.apache.openjpa.integration.validation.ConstraintNull</class>
<validation-mode>NONE</validation-mode>