[hibernate-commits] Hibernate SVN: r17246 - beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Aug 6 11:33:38 EDT 2009


Author: hardy.ferentschik
Date: 2009-08-06 11:33:38 -0400 (Thu, 06 Aug 2009)
New Revision: 17246

Added:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidationTest.java
Log:
Added tests for Validation class

Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidationTest.java (from rev 17238, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidationTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidationTest.java	2009-08-06 15:33:38 UTC (rev 17246)
@@ -0,0 +1,98 @@
+// $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.validation;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+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.Classes;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * Tests for the implementation of <code>Validator</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+public class ValidationTest extends AbstractTest {
+
+	@Test
+	@SpecAssertion(section = "4.4.5", id = "a")
+	public void testVerifyMethodsOfValidationObjects() {
+		Class<?> validatorClass = javax.validation.Validation.class;
+
+		List<Method> expectedValidationMethods = new ArrayList<Method>();
+		Method buildDefaultValidatorFactoryMethod = null;
+		try {
+			buildDefaultValidatorFactoryMethod = validatorClass.getMethod( "buildDefaultValidatorFactory" );
+		}
+		catch ( NoSuchMethodException e ) {
+			fail( "Validation class is mising bootstrap method." );
+		}
+		expectedValidationMethods.add( buildDefaultValidatorFactoryMethod );
+
+		Method byDefaultProviderMethod = null;
+		try {
+			byDefaultProviderMethod = validatorClass.getMethod( "byDefaultProvider" );
+		}
+		catch ( NoSuchMethodException e ) {
+			fail( "Validation class is mising bootstrap method." );
+		}
+		expectedValidationMethods.add( byDefaultProviderMethod );
+
+		Method byProviderMethod = null;
+		try {
+			byProviderMethod = validatorClass.getMethod( "byProvider", Class.class );
+		}
+		catch ( NoSuchMethodException e ) {
+			fail( "Validation class is mising bootstrap method." );
+		}
+		expectedValidationMethods.add( byProviderMethod );
+
+		Method[] validationMethods = validatorClass.getMethods();
+		for ( Method m : validationMethods ) {
+			if ( expectedValidationMethods.contains( m ) || m.getDeclaringClass() != validatorClass ) {
+				continue;
+			}
+			if ( Modifier.isPublic( m.getModifiers() ) || Modifier.isProtected( m.getModifiers() ) ) {
+				fail( "Validation cannot have a non private method on top of the specified ones. " + m.getName() + " not allowed." );
+			}
+		}
+
+		Field[] validationFields = validatorClass.getFields();
+		for ( Field f : validationFields ) {
+			if ( f.getDeclaringClass() != validatorClass ) {
+				continue;
+			}
+			if ( Modifier.isPublic( f.getModifiers() ) || Modifier.isProtected( f.getModifiers() ) ) {
+				fail( "Validation cannot have a non private field. " + f.getName() + " not allowed." );
+			}
+		}
+	}
+}
\ No newline at end of file



More information about the hibernate-commits mailing list