Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for WELD-214, WELD-64, WELD-250, WELD-227, WELD-231
- Loading branch information
Showing
19 changed files
with
731 additions
and
2 deletions.
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
133 changes: 133 additions & 0 deletions
133
tests/src/test/java/org/jboss/weld/tests/builtinBeans/BuiltInBeanPassivationCapableTest.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,133 @@ | ||
package org.jboss.weld.tests.builtinBeans; | ||
|
||
import static org.jboss.weld.tests.builtinBeans.Checker.checkBeanManager; | ||
import static org.jboss.weld.tests.builtinBeans.Checker.checkEquality; | ||
import static org.jboss.weld.tests.builtinBeans.Checker.checkEvent; | ||
import static org.jboss.weld.tests.builtinBeans.Checker.checkInjectionPoint; | ||
import static org.jboss.weld.tests.builtinBeans.Checker.checkInstance; | ||
import static org.jboss.weld.tests.builtinBeans.Checker.checkPrincipal; | ||
import static org.jboss.weld.tests.builtinBeans.Checker.checkUserTransaction; | ||
import static org.jboss.weld.tests.builtinBeans.Checker.checkValidator; | ||
import static org.jboss.weld.tests.builtinBeans.Checker.checkValidatorFactory; | ||
|
||
import java.security.Principal; | ||
|
||
import javax.enterprise.event.Event; | ||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
import javax.transaction.UserTransaction; | ||
import javax.validation.Validator; | ||
import javax.validation.ValidatorFactory; | ||
|
||
import org.jboss.testharness.impl.packaging.Artifact; | ||
import org.jboss.weld.test.AbstractWeldTest; | ||
import org.testng.annotations.Test; | ||
|
||
@Artifact | ||
public class BuiltInBeanPassivationCapableTest extends AbstractWeldTest | ||
{ | ||
|
||
@Test | ||
public void testDefaultValidatorBean() throws Throwable | ||
{ | ||
Validator validator = getCurrentManager().getInstanceByType(Validator.class); | ||
Validator validator1 = deserialize(serialize(validator)); | ||
assert checkValidator(validator1); | ||
} | ||
|
||
@Test | ||
public void testDefaultValidatorFactoryBean() throws Throwable | ||
{ | ||
ValidatorFactory validatorFactory = getCurrentManager().getInstanceByType(ValidatorFactory.class); | ||
ValidatorFactory validatorFactory1 = deserialize(serialize(validatorFactory)); | ||
assert checkValidatorFactory(validatorFactory1); | ||
} | ||
|
||
@Test(groups="incontainer-broken") | ||
public void testPrincipal() throws Throwable | ||
{ | ||
Principal principal = getCurrentManager().getInstanceByType(Principal.class); | ||
Principal principal1 = deserialize(serialize(principal)); | ||
assert checkPrincipal(principal1); | ||
} | ||
|
||
@Test | ||
public void testUserTransactionBean() throws Throwable | ||
{ | ||
UserTransaction userTransaction = getCurrentManager().getInstanceByType(UserTransaction.class); | ||
UserTransaction userTransaction1 = deserialize(serialize(userTransaction)); | ||
assert checkUserTransaction(userTransaction1); | ||
} | ||
|
||
@Test | ||
public void testBeanManagerBean() throws Throwable | ||
{ | ||
BeanManager beanManager = getCurrentManager().getInstanceByType(BeanManager.class); | ||
BeanManager beanManager1 = deserialize(serialize(beanManager)); | ||
assert checkBeanManager(beanManager1); | ||
assert checkEquality(beanManager, beanManager1); | ||
} | ||
|
||
@Test | ||
public void testInstance() throws Throwable | ||
{ | ||
Instance<Cow> instance = getCurrentManager().getInstanceByType(Consumer.class).getCow(); | ||
Instance<Cow> instance1 = deserialize(serialize(instance)); | ||
assert checkInstance(instance1); | ||
assert checkEquality(instance, instance1); | ||
} | ||
|
||
@Test | ||
public void testEvent() throws Throwable | ||
{ | ||
Event<Cow> event = getCurrentManager().getInstanceByType(Consumer.class).getEvent(); | ||
CowEventObserver observer = getCurrentManager().getInstanceByType(CowEventObserver.class); | ||
Event<Cow> event1 = deserialize(serialize(event)); | ||
assert checkEvent(event1, observer); | ||
assert checkEquality(event, event1); | ||
} | ||
|
||
@Test | ||
public void testFieldInjectionPoint() throws Throwable | ||
{ | ||
Dog.reset(); | ||
getCurrentManager().getInstanceByType(FieldInjectionPointConsumer.class).ping(); | ||
InjectionPoint injectionPoint = Dog.getInjectionPoint(); | ||
InjectionPoint injectionPoint1 = deserialize(serialize(injectionPoint)); | ||
assert checkInjectionPoint(injectionPoint1, FieldInjectionPointConsumer.class); | ||
assert checkEquality(injectionPoint, injectionPoint1); | ||
} | ||
|
||
@Test | ||
public void testConstructorInjectionPoint() throws Throwable | ||
{ | ||
Dog.reset(); | ||
getCurrentManager().getInstanceByType(ConstructorInjectionPointConsumer.class).ping(); | ||
InjectionPoint injectionPoint = Dog.getInjectionPoint(); | ||
InjectionPoint injectionPoint1 = deserialize(serialize(injectionPoint)); | ||
assert checkInjectionPoint(injectionPoint1, ConstructorInjectionPointConsumer.class); | ||
assert checkEquality(injectionPoint, injectionPoint1); | ||
} | ||
|
||
@Test | ||
public void testMethodInjectionPoint() throws Throwable | ||
{ | ||
Dog.reset(); | ||
getCurrentManager().getInstanceByType(MethodInjectionPointConsumer.class).ping(); | ||
InjectionPoint injectionPoint = Dog.getInjectionPoint(); | ||
InjectionPoint injectionPoint1 = deserialize(serialize(injectionPoint)); | ||
assert checkInjectionPoint(injectionPoint1, MethodInjectionPointConsumer.class); | ||
assert checkEquality(injectionPoint, injectionPoint1); | ||
} | ||
|
||
@Test | ||
public void testAllOnBean() throws Throwable | ||
{ | ||
Consumer consumer = getCurrentManager().getInstanceByType(Consumer.class); | ||
consumer.check(); | ||
Consumer consumer1 = deserialize(serialize(consumer)); | ||
consumer1.check(); | ||
} | ||
|
||
} |
122 changes: 122 additions & 0 deletions
122
tests/src/test/java/org/jboss/weld/tests/builtinBeans/Checker.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,122 @@ | ||
package org.jboss.weld.tests.builtinBeans; | ||
|
||
import java.security.Principal; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.event.Event; | ||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
import javax.transaction.SystemException; | ||
import javax.transaction.UserTransaction; | ||
import javax.validation.ValidationException; | ||
import javax.validation.Validator; | ||
import javax.validation.ValidatorFactory; | ||
|
||
public class Checker | ||
{ | ||
|
||
public static boolean checkPrincipal(Principal principal) | ||
{ | ||
principal.getName(); | ||
return true; | ||
} | ||
|
||
public static boolean checkBeanManager(BeanManager beanManager) | ||
{ | ||
return beanManager != null && beanManager.isScope(ApplicationScoped.class); | ||
} | ||
|
||
public static boolean checkUserTransaction(UserTransaction userTransaction) | ||
{ | ||
try | ||
{ | ||
if (userTransaction != null) | ||
{ | ||
userTransaction.getStatus(); | ||
return true; | ||
} | ||
} | ||
catch (SystemException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
return false; | ||
} | ||
|
||
public static boolean checkValidator(Validator validator) | ||
{ | ||
try | ||
{ | ||
if (validator != null) | ||
{ | ||
validator.unwrap(String.class); | ||
} | ||
} | ||
catch (ValidationException e) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static boolean checkValidatorFactory(ValidatorFactory validatorFactory) | ||
{ | ||
try | ||
{ | ||
if (validatorFactory != null) | ||
{ | ||
validatorFactory.unwrap(String.class); | ||
} | ||
} | ||
catch (ValidationException e) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static boolean checkInstance(Instance<Cow> cow) | ||
{ | ||
if (cow != null && cow.get() != null) | ||
{ | ||
return cow.get().getName().equals("Daisy"); | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean checkEvent(Event<Cow> cowEvent, CowEventObserver observer) | ||
{ | ||
observer.reset(); | ||
if (cowEvent != null) | ||
{ | ||
cowEvent.fire(new Cow()); | ||
return observer.isObserved(); | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean checkInjectionPoint(InjectionPoint injectionPoint, Class<?> injectedClass) | ||
{ | ||
if (injectionPoint != null) | ||
{ | ||
return injectedClass.equals(injectionPoint.getBean().getBeanClass()); | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean checkEquality(Object object1, Object object2) | ||
{ | ||
return object1.equals(object2) && object1.hashCode() == object2.hashCode(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
tests/src/test/java/org/jboss/weld/tests/builtinBeans/ConstructorInjectionPointConsumer.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,19 @@ | ||
package org.jboss.weld.tests.builtinBeans; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.enterprise.context.SessionScoped; | ||
import javax.inject.Inject; | ||
|
||
@SessionScoped | ||
public class ConstructorInjectionPointConsumer implements Serializable | ||
{ | ||
|
||
public ConstructorInjectionPointConsumer() {} | ||
|
||
@Inject | ||
public ConstructorInjectionPointConsumer(Dog dog) {} | ||
|
||
public void ping() {} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
tests/src/test/java/org/jboss/weld/tests/builtinBeans/Consumer.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,60 @@ | ||
package org.jboss.weld.tests.builtinBeans; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.SessionScoped; | ||
import javax.enterprise.event.Event; | ||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.inject.Inject; | ||
import javax.transaction.UserTransaction; | ||
import javax.validation.Validator; | ||
import javax.validation.ValidatorFactory; | ||
|
||
@SessionScoped | ||
public class Consumer implements Serializable | ||
{ | ||
|
||
@Inject Validator validator; | ||
@Inject ValidatorFactory validatorFactory; | ||
// Not working incontainer as there is no principal | ||
//@Inject Principal principal; | ||
@Inject UserTransaction userTransaction; | ||
@Inject BeanManager beanManager; | ||
@Inject Instance<Cow> cow; | ||
@Inject Event<Cow> event; | ||
@Inject CowEventObserver observer; | ||
|
||
@PostConstruct | ||
public void postConstruct() | ||
{ | ||
cow.get().setName("Daisy"); | ||
} | ||
|
||
public Instance<Cow> getCow() | ||
{ | ||
return cow; | ||
} | ||
|
||
public Event<Cow> getEvent() | ||
{ | ||
return event; | ||
} | ||
|
||
public void check() | ||
{ | ||
assert Checker.checkBeanManager(beanManager); | ||
|
||
// Not working incontainer as there is no principal | ||
//assert Checker.checkPrincipal(principal); | ||
assert Checker.checkUserTransaction(userTransaction); | ||
assert Checker.checkValidator(validator); | ||
assert Checker.checkValidatorFactory(validatorFactory); | ||
assert Checker.checkInstance(cow); | ||
assert Checker.checkEvent(event, observer); | ||
} | ||
|
||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
tests/src/test/java/org/jboss/weld/tests/builtinBeans/Cow.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,21 @@ | ||
package org.jboss.weld.tests.builtinBeans; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
|
||
@RequestScoped | ||
public class Cow | ||
{ | ||
|
||
private String name; | ||
|
||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
public void setName(String name) | ||
{ | ||
this.name = name; | ||
} | ||
|
||
} |
Oops, something went wrong.