[hibernate-commits] Hibernate SVN: r19597 - in validator/trunk: hibernate-validator and 4 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon May 24 15:18:22 EDT 2010


Author: hardy.ferentschik
Date: 2010-05-24 15:18:21 -0400 (Mon, 24 May 2010)
New Revision: 19597

Added:
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/HibernateTestCase.java
   validator/trunk/hibernate-validator/src/test/resources/hibernate.properties
Modified:
   validator/trunk/hibernate-validator-tck-runner/pom.xml
   validator/trunk/hibernate-validator/pom.xml
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java
   validator/trunk/pom.xml
Log:
HV-281 Added some helper classes to allow integration tests with Hibernate Core. This this particular issue there was in the end no new test case needed though. Keeping the infrastructure classes.

Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml	2010-05-24 10:31:09 UTC (rev 19596)
+++ validator/trunk/hibernate-validator/pom.xml	2010-05-24 19:18:21 UTC (rev 19597)
@@ -69,8 +69,8 @@
         Optional dependencies
         -->
         <dependency>
-            <groupId>org.hibernate.java-persistence</groupId>
-            <artifactId>jpa-api</artifactId>
+            <groupId>org.hibernate.javax.persistence</groupId>
+            <artifactId>hibernate-jpa-2.0-api</artifactId>
             <optional>true</optional>
         </dependency>
 
@@ -86,10 +86,24 @@
         <dependency>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-entitymanager</artifactId>
-            <version>3.5.0-Final</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
+
+    <properties>
+        <db.dialect>org.hibernate.dialect.H2Dialect</db.dialect>
+        <jdbc.driver>org.h2.Driver</jdbc.driver>
+        <jdbc.url>jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1</jdbc.url>
+        <jdbc.user>sa</jdbc.user>
+        <jdbc.pass/>
+        <jdbc.isolation/>
+    </properties>
+
     <build>
         <defaultGoal>test</defaultGoal>
         <resources>
@@ -102,6 +116,16 @@
                 <targetPath>META-INF</targetPath>
             </resource>
         </resources>
+        <testResources>
+            <testResource>
+                <filtering>true</filtering>
+                <directory>src/test/resources</directory>
+                <includes>
+                    <include>**/*.properties</include>
+                    <include>**/*.xml</include>
+                </includes>
+            </testResource>
+        </testResources>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>

Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java	2010-05-24 10:31:09 UTC (rev 19596)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java	2010-05-24 19:18:21 UTC (rev 19597)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
 /*
  * JBoss, Home of Professional Open Source
  * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
@@ -34,7 +34,6 @@
 	}
 
 	public String getName() {
-
 		return name;
 	}
 

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/HibernateTestCase.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/HibernateTestCase.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/HibernateTestCase.java	2010-05-24 19:18:21 UTC (rev 19597)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+
+// $Id:$
+package org.hibernate.validator.test.util;
+
+import java.io.InputStream;
+import java.util.Properties;
+import javax.validation.ValidatorFactory;
+
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+
+/**
+ * Base class for validation test which work in combination with Hibernate Core.
+ *
+ * @author Hardy Ferentschik
+ */
+public abstract class HibernateTestCase {
+	private SessionFactory sessionFactory;
+	private Configuration cfg;
+
+	@BeforeTest
+	protected void setUp() throws Exception {
+		buildSessionFactory( getAnnotatedClasses(), getAnnotatedPackages(), getXmlFiles() );
+	}
+
+	@AfterTest
+	protected void tearDown() throws Exception {
+		SchemaExport export = new SchemaExport( cfg );
+		export.drop( false, true );
+		sessionFactory = null;
+	}
+
+	public SessionFactory getSessionFactory() {
+		return sessionFactory;
+	}
+
+	private void buildSessionFactory(Class<?>[] classes, String[] packages, String[] xmlFiles) throws Exception {
+		if ( sessionFactory != null ) {
+			sessionFactory.close();
+		}
+		try {
+			setCfg( new AnnotationConfiguration() );
+			configure( cfg );
+			if ( recreateSchema() ) {
+				cfg.setProperty( org.hibernate.cfg.Environment.HBM2DDL_AUTO, "create-drop" );
+			}
+			for ( String aPackage : packages ) {
+				( ( AnnotationConfiguration ) getCfg() ).addPackage( aPackage );
+			}
+			for ( Class<?> aClass : classes ) {
+				( ( AnnotationConfiguration ) getCfg() ).addAnnotatedClass( aClass );
+			}
+			for ( String xmlFile : xmlFiles ) {
+				InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
+				getCfg().addInputStream( is );
+			}
+			sessionFactory = getCfg().buildSessionFactory();
+		}
+		catch ( Exception e ) {
+			e.printStackTrace();
+			throw e;
+		}
+	}
+
+	protected void configure(Configuration cfg) {
+		Properties prop = cfg.getProperties();
+		//prop.put( "javax.persistence.validation.mode", "none" );
+		prop.put( "javax.persistence.validation.factory", getValidatorFactory() );
+		prop.put( "hibernate.current_session_context_class", "thread" );
+	}
+
+	protected abstract ValidatorFactory getValidatorFactory();
+
+	protected abstract Class<?>[] getAnnotatedClasses();
+
+	protected String[] getAnnotatedPackages() {
+		return new String[] { };
+	}
+
+	protected String[] getXmlFiles() {
+		return new String[] { };
+	}
+
+	protected boolean recreateSchema() {
+		return true;
+	}
+
+	protected void setCfg(Configuration cfg) {
+		this.cfg = cfg;
+	}
+
+	protected Configuration getCfg() {
+		return cfg;
+	}
+}
+
+
+


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/HibernateTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/hibernate-validator/src/test/resources/hibernate.properties
===================================================================
--- validator/trunk/hibernate-validator/src/test/resources/hibernate.properties	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/resources/hibernate.properties	2010-05-24 19:18:21 UTC (rev 19597)
@@ -0,0 +1,30 @@
+#
+# JBoss, Home of Professional Open Source
+# Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# Licensed 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.
+#
+
+hibernate.dialect ${db.dialect}
+hibernate.connection.driver_class ${jdbc.driver}
+hibernate.connection.url ${jdbc.url}
+hibernate.connection.username ${jdbc.user}
+hibernate.connection.password ${jdbc.pass}
+hibernate.connection.isolation ${jdbc.isolation}
+
+hibernate.connection.pool_size 5
+
+hibernate.show_sql true
+hibernate.format_sql true
+
+

