Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.PassivationCapable;
import javax.enterprise.util.AnnotationLiteral;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
Expand All @@ -39,7 +40,7 @@
/**
* @author Hardy Ferentschik
*/
public class ValidatorBean implements Bean<Validator> {
public class ValidatorBean implements Bean<Validator>, PassivationCapable {
private final BeanManager beanManager;
private final Set<Annotation> qualifiers;

Expand Down Expand Up @@ -127,4 +128,9 @@ private <T> T getReference(BeanManager beanManager, Class<T> clazz) {
}
return null;
}

@Override
public String getId() {
return ValidatorBean.class.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.PassivationCapable;
import javax.enterprise.util.AnnotationLiteral;
import javax.validation.BootstrapConfiguration;
import javax.validation.Configuration;
Expand All @@ -43,7 +44,7 @@
/**
* @author Hardy Ferentschik
*/
public class ValidatorFactoryBean implements Bean<ValidatorFactory> {
public class ValidatorFactoryBean implements Bean<ValidatorFactory>, PassivationCapable {
private final BeanManager beanManager;
private final Set<Annotation> qualifiers;
private final Set<DestructibleBeanInstance<?>> destructibleResources;
Expand Down Expand Up @@ -205,4 +206,9 @@ private <T> T createInstance(Class<T> type) {
destructibleResources.add( destructibleInstance );
return destructibleInstance.getInstance();
}

@Override
public String getId() {
return ValidatorFactoryBean.class.getName();
}
}
6 changes: 6 additions & 0 deletions integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<classifier>testing</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.hibernate.validator.integration.cdi.service.PingServiceImpl;
import org.hibernate.validator.integration.util.IntegrationTestUtil;

import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-) Nice one


/**
* @author Hardy Ferentschik
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;

/**
* @author Hardy Ferentschik
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.hibernate.validator.integration.cdi;

import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
Expand All @@ -30,8 +32,9 @@

import org.hibernate.validator.cdi.HibernateValidator;
import org.hibernate.validator.integration.util.IntegrationTestUtil;
import org.hibernate.validator.testutil.TestForIssue;

import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;

/**
* @author Hardy Ferentschik
Expand All @@ -48,6 +51,9 @@ public class QualifiedInjectionUnitIT {
@HibernateValidator
private Validator validator;

@Inject
TestEntity testEntity;

@Deployment
public static WebArchive createTestArchive() throws Exception {
return ShrinkWrap
Expand All @@ -65,4 +71,34 @@ public void testQualifiedValidatorFactoryAndValidatorInjectable() {
assertNotNull( "The validator factory should have been injected", validatorFactory );
assertNotNull( "The validator should have been injected", validator );
}

@Test
@TestForIssue(jiraKey = "HV-787")
public void testInjectionIntoBeanWithPassivatingScope() throws Exception {
assertNotNull( testEntity );
assertNotNull( testEntity.getValidatorFactory() );
assertNotNull( testEntity.getValidator() );
}

@SessionScoped
@SuppressWarnings("serial")
public static class TestEntity implements Serializable {

@Inject
@HibernateValidator
private ValidatorFactory validatorFactory;

@Inject
@HibernateValidator
private Validator validator;


public ValidatorFactory getValidatorFactory() {
return validatorFactory;
}

public Validator getValidator() {
return validator;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

import org.hibernate.validator.integration.util.IntegrationTestUtil;

import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;

/**
* Tests the integration of Hibernate Validator in JBoss AS 7
Expand Down Expand Up @@ -89,7 +89,7 @@ public void testValidatorFactoryPassedToPersistenceUnit() throws Exception {
// under javax.persistence.validation.factory. This works for the JBoss AS purposes, but not generically
Object obj = properties.get( "javax.persistence.validation.factory" );
assertTrue( "There should be an object under this property", obj != null );
ValidatorFactory factory = ( ValidatorFactory ) obj;
ValidatorFactory factory = (ValidatorFactory) obj;
// assertTrue(
// "The Custom Validator implementation should be used",
// factory instanceof MyValidationProvider.DummyValidatorFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

import org.hibernate.validator.integration.util.IntegrationTestUtil;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Tests the integration of Hibernate Validator in JBoss AS 7
Expand Down Expand Up @@ -88,7 +88,7 @@ public void testValidatorFactoryPassedToPersistenceUnit() throws Exception {
// under javax.persistence.validation.factory. This works for the JBoss AS purposes, but not generically
Object obj = properties.get( "javax.persistence.validation.factory" );
assertTrue( "There should be an object under this property", obj != null );
ValidatorFactory factory = ( ValidatorFactory ) obj;
ValidatorFactory factory = (ValidatorFactory) obj;
assertEquals(
"The Hibernate Validator implementation should be used",
"ValidatorImpl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

import org.hibernate.validator.integration.util.IntegrationTestUtil;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* Tests the integration of Hibernate Validator in JBoss AS 7.
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
<artifactId>hibernate-validator</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<classifier>testing</classifier>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
Expand Down