Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-546 Adding tests for LazyValidatorFactory
- Loading branch information
1 parent
62f650a
commit 38af0bc
Showing
6 changed files
with
296 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...tor/integration/lazyfactory/LazyValidatorFactoryWithValidationXmlButNoProviderTestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hibernate.validator.integration.lazyfactory; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ArchivePaths; | ||
import org.jboss.shrinkwrap.api.Node; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.hibernate.validator.engine.ValidatorImpl; | ||
import org.hibernate.validator.integration.util.IntegrationTestUtil; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
import static junit.framework.Assert.assertNotNull; | ||
import static junit.framework.Assert.fail; | ||
|
||
/** | ||
* Tests for {@code LazyValidatorFactory}. See HV-546. | ||
* | ||
* @author Hardy Ferentschik | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class LazyValidatorFactoryWithValidationXmlButNoProviderTestIT { | ||
private static final String WAR_FILE_NAME = LazyValidatorFactoryWithValidationXmlButNoProviderTestIT.class.getSimpleName() + ".war"; | ||
|
||
@Deployment | ||
public static Archive<?> createTestArchive() { | ||
Archive<?> beanValidationJarWithMissingProvider = IntegrationTestUtil.createCustomBeanValidationProviderJar(); | ||
Node providerClass = beanValidationJarWithMissingProvider.delete( | ||
"org/hibernate/validator/integration/util/MyValidationProvider.class" | ||
); | ||
if ( providerClass == null ) { | ||
fail( "MyValidationProvider was not as expected in the custom jar" ); | ||
} | ||
return ShrinkWrap.create( WebArchive.class, WAR_FILE_NAME ) | ||
.addClasses( | ||
MyValidatorCreator.class | ||
) | ||
.addAsLibraries( IntegrationTestUtil.bundleHibernateValidatorWithDependencies( true ) ) | ||
.addAsLibrary( beanValidationJarWithMissingProvider ) | ||
.addAsResource( "log4j.properties" ) | ||
.addAsWebInfResource( EmptyAsset.INSTANCE, ArchivePaths.create( "beans.xml" ) ) | ||
.addAsWebInfResource( "jboss-deployment-structure.xml" ); | ||
} | ||
|
||
@Inject | ||
private MyValidatorCreator validatorCreator; | ||
|
||
@Test | ||
public void testBootstrappingDoesNotFailDueToMissingCustomProvider() throws Exception { | ||
assertNotNull( "The creator bean should have been injected", validatorCreator ); | ||
assertEquals( | ||
"Since the custom provider cannot be loaded, Hibernate Validator should be the default", | ||
ValidatorImpl.class.getName(), | ||
validatorCreator.getValidator().getClass().getName() | ||
); | ||
} | ||
} | ||
|
||
|
74 changes: 74 additions & 0 deletions
74
...ernate/validator/integration/lazyfactory/LazyValidatorFactoryWithValidationXmlTestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hibernate.validator.integration.lazyfactory; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ArchivePaths; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.hibernate.validator.integration.util.IntegrationTestUtil; | ||
import org.hibernate.validator.integration.util.MyValidator; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
import static junit.framework.Assert.assertNotNull; | ||
|
||
/** | ||
* Tests for {@code LazyValidatorFactory}. See HV-546. | ||
* | ||
* @author Hardy Ferentschik | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class LazyValidatorFactoryWithValidationXmlTestIT { | ||
private static final String WAR_FILE_NAME = LazyValidatorFactoryWithValidationXmlTestIT.class.getSimpleName() + ".war"; | ||
|
||
@Deployment | ||
public static Archive<?> createTestArchive() { | ||
return ShrinkWrap.create( WebArchive.class, WAR_FILE_NAME ) | ||
.addClasses( | ||
MyValidatorCreator.class | ||
) | ||
.addAsLibraries( IntegrationTestUtil.bundleHibernateValidatorWithDependencies( true ) ) | ||
.addAsLibraries( IntegrationTestUtil.createCustomBeanValidationProviderJar() ) | ||
.addAsResource( "validation.xml", "META-INF/validation.xml" ) | ||
.addAsResource( "log4j.properties" ) | ||
.addAsWebInfResource( EmptyAsset.INSTANCE, ArchivePaths.create( "beans.xml" ) ) | ||
.addAsWebInfResource( "jboss-deployment-structure.xml" ); | ||
} | ||
|
||
@Inject | ||
private MyValidatorCreator validatorCreator; | ||
|
||
@Test | ||
public void testBootstrapCustomProviderWithLazyFactory() throws Exception { | ||
assertNotNull( "The creator bean should have been injected", validatorCreator ); | ||
assertEquals( | ||
"The custom validator should have been created", | ||
MyValidator.class.getName(), | ||
validatorCreator.getValidator().getClass().getName() | ||
); | ||
} | ||
} | ||
|
||
|
74 changes: 74 additions & 0 deletions
74
...ate/validator/integration/lazyfactory/LazyValidatorFactoryWithoutValidationXmlTestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hibernate.validator.integration.lazyfactory; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ArchivePaths; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.hibernate.validator.engine.ValidatorImpl; | ||
import org.hibernate.validator.integration.util.IntegrationTestUtil; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
import static junit.framework.Assert.assertNotNull; | ||
|
||
/** | ||
* Tests for {@code LazyValidatorFactory}. See HV-546. | ||
* | ||
* @author Hardy Ferentschik | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class LazyValidatorFactoryWithoutValidationXmlTestIT { | ||
private static final String WAR_FILE_NAME = LazyValidatorFactoryWithoutValidationXmlTestIT.class.getSimpleName() + ".war"; | ||
|
||
@Deployment | ||
public static Archive<?> createTestArchive() { | ||
return ShrinkWrap.create( WebArchive.class, WAR_FILE_NAME ) | ||
.addClasses( | ||
MyValidatorCreator.class | ||
) | ||
.addAsLibraries( IntegrationTestUtil.bundleHibernateValidatorWithDependencies( true ) ) | ||
.addAsLibrary( IntegrationTestUtil.createCustomBeanValidationProviderJar() ) | ||
.addAsResource( "log4j.properties" ) | ||
.addAsWebInfResource( EmptyAsset.INSTANCE, ArchivePaths.create( "beans.xml" ) ) | ||
.addAsWebInfResource( "jboss-deployment-structure.xml" ); | ||
} | ||
|
||
@Inject | ||
private MyValidatorCreator validatorCreator; | ||
|
||
@Test | ||
public void testBootstrapWithoutValidationXmlCreatesHibernateValidatorInstance() throws Exception { | ||
assertNotNull( "The creator bean should have been injected", validatorCreator ); | ||
assertEquals( | ||
"Hibernate Validator should be the chosen provider. " + | ||
"Even though we bundle another provider it does not get explicitly configured.", | ||
ValidatorImpl.class.getName(), | ||
validatorCreator.getValidator().getClass().getName() | ||
); | ||
} | ||
} | ||
|
||
|
35 changes: 35 additions & 0 deletions
35
...est/src/test/java/org/hibernate/validator/integration/lazyfactory/MyValidatorCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hibernate.validator.integration.lazyfactory; | ||
|
||
import javax.ejb.Stateful; | ||
import javax.validation.Validator; | ||
|
||
import org.hibernate.validator.util.LazyValidatorFactory; | ||
|
||
/** | ||
* @author Hardy Ferentschik | ||
*/ | ||
@Stateful | ||
public class MyValidatorCreator { | ||
public Validator getValidator() { | ||
LazyValidatorFactory factory = new LazyValidatorFactory(); | ||
return factory.getValidator(); | ||
} | ||
} | ||
|
||
|
30 changes: 30 additions & 0 deletions
30
hibernate-validator-integrationtest/src/test/resources/jboss-deployment-structure.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ JBoss, Home of Professional Open Source | ||
~ Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
~ by the @authors tag. See the copyright.txt in the distribution for a | ||
~ full listing of individual contributors. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
<jboss-deployment-structure> | ||
<deployment> | ||
<exclusions> | ||
<!-- | ||
In order to test with the Hibernate Validator classes bundled in the war file we have to make sure | ||
that the default org.hibernate.validator module classes are not loaded/used instead. | ||
System dependencies have precedence - see https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7 | ||
--> | ||
<module name="org.hibernate.validator"/> | ||
</exclusions> | ||
</deployment> | ||
</jboss-deployment-structure> | ||
|