You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2009/06/26 22:06:40 UTC

svn commit: r788849 - in /openjpa/trunk/openjpa-integration/validation/src/test: java/org/apache/openjpa/integration/validation/ resources/org/apache/openjpa/integration/validation/

Author: dwoods
Date: Fri Jun 26 20:06:40 2009
New Revision: 788849

URL: http://svn.apache.org/viewvc?rev=788849&view=rev
Log:
OPENJPA-1106 Initial @Null and @NotNull validation contraint tests along with other entity classes for future tests to be added.

Added:
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Address.java   (with props)
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintNull.java   (with props)
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Customer.java   (with props)
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IAddress.java   (with props)
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ICustomer.java   (with props)
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IPerson.java   (with props)
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Person.java   (with props)
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java   (with props)
Modified:
    openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml

Added: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Address.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Address.java?rev=788849&view=auto
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Address.java (added)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Address.java Fri Jun 26 20:06:40 2009
@@ -0,0 +1,113 @@
+/*
+ * 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 javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Transient;
+import javax.validation.constraints.NotNull;
+
+@Entity(name="VAddress")
+@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
+public class Address implements IAddress, Serializable {
+    @Transient
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue
+    private long id;
+
+    @Basic
+    @NotNull
+    private String streetAddress;
+
+    @Basic
+    @NotNull
+    private String city;
+
+    @Basic
+    @NotNull
+    private String state;
+
+    @Basic
+    @NotNull
+    private String postalCode;
+
+    @Basic
+    private String phoneNumber;
+
+    public void setStreetAddress(String streetAddress) {
+        this.streetAddress = streetAddress;
+    }
+
+    public String getStreetAddress() {
+        return this.streetAddress;
+    }
+
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getCity() {
+        return this.city;
+    }
+
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public String getState() {
+        return this.state;
+    }
+
+
+    public void setPostalCode(String postalCode) {
+        this.postalCode = postalCode;
+    }
+
+    public String getPostalCode() {
+        return this.postalCode;
+    }
+
+
+    public void setPhoneNumber(String phoneNumber) {
+        this.phoneNumber = phoneNumber;
+    }
+
+    public String getPhoneNumber() {
+        return this.phoneNumber;
+    }
+
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getId() {
+        return this.id;
+    }
+}

Propchange: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Address.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=788849&view=auto
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintNull.java (added)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintNull.java Fri Jun 26 20:06:40 2009
@@ -0,0 +1,100 @@
+/*
+ * 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 javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Null;
+
+@Entity(name = "VNULL")
+@Table(name = "NULL_ENTITY")
+public class ConstraintNull implements Serializable {
+
+    @Transient
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue
+    private long id;
+
+    @Basic
+    @Null
+    private String nullRequired;
+
+    @Basic
+    @NotNull
+    private String nullInvalid;
+
+    
+    /* 
+     * Some helper methods to create the entities to test with
+     */
+    public static ConstraintNull createInvalidNotNull() {
+        ConstraintNull c = new ConstraintNull();
+        return c;
+    }
+
+    public static ConstraintNull createInvalidNull() {
+        ConstraintNull c = new ConstraintNull();
+        c.setNullInvalid("not null");
+        c.setNullRequired("not null");
+        return c;
+    }
+
+    public static ConstraintNull createValid() {
+        ConstraintNull c = new ConstraintNull();
+        c.setNullInvalid("not null");
+        c.setNullRequired(null);
+        return c;
+    }
+
+    
+    /*
+     * Main entity code
+     */
+    public ConstraintNull() {
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public String getNullRequired() {
+        return nullRequired;
+    }
+
+    public void setNullRequired(String s) {
+        nullRequired = s;
+    }
+
+    public String getNullInvalid() {
+        return nullInvalid;
+    }
+
+    public void setNullInvalid(String s) {
+        nullInvalid = s;
+    }
+
+}

