Author: dwoods
Date: Thu Jul 2 19:44:18 2009
New Revision: 790722
URL: http://svn.apache.org/viewvc?rev=790722&view=rev
Log:
OPENJPA-1106 Add tests for DecimalMin/Max constraints. Upgrade to agimatec
0.9.1-SNAPSHOT which has been updated to the 1.0.CR1 API level and now includes
support for DecimalMin/Max constraints.
Added:
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintDecimal.java
(with props)
Modified:
openjpa/trunk/openjpa-integration/validation/pom.xml
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/TestConstraints.java
Modified: openjpa/trunk/openjpa-integration/validation/pom.xml
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/pom.xml?rev=790722&r1=790721&r2=790722&view=diff
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/pom.xml (original)
+++ openjpa/trunk/openjpa-integration/validation/pom.xml Thu Jul 2 19:44:18
2009
@@ -67,7 +67,7 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
- <version>1.0.Beta4</version>
+ <version>1.0.CR1</version>
<scope>test</scope>
</dependency>
-->
@@ -79,13 +79,13 @@
<dependency>
<groupId>com.agimatec</groupId>
<artifactId>agimatec-jsr303</artifactId>
- <version>0.9.0-SNAPSHOT</version>
+ <version>0.9.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.agimatec</groupId>
<artifactId>agimatec-validation</artifactId>
- <version>0.9.0-SNAPSHOT</version>
+ <version>0.9.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
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=790722&r1=790721&r2=790722&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
Thu Jul 2 19:44:18 2009
@@ -23,11 +23,19 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.AssertFalse;
import javax.validation.constraints.AssertTrue;
+...@namedqueries( {
+ @NamedQuery(name="FindFirst",
+ query="select c from VBOOLEAN c where c.id = 1"),
+ @NamedQuery(name="FindAll", query="select c from VBOOLEAN c")
+})
+
@Entity(name = "VBOOLEAN")
@Table(name = "BOOLEAN_ENTITY")
public class ConstraintBoolean implements Serializable {
Added:
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=790722&view=auto
==============================================================================
---
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintDecimal.java
(added)
+++
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintDecimal.java
Thu Jul 2 19:44:18 2009
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.integration.validation;
+
+import java.io.Serializable;
+//import java.math.BigDecimal;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
+
+
+...@namedqueries( {
+ @NamedQuery(name="FindFirst",
+ query="select c from VDECIMAL c where c.id = 1"),
+ @NamedQuery(name="FindAll", query="select c from VDECIMAL c")
+})
+
+...@entity(name = "VDECIMAL")
+...@table(name = "DECIMAL_ENTITY")
+public class ConstraintDecimal implements Serializable {
+
+ @Transient
+ private static final long serialVersionUID = 1L;
+
+ @Transient
+ //private static final BigDecimal negative = new BigDecimal(-99);
+ private static final long negative = -99;
+
+ @Transient
+ //private static final BigDecimal positive = new BigDecimal(99);
+ private static final long positive = 99;
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @Basic
+ @DecimalMin(value = "0")
+ //private BigDecimal minZero;
+ private long minZero;
+
+ @Basic
+ @DecimalMax(value = "0")
+ //private BigDecimal maxZero;
+ private long maxZero;
+
+
+ /*
+ * Some helper methods to create the entities to test with
+ */
+ public static ConstraintDecimal createInvalidMin() {
+ ConstraintDecimal c = new ConstraintDecimal();
+ c.setMinZero(negative);
+ c.setMaxZero(negative);
+ return c;
+ }
+
+ public static ConstraintDecimal createInvalidMax() {
+ ConstraintDecimal c = new ConstraintDecimal();
+ c.setMinZero(positive);
+ c.setMaxZero(positive);
+ return c;
+ }
+
+ public static ConstraintDecimal createInvalidMinMax() {
+ ConstraintDecimal c = new ConstraintDecimal();
+ c.setMinZero(negative);
+ c.setMaxZero(positive);
+ return c;
+ }
+
+ public static ConstraintDecimal createValid() {
+ ConstraintDecimal c = new ConstraintDecimal();
+ c.setMinZero(positive);
+ c.setMaxZero(negative);
+ return c;
+ }
+
+
+ /*
+ * Main entity code
+ */
+ public ConstraintDecimal() {
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getMinZero() {
+ return minZero;
+ }
+
+ public void setMinZero(long d) {
+ minZero = d;
+ }
+
+ public long getMaxZero() {
+ return maxZero;
+ }
+
+ public void setMaxZero(long d) {
+ maxZero = d;
+ }
+}
Propchange:
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintDecimal.java
------------------------------------------------------------------------------
svn:eol-style = native
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=790722&r1=790721&r2=790722&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
Thu Jul 2 19:44:18 2009
@@ -29,22 +29,25 @@
* focusing on the following Validation scenarios:
*
* Check special update/delete/ignore cases once:
- * 1) Update @Null constraint exception on variables in mode=AUTO
- * Tests that a constraint violation will occur on invalid update.
- * 2) No invalid Delete @Null constraint exception when mode=AUTO
- * Tests that a violation will not occur when deleting invalid entity.
- * 3) No invalid Persist constraint exception when mode=NONE
- * Tests that no Validation Providers are used when disabled.
+ * 1) Update @Null constraint exception on variables in mode=AUTO
+ * Tests that a constraint violation will occur on invalid update.
+ * 2) No invalid Delete @Null constraint exception when mode=AUTO
+ * Tests that a violation will not occur when deleting invalid entity.
+ * 3) No invalid Persist constraint exception when mode=NONE
+ * Tests that no Validation Providers are used when disabled.
*
* 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
- * 7) Test @AssertTrue constraint exception on variables in mode=AUTO
- * 8) Test @AssertFalse constraint exception on variables in mode=AUTO
+ * 4) Persist @Null constraint exception on variables in mode=AUTO
+ * 5) Persist @NotNull constraint exception on variables in mode=AUTO
+ * 7) Test @AssertTrue constraint exception on variables in mode=AUTO
+ * 8) Test @AssertFalse constraint exception on variables in mode=AUTO
+ * 10) Test @DecimalMin constraint exception on variables in mode=AUTO
+ * 11) Test @DecimalMax constraint exception on variables in mode=AUTO
*
* Basic constraint test for no violations:
- * 6) Persist @NotNull and @Null constraints pass in mode=AUTO
- * 9) Test @AssertFalse and @AssertTrue constraints pass in mode=AUTO
+ * 6) Persist @NotNull and @Null constraints pass in mode=AUTO
+ * 9) Test @AssertFalse and @AssertTrue constraints pass in mode=AUTO
+ * 12) Test @DecimalMin and @DecimalMax constraints pass in mode=AUTO
*
* @version $Rev$ $Date$
*/
@@ -53,7 +56,8 @@
@Override
public void setUp() {
super.setUp(CLEAR_TABLES,
- ConstraintNull.class, ConstraintBoolean.class);
+ ConstraintNull.class, ConstraintBoolean.class,
+ ConstraintDecimal.class);
}
/**
@@ -86,6 +90,8 @@
fail("Caught unexpected exception = " + e);
} finally {
if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
em.close();
}
}
@@ -152,6 +158,8 @@
fail("Unexpected Validation exception = " + e);
} finally {
if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
em.close();
}
if ((emf != null) && emf.isOpen()) {
@@ -230,6 +238,8 @@
fail("Unexpected Validation exception = " + e);
} finally {
if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
em.close();
}
if ((emf != null) && emf.isOpen()) {
@@ -267,6 +277,8 @@
getLog().trace("testNullConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
em.close();
}
}
@@ -301,6 +313,8 @@
getLog().trace("testNotNullConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
em.close();
}
}
@@ -330,9 +344,12 @@
getLog().trace("testNullNotNullConstraint() passed");
} catch (Exception e) {
// unexpected
+ getLog().trace("testNullNotNullConstraint() failed");
fail("Caught unexpected exception = " + e);
} finally {
if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
em.close();
}
}
@@ -367,6 +384,8 @@
getLog().trace("testAssertTrueConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
em.close();
}
}
@@ -401,6 +420,8 @@
getLog().trace("testAssertFalseConstraint() passed");
} finally {
if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
em.close();
}
}
@@ -430,9 +451,119 @@
getLog().trace("testAssertTrueFalseConstraint() passed");
} catch (Exception e) {
// unexpected
+ getLog().trace("testAssertTrueFalseConstraint() failed");
+ fail("Caught unexpected exception = " + e);
+ } finally {
+ if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
+ em.close();
+ }
+ }
+ }
+
+ /**
+ * Scenario being tested:
+ * 10) Test @DecimalMin constraint exception on variables in mode=AUTO
+ * Basic constraint test for a violation exception.
+ */
+ public void testDecimalMinConstraint() {
+ getLog().trace("testDecimalMinConstraint() started");
+ // create EM from default EMF
+ OpenJPAEntityManager em = emf.createEntityManager();
+ assertNotNull(em);
+ try {
+ // verify Validation Mode
+ OpenJPAConfiguration conf = em.getConfiguration();
+ assertNotNull(conf);
+ assertTrue("ValidationMode",
+ conf.getValidationMode().equalsIgnoreCase("AUTO"));
+ // create invalid ConstraintBoolean instance
+ em.getTransaction().begin();
+ ConstraintDecimal c = ConstraintDecimal.createInvalidMin();
+ em.persist(c);
+ em.getTransaction().commit();
+ getLog().trace("testDecimalMinConstraint() failed");
+ fail("Expected a Validation exception");
+ } catch (Exception e) {
+ // expected
+ getLog().trace("Caught expected exception = " + e);
+ getLog().trace("testDecimalMinConstraint() passed");
+ } finally {
+ if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
+ em.close();
+ }
+ }
+ }
+
+ /**
+ * Scenario being tested:
+ * 11) Test @DecimalMax constraint exception on variables in mode=AUTO
+ * Basic constraint test for a violation exception.
+ */
+ public void testDecimalMaxConstraint() {
+ getLog().trace("testDecimalMaxConstraint() started");
+ // create EM from default EMF
+ OpenJPAEntityManager em = emf.createEntityManager();
+ assertNotNull(em);
+ try {
+ // verify Validation Mode
+ OpenJPAConfiguration conf = em.getConfiguration();
+ assertNotNull(conf);
+ assertTrue("ValidationMode",
+ conf.getValidationMode().equalsIgnoreCase("AUTO"));
+ // create invalid ConstraintBoolean instance
+ em.getTransaction().begin();
+ ConstraintDecimal c = ConstraintDecimal.createInvalidMax();
+ em.persist(c);
+ em.getTransaction().commit();
+ getLog().trace("testDecimalMaxConstraint() failed");
+ fail("Expected a Validation exception");
+ } catch (Exception e) {
+ // expected
+ getLog().trace("Caught expected exception = " + e);
+ getLog().trace("testDecimalMaxConstraint() passed");
+ } finally {
+ if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
+ em.close();
+ }
+ }
+ }
+
+ /**
+ * Scenario being tested:
+ * 12) Test @DecimalMin and @DecimalMax constraints pass in mode=AUTO
+ * Basic constraint test for no violations.
+ */
+ public void testDecimalMinMaxConstraint() {
+ getLog().trace("testDecimalMinMaxConstraint() started");
+ // create EM from default EMF
+ OpenJPAEntityManager em = emf.createEntityManager();
+ assertNotNull(em);
+ try {
+ // verify Validation Mode
+ OpenJPAConfiguration conf = em.getConfiguration();
+ assertNotNull(conf);
+ assertTrue("ValidationMode",
+ conf.getValidationMode().equalsIgnoreCase("AUTO"));
+ // create valid ConstraintBoolean instance
+ em.getTransaction().begin();
+ ConstraintDecimal c = ConstraintDecimal.createValid();
+ em.persist(c);
+ em.getTransaction().commit();
+ getLog().trace("testDecimalMinMaxConstraint() passed");
+ } catch (Exception e) {
+ // unexpected
+ getLog().trace("testDecimalMinMaxConstraint() failed");
fail("Caught unexpected exception = " + e);
} finally {
if ((em != null) && em.isOpen()) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
em.close();
}
}