Hibernate SVN: r16773 - core/branches/INFINISPAN/testsuite.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2009-06-12 10:34:58 -0400 (Fri, 12 Jun 2009)
New Revision: 16773
Modified:
core/branches/INFINISPAN/testsuite/pom.xml
Log:
Initial import
Modified: core/branches/INFINISPAN/testsuite/pom.xml
===================================================================
--- core/branches/INFINISPAN/testsuite/pom.xml 2009-06-12 14:34:14 UTC (rev 16772)
+++ core/branches/INFINISPAN/testsuite/pom.xml 2009-06-12 14:34:58 UTC (rev 16773)
@@ -110,6 +110,11 @@
<artifactId>hsqldb</artifactId>
<version>1.8.0.2</version>
</dependency>
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>hibernate-infinispan</artifactId>
+ <version>${version}</version>
+ </dependency>
</dependencies>
<properties>
<db.dialect>org.hibernate.dialect.HSQLDialect</db.dialect>
15 years, 6 months
Hibernate SVN: r16772 - core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2009-06-12 10:34:14 -0400 (Fri, 12 Jun 2009)
New Revision: 16772
Added:
core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/AbstractCacheTestCase.java
core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/BaseRegionFactoryTestCase.java
Modified:
core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/BaseCacheProviderTestCase.java
Log:
Refactored to allow for RegionFactory configuration
Added: core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/AbstractCacheTestCase.java
===================================================================
--- core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/AbstractCacheTestCase.java (rev 0)
+++ core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/AbstractCacheTestCase.java 2009-06-12 14:34:14 UTC (rev 16772)
@@ -0,0 +1,198 @@
+package org.hibernate.test.cache;
+
+import java.util.Map;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cache.ReadWriteCache;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.stat.SecondLevelCacheStatistics;
+import org.hibernate.stat.Statistics;
+import org.hibernate.test.tm.ConnectionProviderImpl;
+import org.hibernate.test.tm.TransactionManagerLookupImpl;
+import org.hibernate.transaction.JDBCTransactionFactory;
+
+public abstract class AbstractCacheTestCase extends FunctionalTestCase {
+
+ public AbstractCacheTestCase( String string ) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "cache/Item.hbm.xml" };
+ }
+
+ public void configure( Configuration cfg ) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.CACHE_REGION_PREFIX, "" );
+ cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ cfg.setProperty( Environment.USE_STRUCTURED_CACHE, "true" );
+
+ if ( getConfigResourceKey() != null ) {
+ cfg.setProperty( getConfigResourceKey(), getConfigResourceLocation() );
+ }
+
+ if ( useTransactionManager() ) {
+ cfg.setProperty( Environment.CONNECTION_PROVIDER, ConnectionProviderImpl.class.getName() );
+ cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName() );
+ }
+ else {
+ cfg.setProperty( Environment.TRANSACTION_STRATEGY, JDBCTransactionFactory.class.getName() );
+ }
+ }
+
+ /**
+ * For provider-specific configuration, the name of the property key the
+ * provider expects.
+ *
+ * @return The provider-specific config key.
+ */
+ protected abstract String getConfigResourceKey();
+
+ /**
+ * For provider-specific configuration, the resource location of that
+ * config resource.
+ *
+ * @return The config resource location.
+ */
+ protected abstract String getConfigResourceLocation();
+
+ /**
+ * Should we use a transaction manager for transaction management.
+ *
+ * @return True if we should use a RM; false otherwise.
+ */
+ protected abstract boolean useTransactionManager();
+
+ public void testQueryCacheInvalidation() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Item i = new Item();
+ i.setName("widget");
+ i.setDescription("A really top-quality, full-featured widget.");
+ s.persist(i);
+ t.commit();
+ s.close();
+
+ SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics()
+ .getSecondLevelCacheStatistics( Item.class.getName() );
+
+ assertEquals( slcs.getPutCount(), 1 );
+ assertEquals( slcs.getElementCountInMemory(), 1 );
+ assertEquals( slcs.getEntries().size(), 1 );
+
+ s = openSession();
+ t = s.beginTransaction();
+ i = (Item) s.get( Item.class, i.getId() );
+
+ assertEquals( slcs.getHitCount(), 1 );
+ assertEquals( slcs.getMissCount(), 0 );
+
+ i.setDescription("A bog standard item");
+
+ t.commit();
+ s.close();
+
+ assertEquals( slcs.getPutCount(), 2 );
+
+ Object entry = slcs.getEntries().get( i.getId() );
+ Map map;
+ if ( entry instanceof ReadWriteCache.Item ) {
+ map = (Map) ( (ReadWriteCache.Item) entry ).getValue();
+ }
+ else {
+ map = (Map) entry;
+ }
+ assertTrue( map.get("description").equals("A bog standard item") );
+ assertTrue( map.get("name").equals("widget") );
+
+ // cleanup
+ s = openSession();
+ t = s.beginTransaction();
+ s.delete( i );
+ t.commit();
+ s.close();
+ }
+
+ public void testEmptySecondLevelCacheEntry() throws Exception {
+ getSessions().evictEntity( Item.class.getName() );
+ Statistics stats = getSessions().getStatistics();
+ stats.clear();
+ SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics( Item.class.getName() );
+ Map cacheEntries = statistics.getEntries();
+ assertEquals( 0, cacheEntries.size() );
+ }
+
+ public void testStaleWritesLeaveCacheConsistent() {
+ Session s = openSession();
+ Transaction txn = s.beginTransaction();
+ VersionedItem item = new VersionedItem();
+ item.setName( "steve" );
+ item.setDescription( "steve's item" );
+ s.save( item );
+ txn.commit();
+ s.close();
+
+ Long initialVersion = item.getVersion();
+
+ // manually revert the version property
+ item.setVersion( new Long( item.getVersion().longValue() - 1 ) );
+
+ try {
+ s = openSession();
+ txn = s.beginTransaction();
+ s.update( item );
+ txn.commit();
+ s.close();
+ fail( "expected stale write to fail" );
+ }
+ catch( Throwable expected ) {
+ // expected behavior here
+ if ( txn != null ) {
+ try {
+ txn.rollback();
+ }
+ catch( Throwable ignore ) {
+ }
+ }
+ }
+ finally {
+ if ( s != null && s.isOpen() ) {
+ try {
+ s.close();
+ }
+ catch( Throwable ignore ) {
+ }
+ }
+ }
+
+ // check the version value in the cache...
+ SecondLevelCacheStatistics slcs = sfi().getStatistics()
+ .getSecondLevelCacheStatistics( VersionedItem.class.getName() );
+
+ Object entry = slcs.getEntries().get( item.getId() );
+ Long cachedVersionValue;
+ if ( entry instanceof ReadWriteCache.Lock ) {
+ //FIXME don't know what to test here
+ cachedVersionValue = new Long( ( (ReadWriteCache.Lock) entry).getUnlockTimestamp() );
+ }
+ else {
+ cachedVersionValue = ( Long ) ( (Map) entry ).get( "_version" );
+ assertEquals( initialVersion.longValue(), cachedVersionValue.longValue() );
+ }
+
+
+ // cleanup
+ s = openSession();
+ txn = s.beginTransaction();
+ item = ( VersionedItem ) s.load( VersionedItem.class, item.getId() );
+ s.delete( item );
+ txn.commit();
+ s.close();
+
+ }
+
+}
\ No newline at end of file
Modified: core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/BaseCacheProviderTestCase.java
===================================================================
--- core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/BaseCacheProviderTestCase.java 2009-06-12 14:33:00 UTC (rev 16771)
+++ core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/BaseCacheProviderTestCase.java 2009-06-12 14:34:14 UTC (rev 16772)
@@ -23,26 +23,15 @@
*/
package org.hibernate.test.cache;
-import java.util.Map;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.cache.ReadWriteCache;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.stat.SecondLevelCacheStatistics;
-import org.hibernate.stat.Statistics;
-import org.hibernate.test.tm.ConnectionProviderImpl;
-import org.hibernate.test.tm.TransactionManagerLookupImpl;
-import org.hibernate.transaction.JDBCTransactionFactory;
/**
* Common requirement testing for each {@link org.hibernate.cache.CacheProvider} impl.
*
* @author Steve Ebersole
*/
-public abstract class BaseCacheProviderTestCase extends FunctionalTestCase {
+public abstract class BaseCacheProviderTestCase extends AbstractCacheTestCase {
// note that a lot of the fucntionality here is intended to be used
// in creating specific tests for each CacheProvider that would extend
@@ -52,29 +41,9 @@
super( x );
}
- public String[] getMappings() {
- return new String[] { "cache/Item.hbm.xml" };
- }
-
- public void configure(Configuration cfg) {
+ public void configure( Configuration cfg ) {
super.configure( cfg );
- cfg.setProperty( Environment.CACHE_REGION_PREFIX, "" );
- cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
- cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
- cfg.setProperty( Environment.USE_STRUCTURED_CACHE, "true" );
cfg.setProperty( Environment.CACHE_PROVIDER, getCacheProvider().getName() );
-
- if ( getConfigResourceKey() != null ) {
- cfg.setProperty( getConfigResourceKey(), getConfigResourceLocation() );
- }
-
- if ( useTransactionManager() ) {
- cfg.setProperty( Environment.CONNECTION_PROVIDER, ConnectionProviderImpl.class.getName() );
- cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName() );
- }
- else {
- cfg.setProperty( Environment.TRANSACTION_STRATEGY, JDBCTransactionFactory.class.getName() );
- }
}
/**
@@ -83,156 +52,4 @@
* @return The cache provider.
*/
protected abstract Class getCacheProvider();
-
- /**
- * For provider-specific configuration, the name of the property key the
- * provider expects.
- *
- * @return The provider-specific config key.
- */
- protected abstract String getConfigResourceKey();
-
- /**
- * For provider-specific configuration, the resource location of that
- * config resource.
- *
- * @return The config resource location.
- */
- protected abstract String getConfigResourceLocation();
-
- /**
- * Should we use a transaction manager for transaction management.
- *
- * @return True if we should use a RM; false otherwise.
- */
- protected abstract boolean useTransactionManager();
-
-
- public void testQueryCacheInvalidation() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Item i = new Item();
- i.setName("widget");
- i.setDescription("A really top-quality, full-featured widget.");
- s.persist(i);
- t.commit();
- s.close();
-
- SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics()
- .getSecondLevelCacheStatistics( Item.class.getName() );
-
- assertEquals( slcs.getPutCount(), 1 );
- assertEquals( slcs.getElementCountInMemory(), 1 );
- assertEquals( slcs.getEntries().size(), 1 );
-
- s = openSession();
- t = s.beginTransaction();
- i = (Item) s.get( Item.class, i.getId() );
-
- assertEquals( slcs.getHitCount(), 1 );
- assertEquals( slcs.getMissCount(), 0 );
-
- i.setDescription("A bog standard item");
-
- t.commit();
- s.close();
-
- assertEquals( slcs.getPutCount(), 2 );
-
- Object entry = slcs.getEntries().get( i.getId() );
- Map map;
- if ( entry instanceof ReadWriteCache.Item ) {
- map = (Map) ( (ReadWriteCache.Item) entry ).getValue();
- }
- else {
- map = (Map) entry;
- }
- assertTrue( map.get("description").equals("A bog standard item") );
- assertTrue( map.get("name").equals("widget") );
-
- // cleanup
- s = openSession();
- t = s.beginTransaction();
- s.delete( i );
- t.commit();
- s.close();
- }
-
- public void testEmptySecondLevelCacheEntry() throws Exception {
- getSessions().evictEntity( Item.class.getName() );
- Statistics stats = getSessions().getStatistics();
- stats.clear();
- SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics( Item.class.getName() );
- Map cacheEntries = statistics.getEntries();
- assertEquals( 0, cacheEntries.size() );
- }
-
- public void testStaleWritesLeaveCacheConsistent() {
- Session s = openSession();
- Transaction txn = s.beginTransaction();
- VersionedItem item = new VersionedItem();
- item.setName( "steve" );
- item.setDescription( "steve's item" );
- s.save( item );
- txn.commit();
- s.close();
-
- Long initialVersion = item.getVersion();
-
- // manually revert the version property
- item.setVersion( new Long( item.getVersion().longValue() - 1 ) );
-
- try {
- s = openSession();
- txn = s.beginTransaction();
- s.update( item );
- txn.commit();
- s.close();
- fail( "expected stale write to fail" );
- }
- catch( Throwable expected ) {
- // expected behavior here
- if ( txn != null ) {
- try {
- txn.rollback();
- }
- catch( Throwable ignore ) {
- }
- }
- }
- finally {
- if ( s != null && s.isOpen() ) {
- try {
- s.close();
- }
- catch( Throwable ignore ) {
- }
- }
- }
-
- // check the version value in the cache...
- SecondLevelCacheStatistics slcs = sfi().getStatistics()
- .getSecondLevelCacheStatistics( VersionedItem.class.getName() );
-
- Object entry = slcs.getEntries().get( item.getId() );
- Long cachedVersionValue;
- if ( entry instanceof ReadWriteCache.Lock ) {
- //FIXME don't know what to test here
- cachedVersionValue = new Long( ( (ReadWriteCache.Lock) entry).getUnlockTimestamp() );
- }
- else {
- cachedVersionValue = ( Long ) ( (Map) entry ).get( "_version" );
- assertEquals( initialVersion.longValue(), cachedVersionValue.longValue() );
- }
-
-
- // cleanup
- s = openSession();
- txn = s.beginTransaction();
- item = ( VersionedItem ) s.load( VersionedItem.class, item.getId() );
- s.delete( item );
- txn.commit();
- s.close();
-
- }
-}
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/BaseRegionFactoryTestCase.java
===================================================================
--- core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/BaseRegionFactoryTestCase.java (rev 0)
+++ core/branches/INFINISPAN/testing/src/main/java/org/hibernate/test/cache/BaseRegionFactoryTestCase.java 2009-06-12 14:34:14 UTC (rev 16772)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+
+/**
+ * Common requirement testing for each {@link org.hibernate.cache.RegionFactory} impl.
+ *
+ * @author Chris Bredesen
+ */
+public abstract class BaseRegionFactoryTestCase extends AbstractCacheTestCase {
+
+ // note that a lot of the fucntionality here is intended to be used
+ // in creating specific tests for each CacheProvider that would extend
+ // from a base test case (this) for common requirement testing...
+
+ public BaseRegionFactoryTestCase(String x) {
+ super( x );
+ }
+
+
+ public void configure( Configuration cfg ) {
+ super.configure( cfg );
+ String s = getRegionFactory().getClass().getName();
+ cfg.setProperty( Environment.CACHE_REGION_FACTORY, getRegionFactory().getName() );
+ }
+
+ /**
+ * The region factory to be tested.
+ *
+ * @return The region factory class..
+ */
+ protected abstract Class getRegionFactory();
+}
\ No newline at end of file
15 years, 6 months
Hibernate SVN: r16771 - in core/branches/INFINISPAN/cache-infinispan: src and 17 other directories.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2009-06-12 10:33:00 -0400 (Fri, 12 Jun 2009)
New Revision: 16771
Added:
core/branches/INFINISPAN/cache-infinispan/pom.xml
core/branches/INFINISPAN/cache-infinispan/src/
core/branches/INFINISPAN/cache-infinispan/src/main/
core/branches/INFINISPAN/cache-infinispan/src/main/java/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseGeneralDataRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseTransactionalDataRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/resources/
core/branches/INFINISPAN/cache-infinispan/src/test/
core/branches/INFINISPAN/cache-infinispan/src/test/java/
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/cache/
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/cache/infinispan/
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/cache/infinispan/InfinispanTest.java
core/branches/INFINISPAN/cache-infinispan/src/test/resources/
core/branches/INFINISPAN/cache-infinispan/src/test/resources/hibernate.properties
core/branches/INFINISPAN/cache-infinispan/src/test/resources/log4j.properties
Modified:
core/branches/INFINISPAN/cache-infinispan/
Log:
Initial import
Property changes on: core/branches/INFINISPAN/cache-infinispan
___________________________________________________________________
Name: svn:ignore
+ target
.classpath
Added: core/branches/INFINISPAN/cache-infinispan/pom.xml
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/pom.xml (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/pom.xml 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,149 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-parent</artifactId>
+ <version>3.3.2-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-infinispan</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Hibernate Infinispan Integration</name>
+ <description>Integration of Hibernate with Infinispan</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ <version>4.0.0.ALPHA3</version>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <version>${version}</version>
+ <!-- <scope>test</scope> TODO fix this -->
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.2</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- this is optional on core :( and needed for testing -->
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.4.GA</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <!-- Skip a long-running test of a prototype class -->
+ <exclude>**/ClusteredConcurrentTimestampRegionTestCase.java</exclude>
+ </excludes>
+ <systemProperties>
+ <property>
+ <name>hibernate.test.validatefailureexpected</name>
+ <value>true</value>
+ </property>
+ <property>
+ <name>jgroups.bind_addr</name>
+ <value>${jgroups.bind_addr}</value>
+ </property>
+ <!-- There are problems with multicast and IPv6 on some
+ OS/JDK combos, so we tell Java to use IPv4. If you
+ have problems with multicast when running the tests
+ you can try setting this to 'false', although typically
+ that won't be helpful.
+ -->
+ <property>
+ <name>java.net.preferIPv4Stack</name>
+ <value>true</value>
+ </property>
+ <!-- Tell JGroups to only wait a short time for PING
+ responses before determining coordinator. Speeds cluster
+ formation during integration tests. (This is too
+ low a value for a real system; only use for tests.)
+ -->
+ <property>
+ <name>jgroups.ping.timeout</name>
+ <value>500</value>
+ </property>
+ <!-- Tell JGroups to only require one PING response
+ before determining coordinator. Speeds cluster
+ formation during integration tests. (This is too
+ low a value for a real system; only use for tests.)
+ -->
+ <property>
+ <name>jgroups.ping.num_initial_members</name>
+ <value>1</value>
+ </property>
+ <!-- Disable the JGroups message bundling feature
+ to speed tests and avoid FLUSH issue -->
+ <property>
+ <name>jgroups.udp.enable_bundling</name>
+ <value>false</value>
+ </property>
+ </systemProperties>
+ <skipExec>${skipUnitTests}</skipExec>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <skipUnitTests>true</skipUnitTests>
+ <!--
+ Following is the default jgroups mcast address. If you find the testsuite runs very slowly, there
+ may be problems with multicast on the interface JGroups uses by default on your machine. You can
+ try to resolve setting 'jgroups.bind_addr' as a system-property to the jvm launching maven and
+ setting the value to an interface where you know multicast works
+ -->
+ <jgroups.bind_addr>127.0.0.1</jgroups.bind_addr>
+ </properties>
+
+ <profiles>
+ <profile>
+ <id>test</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <properties>
+ <skipUnitTests>false</skipUnitTests>
+ </properties>
+ </profile>
+ </profiles>
+</project>
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseGeneralDataRegion.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseGeneralDataRegion.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseGeneralDataRegion.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,34 @@
+package org.hibernate.cache.infinispan;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.GeneralDataRegion;
+import org.infinispan.Cache;
+
+/**
+ * Support for Infinispan {@link GeneralDataRegion} implementors.
+ *
+ * @author Chris Bredesen
+ */
+public abstract class BaseGeneralDataRegion extends BaseRegion implements GeneralDataRegion {
+
+ public BaseGeneralDataRegion( Cache<Object, Object> cache, String name ) {
+ super( cache, name );
+ }
+
+ public void evict( Object key ) throws CacheException {
+ getCache().evict( key );
+ }
+
+ public void evictAll() throws CacheException {
+ getCache().clear();
+ }
+
+ public Object get( Object key ) throws CacheException {
+ return getCache().get( key );
+ }
+
+ public void put( Object key, Object value ) throws CacheException {
+ getCache().put( key, value );
+ }
+
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseRegion.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseRegion.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseRegion.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,74 @@
+package org.hibernate.cache.infinispan;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.Region;
+import org.infinispan.Cache;
+
+/**
+ * Support for Infinispan {@link Region}s. Handles the management of a Cache
+ * instance as well as basic peripheral operations.
+ *
+ * @author Chris Bredesen
+ */
+abstract class BaseRegion implements Region {
+ private final Cache<Object, Object> cache;
+ private final String name;
+
+ public BaseRegion( Cache<Object, Object> cache, String name ) {
+ this.cache = cache;
+ this.name = name;
+ }
+
+ public Cache<Object, Object> getCache() {
+ return cache;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public long getElementCountInMemory() {
+ return cache.size();
+ }
+
+ /**
+ * Not supported.
+ *
+ * @return -1
+ */
+ public long getElementCountOnDisk() {
+ return -1;
+ }
+
+ /**
+ * Not supported.
+ *
+ * @return -1
+ */
+ public long getSizeInMemory() {
+ return -1;
+ }
+
+ public int getTimeout() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long nextTimestamp() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map toMap() {
+ return Collections.EMPTY_MAP;
+ }
+
+ public void destroy() throws CacheException {
+ // TODO see if we need to do this even in spite of RF.shutdown()
+ }
+
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseTransactionalDataRegion.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseTransactionalDataRegion.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseTransactionalDataRegion.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,28 @@
+package org.hibernate.cache.infinispan;
+
+import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.TransactionalDataRegion;
+import org.infinispan.Cache;
+
+/**
+ * Support for Inifinispan {@link TransactionalDataRegion} implementors.
+ *
+ * @author Chris Bredesen
+ */
+public abstract class BaseTransactionalDataRegion extends BaseRegion implements TransactionalDataRegion {
+ private final CacheDataDescription metadata;
+
+ public BaseTransactionalDataRegion( Cache<Object, Object> cache, String name, CacheDataDescription metadata ) {
+ super( cache, name );
+ this.metadata = metadata;
+ }
+
+ public CacheDataDescription getCacheDataDescription() {
+ return metadata;
+ }
+
+ public boolean isTransactionAware() {
+ return true;
+ }
+
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,116 @@
+package org.hibernate.cache.infinispan;
+
+import java.util.Properties;
+
+import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.CollectionRegion;
+import org.hibernate.cache.EntityRegion;
+import org.hibernate.cache.QueryResultsRegion;
+import org.hibernate.cache.RegionFactory;
+import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.infinispan.collection.InfinispanCollectionRegion;
+import org.hibernate.cache.infinispan.entity.InfinispanEntityRegion;
+import org.hibernate.cache.infinispan.query.InfinispanQueryResultsRegion;
+import org.hibernate.cache.infinispan.timestamp.InfinispanTimestampsRegion;
+import org.hibernate.cfg.Settings;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.manager.DefaultCacheManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link RegionFactory} for <a
+ * href="http://www.jboss.org/infinispan">Infinispan</a>-backed cache regions.
+ *
+ * @author Chris Bredesen
+ */
+public class InfinispanRegionFactory implements RegionFactory {
+ private static final Logger log = LoggerFactory.getLogger(InfinispanRegionFactory.class);
+
+ final CacheManager cacheManager = new DefaultCacheManager( false );
+
+ /**
+ * Create a new instance using the default configuration.
+ */
+ public InfinispanRegionFactory() {
+ }
+
+ /**
+ * Create a new instance using conifguration properties in
+ * <code>props</code>.
+ *
+ * @param props Environmental properties; currently unused.
+ */
+ public InfinispanRegionFactory( Properties props ) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CollectionRegion buildCollectionRegion( String regionName, Properties properties,
+ CacheDataDescription metadata ) throws CacheException {
+ log.debug( "Building collection cache region [" + regionName + "]" );
+ return new InfinispanCollectionRegion( cacheManager.getCache( regionName ), regionName,
+ metadata );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EntityRegion buildEntityRegion( String regionName, Properties properties,
+ CacheDataDescription metadata ) throws CacheException {
+ log.debug( "Building entity cache region [" + regionName + "]" );
+ return new InfinispanEntityRegion( cacheManager.getCache( regionName ), regionName,
+ metadata );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public QueryResultsRegion buildQueryResultsRegion( String regionName, Properties properties )
+ throws CacheException {
+ log.debug( "Building query results cache region [" + regionName + "]" );
+ return new InfinispanQueryResultsRegion( cacheManager.getCache(regionName), regionName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public TimestampsRegion buildTimestampsRegion( String regionName, Properties properties )
+ throws CacheException {
+ log.debug( "Building timestamps cache region [" + regionName + "]" );
+ return new InfinispanTimestampsRegion( cacheManager.getCache( regionName ), regionName );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMinimalPutsEnabledByDefault() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long nextTimestamp() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start( Settings settings, Properties properties ) throws CacheException {
+ log.debug( "Starting Infinispan CacheManager" );
+ this.cacheManager.start();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stop() {
+ log.debug( "Stopping Infinispan CacheManager" );
+ this.cacheManager.stop();
+ }
+
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,28 @@
+package org.hibernate.cache.infinispan.collection;
+
+import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.CollectionRegion;
+import org.hibernate.cache.access.AccessType;
+import org.hibernate.cache.access.CollectionRegionAccessStrategy;
+import org.hibernate.cache.infinispan.BaseTransactionalDataRegion;
+import org.infinispan.Cache;
+
+public class InfinispanCollectionRegion extends BaseTransactionalDataRegion implements CollectionRegion {
+
+ public InfinispanCollectionRegion( Cache<Object, Object> cache, String name, CacheDataDescription metadata ) {
+ super( cache, name, metadata );
+ }
+
+ public CollectionRegionAccessStrategy buildAccessStrategy( AccessType accessType )
+ throws CacheException {
+ if (AccessType.READ_ONLY.equals( accessType )) {
+ return new ReadOnlyAccess(this);
+ } else if (AccessType.TRANSACTIONAL.equals( accessType )) {
+ return new TransactionalAccess(this);
+ }
+
+ throw new CacheException("unsupported access type [" + accessType.getName() + "]");
+ }
+
+}
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,79 @@
+package org.hibernate.cache.infinispan.collection;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.CollectionRegion;
+import org.hibernate.cache.Region;
+import org.hibernate.cache.access.CollectionRegionAccessStrategy;
+import org.hibernate.cache.access.SoftLock;
+
+public class ReadOnlyAccess implements CollectionRegionAccessStrategy {
+ private final Region region;
+
+ public ReadOnlyAccess( Region region ) {
+ this.region = region;
+ }
+
+ public void evict( Object key ) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void evictAll() throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Object get( Object key, long txTimestamp ) throws CacheException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public CollectionRegion getRegion() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public SoftLock lockItem( Object key, Object version ) throws CacheException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public SoftLock lockRegion() throws CacheException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version )
+ throws CacheException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version,
+ boolean minimalPutOverride ) throws CacheException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void remove( Object key ) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeAll() throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unlockItem( Object key, SoftLock lock ) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unlockRegion( SoftLock lock ) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+
+}
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,78 @@
+package org.hibernate.cache.infinispan.collection;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.CollectionRegion;
+import org.hibernate.cache.Region;
+import org.hibernate.cache.access.CollectionRegionAccessStrategy;
+import org.hibernate.cache.access.SoftLock;
+
+public class TransactionalAccess implements CollectionRegionAccessStrategy {
+ private final Region region;
+
+ public TransactionalAccess( Region region ) {
+ this.region = region;
+ }
+
+ public void evict( Object key ) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void evictAll() throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Object get( Object key, long txTimestamp ) throws CacheException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public CollectionRegion getRegion() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public SoftLock lockItem( Object key, Object version ) throws CacheException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public SoftLock lockRegion() throws CacheException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version )
+ throws CacheException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version,
+ boolean minimalPutOverride ) throws CacheException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void remove( Object key ) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeAll() throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unlockItem( Object key, SoftLock lock ) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unlockRegion( SoftLock lock ) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,29 @@
+package org.hibernate.cache.infinispan.entity;
+
+import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.EntityRegion;
+import org.hibernate.cache.access.AccessType;
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+import org.hibernate.cache.infinispan.BaseTransactionalDataRegion;
+import org.infinispan.Cache;
+
+public class InfinispanEntityRegion extends BaseTransactionalDataRegion implements EntityRegion {
+
+ public InfinispanEntityRegion( Cache<Object, Object> cache, String name, CacheDataDescription metadata ) {
+ super( cache, name, metadata );
+ }
+
+ public EntityRegionAccessStrategy buildAccessStrategy( AccessType accessType )
+ throws CacheException {
+ if (AccessType.READ_ONLY.equals( accessType )) {
+ return new ReadOnlyAccess(this);
+ } else if (AccessType.TRANSACTIONAL.equals( accessType )) {
+ return new TransactionalAccess(this);
+ }
+
+ throw new CacheException("unsupported access type [" + accessType.getName() + "]");
+
+ }
+
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,48 @@
+package org.hibernate.cache.infinispan.entity;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.access.SoftLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A specialization of {@link TransactionalAccess} that ensures we never update
+ * data. Infinispan access is always transactional.
+ *
+ * @author Chris Bredesen
+ */
+class ReadOnlyAccess extends TransactionalAccess {
+ private static final Logger log = LoggerFactory.getLogger( ReadOnlyAccess.class );
+
+ ReadOnlyAccess( InfinispanEntityRegion region ) {
+ super( region );
+ }
+
+ public SoftLock lockItem( Object key, Object version ) throws CacheException {
+ throw new UnsupportedOperationException( "Illegal attempt to edit read only item" );
+ }
+
+ public SoftLock lockRegion() throws CacheException {
+ throw new UnsupportedOperationException( "Illegal attempt to edit read only item" );
+ }
+
+ public void unlockItem( Object key, SoftLock lock ) throws CacheException {
+ log.error( "Illegal attempt to edit read only item" );
+ }
+
+ public void unlockRegion( SoftLock lock ) throws CacheException {
+ log.error( "Illegal attempt to edit read only item" );
+ }
+
+ @Override
+ public boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
+ throws CacheException {
+ throw new UnsupportedOperationException("Illegal attempt to edit read only item");
+ }
+
+ @Override
+ public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
+ throws CacheException {
+ throw new UnsupportedOperationException("Illegal attempt to edit read only item");
+ }
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,94 @@
+package org.hibernate.cache.infinispan.entity;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.EntityRegion;
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+import org.hibernate.cache.access.SoftLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Transactional entity region access for Infinispan.
+ *
+ * @author Chris Bredesen
+ */
+class TransactionalAccess implements EntityRegionAccessStrategy {
+ private static final Logger log = LoggerFactory.getLogger( TransactionalAccess.class );
+ private final InfinispanEntityRegion region;
+
+ TransactionalAccess( InfinispanEntityRegion region ) {
+ this.region = region;
+ }
+
+ public void evict( Object key ) throws CacheException {
+ region.getCache().evict( key );
+ }
+
+ public void evictAll() throws CacheException {
+ region.getCache().clear();
+ }
+
+ public Object get( Object key, long txTimestamp ) throws CacheException {
+ return region.getCache().get( key );
+ }
+
+ public EntityRegion getRegion() {
+ return this.region;
+ }
+
+ public boolean insert( Object key, Object value, Object version ) throws CacheException {
+ region.getCache().put( key, value );
+ return true; // TODO this is suspect
+ }
+
+ public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version )
+ throws CacheException {
+ region.getCache().putForExternalRead( key, value );
+ return true;
+ }
+
+ public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version,
+ boolean minimalPutOverride ) throws CacheException {
+ region.getCache().putForExternalRead( key, value );
+ return true;
+ }
+
+ public void remove( Object key ) throws CacheException {
+ region.getCache().remove( key );
+ }
+
+ public void removeAll() throws CacheException {
+ region.getCache().clear(); // TODO is this right?
+ }
+
+ public boolean update( Object key, Object value, Object currentVersion, Object previousVersion )
+ throws CacheException {
+ region.getCache().put( key, value );
+ return true; // JBC2 provider does this...
+ }
+
+ // all remaining methods copied from the o.h.c.jbc2.entity.TransactionalAccess
+
+ public SoftLock lockItem(Object key, Object version) throws CacheException {
+ return null;
+ }
+
+ public SoftLock lockRegion() throws CacheException {
+ return null;
+ }
+
+ public void unlockItem(Object key, SoftLock lock) throws CacheException {
+ }
+
+ public void unlockRegion(SoftLock lock) throws CacheException {
+ }
+
+ public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
+ return false;
+ }
+
+ public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
+ throws CacheException {
+ return false;
+ }
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,13 @@
+package org.hibernate.cache.infinispan.query;
+
+import org.hibernate.cache.QueryResultsRegion;
+import org.hibernate.cache.infinispan.BaseGeneralDataRegion;
+import org.infinispan.Cache;
+
+public class InfinispanQueryResultsRegion extends BaseGeneralDataRegion implements QueryResultsRegion {
+
+ public InfinispanQueryResultsRegion( Cache<Object, Object> cache, String name ) {
+ super( cache, name );
+ }
+
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,13 @@
+package org.hibernate.cache.infinispan.timestamp;
+
+import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.infinispan.BaseGeneralDataRegion;
+import org.infinispan.Cache;
+
+public class InfinispanTimestampsRegion extends BaseGeneralDataRegion implements TimestampsRegion {
+
+ public InfinispanTimestampsRegion( Cache<Object, Object> cache, String name ) {
+ super( cache, name );
+ }
+
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/cache/infinispan/InfinispanTest.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/cache/infinispan/InfinispanTest.java (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/cache/infinispan/InfinispanTest.java 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,37 @@
+package org.hibernate.cache.infinispan;
+
+import org.hibernate.test.cache.BaseRegionFactoryTestCase;
+
+public class InfinispanTest extends BaseRegionFactoryTestCase {
+
+ public InfinispanTest( String x ) {
+ super( x );
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Class getRegionFactory() {
+ return InfinispanRegionFactory.class;
+ }
+
+ @Override
+ protected String getConfigResourceKey() {
+ return null;
+ }
+
+ @Override
+ protected String getConfigResourceLocation() {
+ return null;
+ }
+
+ @Override
+ protected boolean useTransactionManager() {
+ return true;
+ }
+
+ @Override
+ public String getCacheConcurrencyStrategy() {
+ return "read-only";
+ }
+
+}
\ No newline at end of file
Added: core/branches/INFINISPAN/cache-infinispan/src/test/resources/hibernate.properties
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/test/resources/hibernate.properties (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/test/resources/hibernate.properties 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,34 @@
+################################################################################
+# Hibernate, Relational Persistence for Idiomatic Java #
+# #
+# Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as #
+# indicated by the @author tags or express copyright attribution #
+# statements applied by the authors. All third-party contributions are #
+# distributed under license by Red Hat Middleware LLC. #
+# #
+# This copyrighted material is made available to anyone wishing to use, modify,#
+# copy, or redistribute it subject to the terms and conditions of the GNU #
+# Lesser General Public License, as published by the Free Software Foundation. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+# for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public License #
+# along with this distribution; if not, write to: #
+# Free Software Foundation, Inc. #
+# 51 Franklin Street, Fifth Floor #
+# Boston, MA 02110-1301 USA #
+################################################################################
+hibernate.dialect org.hibernate.dialect.HSQLDialect
+hibernate.connection.driver_class org.hsqldb.jdbcDriver
+hibernate.connection.url jdbc:hsqldb:mem:/test
+hibernate.connection.username sa
+hibernate.connection.password
+
+hibernate.connection.pool_size 5
+
+hibernate.format_sql true
+
+hibernate.max_fetch_depth 5
Property changes on: core/branches/INFINISPAN/cache-infinispan/src/test/resources/hibernate.properties
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/INFINISPAN/cache-infinispan/src/test/resources/log4j.properties
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/test/resources/log4j.properties (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/test/resources/log4j.properties 2009-06-12 14:33:00 UTC (rev 16771)
@@ -0,0 +1,39 @@
+################################################################################
+# Hibernate, Relational Persistence for Idiomatic Java #
+# #
+# Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as #
+# indicated by the @author tags or express copyright attribution #
+# statements applied by the authors. All third-party contributions are #
+# distributed under license by Red Hat Middleware LLC. #
+# #
+# This copyrighted material is made available to anyone wishing to use, modify,#
+# copy, or redistribute it subject to the terms and conditions of the GNU #
+# Lesser General Public License, as published by the Free Software Foundation. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+# for more details. #
+# #
+# You should have received a copy of the GNU Lesser General Public License #
+# along with this distribution; if not, write to: #
+# Free Software Foundation, Inc. #
+# 51 Franklin Street, Fifth Floor #
+# Boston, MA 02110-1301 USA #
+################################################################################
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p [%t] %c{1}:%L - %m%n
+
+
+log4j.rootLogger=info, stdout
+
+log4j.logger.org.hibernate.test=info
+log4j.logger.org.hibernate.cache=debug
+#log4j.logger.org.jgroups=info
+#log4j.logger.org.jboss.cache=trace
+#log4j.logger.org.jboss.cache.RegionManager=info
+#log4j.logger.org.jboss.cache.lock=info
+#log4j.logger.org.jboss.cache.interceptors.PessimisticLockInterceptor=info
+#log4j.logger.org.jboss.cache.interceptors.UnlockInterceptor=info
Property changes on: core/branches/INFINISPAN/cache-infinispan/src/test/resources/log4j.properties
___________________________________________________________________
Name: svn:executable
+ *
15 years, 6 months
Hibernate SVN: r16770 - core/branches/INFINISPAN.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2009-06-12 10:31:58 -0400 (Fri, 12 Jun 2009)
New Revision: 16770
Added:
core/branches/INFINISPAN/cache-infinispan/
Log:
Initial import.
15 years, 6 months
Hibernate SVN: r16769 - core/branches.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2009-06-12 10:22:26 -0400 (Fri, 12 Jun 2009)
New Revision: 16769
Added:
core/branches/INFINISPAN/
Log:
Temporary working branch for cache-infinispan integration
Copied: core/branches/INFINISPAN (from rev 16768, core/branches/Branch_3_3)
15 years, 6 months
Hibernate SVN: r16768 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-12 07:22:42 -0400 (Fri, 12 Jun 2009)
New Revision: 16768
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationXmlParser.java
Log:
Fixed wrong scope of debug if statement
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationXmlParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationXmlParser.java 2009-06-12 11:22:11 UTC (rev 16767)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationXmlParser.java 2009-06-12 11:22:42 UTC (rev 16768)
@@ -120,12 +120,12 @@
log.debug(
"Trying to open input stream for {}.", mappingFileName.getValue()
);
- InputStream in = getInputStreamForPath( mappingFileName.getValue() );
- if ( in == null ) {
- throw new ValidationException( "Unable to open input stream for mapping file " + mappingFileName + "." );
- }
- xmlParameters.mappings.add( in );
}
+ InputStream in = getInputStreamForPath( mappingFileName.getValue() );
+ if ( in == null ) {
+ throw new ValidationException( "Unable to open input stream for mapping file " + mappingFileName.getValue() + "." );
+ }
+ xmlParameters.mappings.add( in );
}
}
@@ -212,7 +212,7 @@
log.info( "{} found.", VALIDATION_XML_FILE );
- ValidationConfigType validationConfig = null;
+ ValidationConfigType validationConfig;
Schema schema = getValidationConfigurationSchema();
try {
JAXBContext jc = JAXBContext.newInstance( ValidationConfigType.class );
@@ -224,7 +224,7 @@
}
catch ( JAXBException e ) {
log.error( "Error parsing validation.xml: {}", e.getMessage() );
- throw new ValidationException( "Unable to parse " + VALIDATION_XML_FILE);
+ throw new ValidationException( "Unable to parse " + VALIDATION_XML_FILE );
}
return validationConfig;
}
15 years, 6 months
Hibernate SVN: r16766 - beanvalidation/trunk/validation-tck.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-12 07:21:20 -0400 (Fri, 12 Jun 2009)
New Revision: 16766
Modified:
beanvalidation/trunk/validation-tck/pom.xml
Log:
Fixed typo
Modified: beanvalidation/trunk/validation-tck/pom.xml
===================================================================
--- beanvalidation/trunk/validation-tck/pom.xml 2009-06-12 11:20:08 UTC (rev 16765)
+++ beanvalidation/trunk/validation-tck/pom.xml 2009-06-12 11:21:20 UTC (rev 16766)
@@ -232,7 +232,7 @@
<distributionManagement>
<repository>
<!-- Copy the dist to the local checkout of the JBoss maven2 repo ${maven.repository.root} -->
- <!-- It is anticipated that ${maven.repository.root} be set in user's settings.xmlconfiguration -->
+ <!-- It is anticipated that ${maven.repository.root} be set in user's settings.xml -->
<!-- todo : replace this with direct svn access once the svnkit providers are available -->
<id>repository.jboss.org</id>
<url>file://${maven.repository.root}</url>
15 years, 6 months
Hibernate SVN: r16765 - in beanvalidation/trunk/validation-tck: src/main/java/org/hibernate/jsr303/tck/tests and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-12 07:20:08 -0400 (Fri, 12 Jun 2009)
New Revision: 16765
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserInformation.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CreditCard.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CustomConsistentUserValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Optional.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Order.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/OrderLine.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/TestGroup.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/User.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/UserType.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-invalid-xml.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-no-additional-config.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation.xml
Modified:
beanvalidation/trunk/validation-tck/pom.xml
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
Log:
Added some xml config tests
Modified: beanvalidation/trunk/validation-tck/pom.xml
===================================================================
--- beanvalidation/trunk/validation-tck/pom.xml 2009-06-11 19:44:59 UTC (rev 16764)
+++ beanvalidation/trunk/validation-tck/pom.xml 2009-06-12 11:20:08 UTC (rev 16765)
@@ -232,7 +232,7 @@
<distributionManagement>
<repository>
<!-- Copy the dist to the local checkout of the JBoss maven2 repo ${maven.repository.root} -->
- <!-- It is anticipated that ${maven.repository.root} be set in user's settings.xml -->
+ <!-- It is anticipated that ${maven.repository.root} be set in user's settings.xmlconfiguration -->
<!-- todo : replace this with direct svn access once the svnkit providers are available -->
<id>repository.jboss.org</id>
<url>file://${maven.repository.root}</url>
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserInformation.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserInformation.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserInformation.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,52 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.constraints.Pattern;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = ConsistentUserValidator.class)
+@Documented
+@Target({ METHOD, FIELD, TYPE })
+@Retention(RUNTIME)
+public @interface ConsistentUserInformation {
+ public abstract String message() default "User information is not consistent.";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract String stringParam() default "";
+
+ public abstract String[] stringArrayParam() default { };
+
+ public abstract int intParam() default 0;
+
+ public abstract Pattern[] patterns();
+
+ public abstract UserType userType() default UserType.BUYER;
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserInformation.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserValidator.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserValidator.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,34 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ConsistentUserValidator implements ConstraintValidator<ConsistentUserInformation, User> {
+
+ public void initialize(ConsistentUserInformation parameters) {
+ }
+
+ public boolean isValid(User user, ConstraintValidatorContext constraintValidatorContext) {
+ return user.isConsistent();
+ }
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CreditCard.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CreditCard.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CreditCard.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,37 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+import javax.validation.constraints.Pattern;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CreditCard {
+
+ @Pattern(regexp = "[0-9]+", message = "Not a credit casrd number.")
+ private String number;
+
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CreditCard.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CustomConsistentUserValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CustomConsistentUserValidator.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CustomConsistentUserValidator.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,30 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CustomConsistentUserValidator extends ConsistentUserValidator {
+
+ public boolean isValid(User user, ConstraintValidatorContext constraintValidatorContext) {
+ return super.isValid( user, constraintValidatorContext );
+ }
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/CustomConsistentUserValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,51 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+
+import javax.validation.Validator;
+
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import static org.testng.Assert.assertFalse;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+@ValidationXml(value = "validation-no-additional-config.xml")
+@Resource(source = "order-constraints-no-additional-config.xml",
+ destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml")
+public class EmptyXmlConfigurationTest extends AbstractTest {
+
+ @Test
+ public void testNoDefinedConstraints() {
+ Validator validator = TestUtil.getDefaultValidator();
+ assertFalse(
+ validator.getConstraintsForClass( Order.class ).isBeanConstrained(), "Bean should be unsonstrained"
+ );
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,60 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+
+import javax.validation.ValidationException;
+
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+@ValidationXml(value = "validation-invalid-xml.xml")
+public class InvalidXmlConfigurationTest extends AbstractTest {
+
+ @Test
+ public void testInvalidValidationXml() {
+ try {
+ TestUtil.getDefaultValidator();
+ fail();
+ }
+ catch ( ValidationException e ) {
+ // success
+ }
+ }
+
+//
+// @Test
+// public void testNoDefinedConstraints() {
+// Validator validator = getValidatorWithCustomConfiguration( "org/hibernate/validation/engine/xmlconfiguration/validation.xmlconfiguration" );
+// assertFalse(
+// validator.getConstraintsForClass( Order.class ).isBeanConstrained(), "Bean should be unsonstrained"
+// );
+// }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Optional.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Optional.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Optional.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,24 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Optional {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Optional.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Order.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Order.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Order.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,32 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Order {
+
+ private Date orderDate;
+
+ private List<OrderLine> orderLines;
+
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Order.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/OrderLine.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/OrderLine.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/OrderLine.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,24 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class OrderLine {
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/OrderLine.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/TestGroup.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/TestGroup.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/TestGroup.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,24 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface TestGroup {
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/TestGroup.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/User.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/User.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/User.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,63 @@
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.groups.Default;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class User {
+
+ private boolean isConsistent;
+
+ private String firstname;
+
+ private String lastname;
+
+ private CreditCard creditcard;
+
+ @Pattern(regexp = "[0-9 -]+", message = "A phone number can only contain numbers, whitespaces and dashes.", groups = Optional.class)
+ private String phoneNumber;
+
+ @NotNull(groups = Default.class)
+ public String getFirstname() {
+ return firstname;
+ }
+
+ public void setFirstname(String firstname) {
+ this.firstname = firstname;
+ }
+
+ public String getLastname() {
+ return lastname;
+ }
+
+ public void setLastname(String lastname) {
+ this.lastname = lastname;
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+
+ public void setConsistent(boolean consistent) {
+ isConsistent = consistent;
+ }
+
+ public boolean isConsistent() {
+ return isConsistent;
+ }
+
+ public CreditCard getCreditcard() {
+ return creditcard;
+ }
+
+ public void setCreditcard(CreditCard creditcard) {
+ this.creditcard = creditcard;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/User.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/UserType.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/UserType.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/UserType.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,26 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public enum UserType {
+ BUYER,
+ SELLER
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/UserType.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,159 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.Resources;
+import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessage;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+@ValidationXml(value = "validation.xml")
+@Resources(
+ {
+ @Resource(source = "user-constraints.xml",
+ destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml"),
+ @Resource(source = "order-constraints.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml")
+ }
+)
+public class XmlConfigurationTest extends AbstractTest {
+
+ @Test
+ public void testClassConstraintDefinedInXml() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ User user = new User();
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintViolationMessage(
+ constraintViolations.iterator().next(), "Message from xml"
+ );
+
+ user.setConsistent( true );
+ constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ public void testPropertyConstraintDefinedInXml() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ User user = new User();
+ user.setConsistent( true );
+ user.setFirstname( "Wolfeschlegelsteinhausenbergerdorff" );
+
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintViolationMessage( constraintViolations.iterator().next(), "Size is limited!" );
+
+ user.setFirstname( "Wolfgang" );
+ constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ public void testFieldConstraintDefinedInXml() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ User user = new User();
+ user.setConsistent( true );
+ user.setFirstname( "Wolfgang" );
+ user.setLastname( "doe" );
+
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintViolationMessage(
+ constraintViolations.iterator().next(), "Last name has to start with with a capital letter."
+ );
+
+ user.setLastname( "Doe" );
+ constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ public void testAnnotationDefinedConstraintApplies() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ User user = new User();
+ user.setConsistent( true );
+ user.setPhoneNumber( "police" );
+
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintViolationMessage(
+ constraintViolations.iterator().next(),
+ "A phone number can only contain numbers, whitespaces and dashes."
+ );
+
+ user.setPhoneNumber( "112" );
+ constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ public void testCascadingConfiguredInXml() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ User user = new User();
+ user.setConsistent( true );
+ CreditCard card = new CreditCard();
+ card.setNumber( "not a number" );
+ user.setCreditcard( card );
+
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintViolationMessage(
+ constraintViolations.iterator().next(),
+ "Not a credit casrd number."
+ );
+
+ card.setNumber( "1234567890" );
+ constraintViolations = validator.validate( user );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+// @Test(expectedExceptions = ValidationException.class)
+// public void testInvalidValidationXml() {
+// getValidatorWithCustomConfiguration( "META-INF/validation-invalid-xmlconfiguration.xmlconfiguration" );
+// }
+//
+// @Test
+// public void testNoDefinedConstraints() {
+// Validator validator = getValidatorWithCustomConfiguration( "org/hibernate/validation/engine/xmlconfiguration/validation.xmlconfiguration" );
+// assertFalse(
+// validator.getConstraintsForClass( Order.class ).isBeanConstrained(), "Bean should be unsonstrained"
+// );
+// }
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-11 19:44:59 UTC (rev 16764)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-12 11:20:08 UTC (rev 16765)
@@ -17,10 +17,10 @@
*/
package org.hibernate.jsr303.tck.util;
+import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import java.lang.annotation.Annotation;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
@@ -42,12 +42,18 @@
public static <T> void assertCorrectConstraintType(ConstraintViolation<T> violation, Class<?> expectedConstraintType) {
assertEquals(
- (( Annotation )violation.getConstraintDescriptor().getAnnotation()).annotationType().getName(),
+ ( ( Annotation ) violation.getConstraintDescriptor().getAnnotation() ).annotationType().getName(),
expectedConstraintType.getName(),
"Wrong constraint type"
);
}
+ public static <T> void assertCorrectConstraintViolationMessage(ConstraintViolation<T> violation, String message) {
+ assertEquals(
+ violation.getMessage(), message, "Wrong error message"
+ );
+ }
+
public static <T> void assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations, int expectedViolations) {
assertEquals( violations.size(), expectedViolations, "Wrong number of constraint violations" );
}
@@ -55,14 +61,16 @@
public static <T> void assertCorrectConstraintTypes(Set<ConstraintViolation<T>> violations, Class<?>[] expectedConsraintTypes) {
List<String> constraintTypes = new ArrayList<String>();
for ( ConstraintViolation<?> violation : violations ) {
- constraintTypes.add( (( Annotation )violation.getConstraintDescriptor().getAnnotation()).annotationType().getName() );
+ constraintTypes.add(
+ ( ( Annotation ) violation.getConstraintDescriptor().getAnnotation() ).annotationType().getName()
+ );
}
assertEquals( expectedConsraintTypes.length, constraintTypes.size(), "Wring number of constraint types." );
for ( Class<?> expectedConstraintType : expectedConsraintTypes ) {
assertTrue(
- constraintTypes.contains(expectedConstraintType.getName()),
+ constraintTypes.contains( expectedConstraintType.getName() ),
"The constraint type " + expectedConstraintType.getName() + " should have been violated."
);
}
Added: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<constraint-mappings
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
+ xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
+
+ <default-package>org.hibernate.jsr303.tck.tests.xmlconfiguration</default-package>
+
+ <bean class="Order" ignore-annotations="false">
+ </bean>
+
+</constraint-mappings>
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,4 @@
+<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
+ xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
+</constraint-mappings>
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,60 @@
+<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
+ xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
+ <default-package>org.hibernate.jsr303.tck.tests.xmlconfiguration</default-package>
+ <bean class="User" ignore-annotations="false">
+ <class ignore-annotations="true">
+ <group-sequence>
+ <value>User</value>
+ <value>Optional</value>
+ </group-sequence>
+ <constraint annotation="org.hibernate.jsr303.tck.tests.xmlconfiguration.ConsistentUserInformation">
+ <message>Message from xml</message>
+ <groups>
+ <value>javax.validation.groups.Default</value>
+ </groups>
+ <element name="stringParam">foobar</element>
+ <element name="stringArrayParam">
+ <value>foo</value>
+ <value>bar</value>
+ </element>
+ <element name="intParam">
+ <value>42</value>
+ </element>
+ <element name="patterns">
+ <annotation>
+ <element name="regexp">myRegExp1</element>
+ </annotation>
+ <annotation>
+ <element name="regexp">myRegExp2</element>
+ </annotation>
+ </element>
+ <element name="userType">SELLER</element>
+ </constraint>
+ </class>
+ <field name="lastname">
+ <constraint annotation="javax.validation.constraints.Pattern">
+ <message>Last name has to start with with a capital letter.</message>
+ <element name="regexp">^[A-Z][a-z]+</element>
+ </constraint>
+ </field>
+ <field name="creditcard">
+ <valid/>
+ </field>
+ <getter name="firstname" ignore-annotations="true">
+ <constraint annotation="javax.validation.constraints.Size">
+ <message>Size is limited!</message>
+ <groups>
+ <value>org.hibernate.jsr303.tck.tests.xmlconfiguration.TestGroup</value>
+ <value>javax.validation.groups.Default</value>
+ </groups>
+ <element name="max">10</element>
+ </constraint>
+ </getter>
+ </bean>
+ <constraint-definition annotation="org.hibernate.jsr303.tck.tests.xmlconfiguration.ConsistentUserInformation">
+ <validated-by include-existing-validators="false">
+ <value>org.hibernate.jsr303.tck.tests.xmlconfiguration.CustomConsistentUserValidator</value>
+ </validated-by>
+ </constraint-definition>
+</constraint-mappings>
Property changes on: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-invalid-xml.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-invalid-xml.xml (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-invalid-xml.xml 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+</validation-confi>
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-invalid-xml.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-no-additional-config.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-no-additional-config.xml (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-no-additional-config.xml 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config
+ xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd">
+
+ <constraint-mapping>org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml</constraint-mapping>
+</validation-config>
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-no-additional-config.xml
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation.xml (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation.xml 2009-06-12 11:20:08 UTC (rev 16765)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <constraint-mapping>/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml</constraint-mapping>
+ <constraint-mapping>org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml</constraint-mapping>
+ <property name="javax.validation.test">foobar</property>
+</validation-config>
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
15 years, 6 months