Modified: validator/trunk/hibernate-validator-tck-runner/pom.xml
===================================================================
--- validator/trunk/hibernate-validator-tck-runner/pom.xml	2010-05-24 10:31:09 UTC (rev 19596)
+++ validator/trunk/hibernate-validator-tck-runner/pom.xml	2010-05-24 19:18:21 UTC (rev 19597)
@@ -38,6 +38,12 @@
         <dependency>
             <groupId>org.jboss.test-harness</groupId>
             <artifactId>jboss-test-harness-jboss-as-51</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.hibernate</groupId>
+                    <artifactId>hibernate-entitymanager</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <!--
         Provided dependencies.

Modified: validator/trunk/pom.xml
===================================================================
--- validator/trunk/pom.xml	2010-05-24 10:31:09 UTC (rev 19596)
+++ validator/trunk/pom.xml	2010-05-24 19:18:21 UTC (rev 19597)
@@ -69,13 +69,11 @@
                 <groupId>javax.xml.bind</groupId>
                 <artifactId>jaxb-api</artifactId>
                 <version>2.2</version>
-                <scope>provided</scope>
             </dependency>
             <dependency>
                 <groupId>com.sun.xml.bind</groupId>
                 <artifactId>jaxb-impl</artifactId>
                 <version>2.1.12</version>
-                <scope>provided</scope>
             </dependency>
             <dependency>
                 <groupId>org.slf4j</groupId>
@@ -86,7 +84,6 @@
                 <groupId>org.slf4j</groupId>
                 <artifactId>slf4j-log4j12</artifactId>
                 <version>1.5.6</version>
-                <scope>runtime</scope>
             </dependency>
             <dependency>
                 <groupId>com.googlecode.jtype</groupId>
@@ -94,18 +91,27 @@
                 <version>0.1.1</version>
             </dependency>
             <dependency>
-                <groupId>org.hibernate.java-persistence</groupId>
-                <artifactId>jpa-api</artifactId>
-                <version>2.0-cr-1</version>
+                <groupId>org.hibernate.javax.persistence</groupId>
+                <artifactId>hibernate-jpa-2.0-api</artifactId>
+                <version>1.0.0.Final</version>
             </dependency>
             <dependency>
+                <groupId>org.hibernate</groupId>
+                <artifactId>hibernate-entitymanager</artifactId>
+                <version>3.5.0-Final</version>
+            </dependency>
+            <dependency>
                 <groupId>org.testng</groupId>
                 <artifactId>testng</artifactId>
                 <version>5.8</version>
                 <classifier>jdk15</classifier>
-                <scope>test</scope>
             </dependency>
             <dependency>
+                <groupId>com.h2database</groupId>
+                <artifactId>h2</artifactId>
+                <version>1.2.124</version>
+            </dependency>
+            <dependency>
                 <groupId>org.hibernate.jsr303.tck</groupId>
                 <artifactId>jsr303-tck</artifactId>
                 <version>1.0.3.GA</version>



More information about the hibernate-commits mailing list