Propchange: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ConstraintNull.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Customer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Customer.java?rev=788849&view=auto
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Customer.java (added)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Customer.java Fri Jun 26 20:06:40 2009
@@ -0,0 +1,56 @@
+/*
+ * 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 javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.OneToOne;
+import javax.persistence.Transient;
+
+@Entity(name="VCustomer")
+public class Customer extends Person implements ICustomer, Serializable {
+    @Transient
+    private static final long serialVersionUID = 1L;
+
+    @OneToOne(fetch=FetchType.LAZY)
+    private Address shippingAddress;
+
+    @OneToOne(fetch=FetchType.LAZY)
+    private Address billingAddress;
+
+
+    public void setShippingAddress(IAddress shippingAddress) {
+        this.shippingAddress = (Address) shippingAddress;
+    }
+
+    public IAddress getShippingAddress() {
+        return this.shippingAddress;
+    }
+
+
+    public void setBillingAddress(IAddress billingAddress) {
+        this.billingAddress = (Address) billingAddress;
+    }
+
+    public IAddress getBillingAddress() {
+        return this.billingAddress;
+    }
+}

Propchange: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Customer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IAddress.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IAddress.java?rev=788849&view=auto
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IAddress.java (added)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IAddress.java Fri Jun 26 20:06:40 2009
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+public interface IAddress {
+
+    public void setStreetAddress(String streetAddress);
+    public String getStreetAddress();
+
+    public void setCity(String city);
+    public String getCity();
+
+    public void setState(String state);
+    public String getState();
+
+    public void setPostalCode(String postalCode);
+    public String getPostalCode();
+
+    public void setPhoneNumber(String phoneNumber);
+    public String getPhoneNumber();
+}

Propchange: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IAddress.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ICustomer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ICustomer.java?rev=788849&view=auto
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ICustomer.java (added)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ICustomer.java Fri Jun 26 20:06:40 2009
@@ -0,0 +1,30 @@
+/*
+ * 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.util.*;
+
+public interface ICustomer extends IPerson {
+
+    public void setShippingAddress(IAddress shippingAddress);
+    public IAddress getShippingAddress();
+
+    public void setBillingAddress(IAddress billingAddress);
+    public IAddress getBillingAddress();
+}

Propchange: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ICustomer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IPerson.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IPerson.java?rev=788849&view=auto
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IPerson.java (added)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IPerson.java Fri Jun 26 20:06:40 2009
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+public interface IPerson {
+
+    public void setFirstName(String firstName);
+    public String getFirstName();
+
+    public void setLastName(String lastName);
+    public String getLastName();
+
+    public void setHomeAddress(IAddress homeAddress);
+    public IAddress getHomeAddress();
+}

Propchange: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/IPerson.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Person.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Person.java?rev=788849&view=auto
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Person.java (added)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Person.java Fri Jun 26 20:06:40 2009
@@ -0,0 +1,92 @@
+/*
+ * 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 javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToOne;
+import javax.persistence.Transient;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+
+@Entity(name="VPerson")
+@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
+public abstract class Person implements IPerson, Serializable {
+    @Transient
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue
+    private long id;
+
+    @Basic
+    @NotNull
+    private String firstName;
+
+    @Basic
+    @NotNull
+    private String lastName;
+
+    @OneToOne
+    @Valid
+    @NotNull
+    private Address homeAddress;
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getFirstName() {
+        return this.firstName;
+    }
+
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public String getLastName() {
+        return this.lastName;
+    }
+
+
+    public void setHomeAddress(IAddress homeAddress) {
+        this.homeAddress = (Address) homeAddress;
+    }
+
+    public IAddress getHomeAddress() {
+        return this.homeAddress;
+    }
+
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getId() {
+        return this.id;
+    }
+
+}

Propchange: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/Person.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=788849&view=auto
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java (added)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java Fri Jun 26 20:06:40 2009
@@ -0,0 +1,155 @@
+/*
+ * 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 javax.persistence.ValidationMode;
+
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Tests the new Bean Validation constraint support in the JPA 2.0 spec by
+ * focusing on the following Validation scenarios:
+ *   1) Test @Null constraint exception on variables in mode=AUTO
+ *   2) Test @NotNull constraint exception on variables in mode=AUTO
+ *   3) Test no constraint exception when mode=NONE
+ *    
+ * @version $Rev$ $Date$
+ */
+public class TestConstraints extends SingleEMFTestCase {
+
+    @Override
+    public void setUp() {
+        super.setUp(CLEAR_TABLES, ConstraintNull.class);
+    }
+
+    /**
+     * Scenario being tested:
+     *   1) Test @Null constraint exception on variables in mode=AUTO
+     */
+    public void testNullConstraint() {
+        getLog().trace("testNullConstraint() 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 ConstraintNull instance
+            em.getTransaction().begin();
+            ConstraintNull c = ConstraintNull.createInvalidNull();
+            em.persist(c);
+            em.getTransaction().commit();
+            getLog().trace("testNullConstraint() failed");
+            fail("Expected a Validation exception");
+        } catch (Exception e) {
+            // expected
+            getLog().trace("Caught expected exception = " + e);
+            getLog().trace("testNullConstraint() passed");
+        } finally {
+            if ((em != null) && em.isOpen()) {
+                em.close();
+            }
+        }
+    }
+
+    /**
+     * Scenario being tested:
+     *   2) Test @NotNull constraint exception on variables in mode=AUTO
+     */
+    public void testNotNullConstraint() {
+        getLog().trace("testNotNullConstraint() 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 ConstraintNull instance
+            em.getTransaction().begin();
+            ConstraintNull c = ConstraintNull.createInvalidNotNull();
+            em.persist(c);
+            em.getTransaction().commit();
+            getLog().trace("testNotNullConstraint() failed");
+            fail("Expected a Validation exception");
+        } catch (Exception e) {
+            // expected
+            getLog().trace("Caught expected exception = " + e);
+            getLog().trace("testNotNullConstraint() passed");
+        } finally {
+            if ((em != null) && em.isOpen()) {
+                em.close();
+            }
+        }
+    }
+
+    /**
+     * Scenario being tested:
+     *   3) Test no constraint exception when mode=NONE
+     */
+    public void testNullConstraintIgnored() {
+        getLog().trace("testNullConstraintIgnored() started");
+        // create our EMF w/ props
+        OpenJPAEntityManagerFactory emf = OpenJPAPersistence
+            .createEntityManagerFactory(
+                "null-none-mode",
+                "org/apache/openjpa/integration/validation/persistence.xml");
+        assertNotNull(emf);
+        // create EM
+        OpenJPAEntityManager em = emf.createEntityManager();
+        assertNotNull(em);
+        try {
+            // verify Validation Mode
+            OpenJPAConfiguration conf = em.getConfiguration();
+            assertNotNull(conf);
+            assertTrue("ValidationMode",
+                conf.getValidationMode().equalsIgnoreCase("NONE"));
+            // create invalid ConstraintNull instance
+            em.getTransaction().begin();
+            ConstraintNull c = ConstraintNull.createInvalidNull();
+            em.persist(c);
+            em.getTransaction().commit();
+            getLog().trace("testNullConstraintIgnored() passed");
+        } catch (Exception e) {
+            // unexpected
+            getLog().trace("testNullConstraintIgnored() failed");
+            fail("Unexpected Validation exception = " + e);
+        } finally {
+            if ((em != null) && em.isOpen()) {
+                em.close();
+            }
+        }
+    }
+
+    
+    /**
+     * Internal convenience method for getting the OpenJPA logger
+     * 
+     * @return
+     */
+    private Log getLog() {
+        return emf.getConfiguration().getLog("Tests");
+    }
+}

Propchange: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=788849&r1=788848&r2=788849&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 Fri Jun 26 20:06:40 2009
@@ -40,4 +40,9 @@
         <validation-mode>NONE</validation-mode>
     </persistence-unit>
     
+    <persistence-unit name="null-none-mode">
+    	<class>org.apache.openjpa.integration.validation.ConstraintNull</class>
+        <validation-mode>NONE</validation-mode>
+    </persistence-unit>
+    
 </persistence>