Skip to content

Commit

Permalink
Unit tests added from WBRI-225.
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2370 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
drallen committed Apr 9, 2009
1 parent 0b6e77e commit dd403e9
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
@@ -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;
}
}
}
@@ -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
{

}

0 comments on commit dd403e9

Please sign in to comment.