[hibernate-commits] Hibernate SVN: r16817 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider and 5 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jun 17 07:21:33 EDT 2009


Author: hardy.ferentschik
Date: 2009-06-17 07:21:33 -0400 (Wed, 17 Jun 2009)
New Revision: 16817

Added:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/MappingStreamHandlingTest.java
   beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/configuration/
   beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/configuration/empty-constraints.xml
Modified:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/validationxml/ValidationXmlBootstrapTest.java
   beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
added some tests for mapping stream handling

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java	2009-06-17 10:42:27 UTC (rev 16816)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java	2009-06-17 11:21:33 UTC (rev 16817)
@@ -57,7 +57,6 @@
 			}
 		};
 
-
 		TCKValidatorConfiguration configuration = Validation
 				.byProvider( TCKValidationProvider.class )
 				.providerResolver( resolver )

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/validationxml/ValidationXmlBootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/validationxml/ValidationXmlBootstrapTest.java	2009-06-17 10:42:27 UTC (rev 16816)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/validationxml/ValidationXmlBootstrapTest.java	2009-06-17 11:21:33 UTC (rev 16817)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
 /*
 * JBoss, Home of Professional Open Source
 * Copyright 2008, Red Hat Middleware LLC, and individual contributors

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/MappingStreamHandlingTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/MappingStreamHandlingTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/MappingStreamHandlingTest.java	2009-06-17 11:21:33 UTC (rev 16817)
@@ -0,0 +1,113 @@
+// $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.configuration;
+
+import java.io.IOException;
+import java.io.InputStream;
+import javax.validation.Configuration;
+import javax.validation.Validation;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+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.Resource;
+import static org.testng.Assert.assertTrue;
+import static org.testng.FileAssert.fail;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Resource(source = "empty-constraints.xml",
+		destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/configuration/empty-constraints.xml")
+public class MappingStreamHandlingTest extends AbstractTest {
+
+
+	@Test
+	@SpecAssertion(section = "4.4.3", id = "b")
+	public void testMappingStreamGetsClosed() {
+		Configuration<?> config = Validation.byDefaultProvider().configure();
+		InputStream in = getInputStreamForPath( "org/hibernate/jsr303/tck/tests/configuration/empty-constraints.xml" );
+		DelegatingInputStream delegatingInputStream = new DelegatingInputStream( in );
+		config.addMapping( delegatingInputStream );
+		config.buildValidatorFactory();
+
+		assertTrue( delegatingInputStream.closeHasBeenCalled, "The input stream must be closed." );
+	}
+
+	@Test
+	@SpecAssertion(section = "4.4.3", id = "b")
+	public void testMappingStreamGetsClosedInExceptionalCondition() {
+		Configuration<?> config = Validation.byDefaultProvider().configure();
+		DummyInputStream dummyIn = new DummyInputStream();
+		config.addMapping( dummyIn );
+		try {
+			config.buildValidatorFactory();
+			fail();
+		}
+		catch ( Exception e ) {
+			// success
+		}
+
+		assertTrue( dummyIn.closeHasBeenCalled, "The input stream must be closed." );
+	}
+
+	public class DummyInputStream extends InputStream {
+		boolean closeHasBeenCalled = false;
+
+		public int read() throws IOException {
+			throw new IOException();
+		}
+
+		public void close() throws IOException {
+			closeHasBeenCalled = true;
+			super.close();
+		}
+	}
+
+	private InputStream getInputStreamForPath(String path) {
+		// try the context class loader first
+		InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream( path );
+
+		// try the current class loader
+		if ( inputStream == null ) {
+			inputStream = this.getClass().getResourceAsStream( path );
+		}
+		return inputStream;
+	}
+
+	public class DelegatingInputStream extends InputStream {
+		boolean closeHasBeenCalled = false;
+		final InputStream delegate;
+
+		public DelegatingInputStream(InputStream in) {
+			delegate = in;
+		}
+
+		public int read() throws IOException {
+			return delegate.read();
+		}
+
+		public void close() throws IOException {
+			closeHasBeenCalled = true;
+			delegate.close();
+		}
+	}
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/configuration/MappingStreamHandlingTest.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/configuration/empty-constraints.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/configuration/empty-constraints.xml	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/configuration/empty-constraints.xml	2009-06-17 11:21:33 UTC (rev 16817)
@@ -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>


Property changes on: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/configuration/empty-constraints.xml
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-06-17 10:42:27 UTC (rev 16816)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-06-17 11:21:33 UTC (rev 16817)
@@ -703,33 +703,29 @@
                 identifying the provider.</text>
         </assertion>
         <assertion id="b">
-            <text>The isSuitable() method of its ValidationProvider implementation must return true
-                when this sub interface type is passed as a parameter, false otherwise</text>
-        </assertion>
-        <assertion id="c">
             <text>Streams represented in the XML configuration and opened by the Configuration
                 implementation must be closed by the Configuration implementation after the
                 ValidatorFactory creation (or if an exception occurs)</text>
         </assertion>
-        <assertion id="d">
+        <assertion id="c">
             <text>Use the provider implementation requested if Configuration has been created from
                 Validation.byProvider(Class)</text>
         </assertion>
-        <assertion id="e">
+        <assertion id="d">
             <text>Use the provider implementation associated with the Configuration implementation
                 described in the XML configuration (under validation-config.default-provider see
                 Section 4.4.6) if defined: the value of this element is the fully qualified class
                 name of the Configuration sub interface uniquely identifying the provider.</text>
         </assertion>
-        <assertion id="f">
+        <assertion id="e">
             <text>Use the first provider implementation returned by
                 validationProviderResolver.getValidationProviders()</text>
         </assertion>
-        <assertion id="g">
+        <assertion id="f">
             <text>If no ValidationProviderResolver instance has been specified, the default
-                ValidationProviderResolv- er is used</text>
+                ValidationProviderResolver is used</text>
         </assertion>
-        <assertion id="h">
+        <assertion id="g">
             <text>If a problem occurs while building the ValidationFactory, a ValidationException is
                 raised</text>
         </assertion>




More information about the hibernate-commits mailing list