Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2370 1c488680-804c-0410-94cd-c6b725194a0e
- Loading branch information
Showing
2 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/SimpleEventTest.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,129 @@ | ||
package org.jboss.webbeans.test.unit.implementation.event; | ||
|
||
import javax.event.Event; | ||
import javax.event.Fires; | ||
import javax.event.Observes; | ||
import javax.inject.AnnotationLiteral; | ||
|
||
import org.jboss.testharness.impl.packaging.Artifact; | ||
import org.jboss.webbeans.ManagerImpl; | ||
import org.jboss.webbeans.test.AbstractWebBeansTest; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
@Artifact | ||
public class SimpleEventTest extends AbstractWebBeansTest | ||
{ | ||
private static boolean called_flag_for_BindingType; | ||
private static boolean called_flag_for_NonBindingType; | ||
|
||
private static void initCalledFlag() { | ||
called_flag_for_BindingType = false; | ||
called_flag_for_NonBindingType = false; | ||
} | ||
|
||
@Override | ||
@BeforeMethod | ||
public void before() throws Exception | ||
{ | ||
initCalledFlag(); | ||
super.before(); | ||
} | ||
|
||
@Override | ||
@AfterMethod | ||
public void after() throws Exception | ||
{ | ||
initCalledFlag(); | ||
super.after(); | ||
} | ||
|
||
@Test | ||
public void testEventUsingManager() | ||
{ | ||
ManagerImpl manager = getCurrentManager(); | ||
|
||
manager.fireEvent("Fired using Manager Interface with AnnotationLiteral.", | ||
new AnnotationLiteral<Updated>(){}); | ||
|
||
assert called_flag_for_NonBindingType == true; | ||
assert called_flag_for_BindingType == true; | ||
|
||
initCalledFlag(); | ||
|
||
manager.fireEvent("Fired using Manager Interface."); | ||
|
||
assert called_flag_for_NonBindingType == true; | ||
assert called_flag_for_BindingType == false; // not called | ||
} | ||
|
||
@Test | ||
public void testEventUsingEvent() | ||
{ | ||
ManagerImpl manager = getCurrentManager(); | ||
|
||
App app = manager.getInstanceByType(App.class); | ||
|
||
app.fireEventByBindingDeclaredAtInjectionPoint(); | ||
|
||
assert called_flag_for_NonBindingType == true; | ||
assert called_flag_for_BindingType == true; | ||
|
||
initCalledFlag(); | ||
|
||
app.fireEventByAnnotationLiteral(); | ||
|
||
assert called_flag_for_NonBindingType == true; | ||
assert called_flag_for_BindingType == true; | ||
|
||
initCalledFlag(); | ||
|
||
app.fireEventNonBindingType(); | ||
|
||
assert called_flag_for_NonBindingType == true; | ||
assert called_flag_for_BindingType == false; // not called | ||
} | ||
|
||
public static class App | ||
{ | ||
@Fires | ||
Event<String> event1; | ||
|
||
@Fires | ||
@Updated | ||
Event<String> event2; | ||
|
||
@Fires | ||
Event<String> event3; | ||
|
||
public void fireEventByAnnotationLiteral() | ||
{ | ||
event1.fire("Fired using Event Interface with AnnotationLiteral.", | ||
new AnnotationLiteral<Updated>(){}); | ||
} | ||
|
||
public void fireEventByBindingDeclaredAtInjectionPoint() | ||
{ | ||
event2.fire("Fired using Event Interface with Binding Declared."); | ||
} | ||
|
||
public void fireEventNonBindingType() | ||
{ | ||
event3.fire("Fired using Event Interface with Non-BindingType."); | ||
} | ||
} | ||
|
||
public static class Receiver | ||
{ | ||
public void receive1(@Observes @Updated String s) | ||
{ | ||
called_flag_for_BindingType = true; | ||
} | ||
|
||
public void receive2(@Observes String s) | ||
{ | ||
called_flag_for_NonBindingType = true; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/Updated.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,22 @@ | ||
package org.jboss.webbeans.test.unit.implementation.event; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.inject.BindingType; | ||
|
||
@BindingType | ||
@Retention(RUNTIME) | ||
@Target( { TYPE, METHOD, FIELD, PARAMETER }) | ||
@Documented | ||
@interface Updated | ||
{ | ||
|
||
} |