You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2015/04/22 12:06:10 UTC

svn commit: r1675309 - in /openwebbeans/branches/owb_1.2.x/webbeans-impl/src: main/java/org/apache/webbeans/event/ test/java/org/apache/webbeans/newtests/portable/events/ test/java/org/apache/webbeans/test/event/

Author: rmannibucau
Date: Wed Apr 22 10:06:10 2015
New Revision: 1675309

URL: http://svn.apache.org/r1675309
Log:
OWB-1057 using real event type and not the Event<X> metadata to fire an event to support apps with event API design

Added:
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/ListenOnInterfaceTest.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/EventImpl.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/FireIEvent.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/IEvent.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/ListentIEvent.java
Modified:
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java?rev=1675309&r1=1675308&r2=1675309&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java (original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java Wed Apr 22 10:06:10 2015
@@ -79,7 +79,7 @@ public class EventImpl<T> implements Eve
     @Override
     public void fire(T event)
     {
-        webBeansContext.getBeanManagerImpl().fireEvent(event, new EventMetadataImpl(eventType, injectionPoint, injectedBindings), false);
+        webBeansContext.getBeanManagerImpl().fireEvent(event, new EventMetadataImpl(event == null ? eventType : event.getClass(), injectionPoint, injectedBindings), false);
     }
 
     /**

Added: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/ListenOnInterfaceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/ListenOnInterfaceTest.java?rev=1675309&view=auto
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/ListenOnInterfaceTest.java (added)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/ListenOnInterfaceTest.java Wed Apr 22 10:06:10 2015
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.portable.events;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.test.event.FireIEvent;
+import org.apache.webbeans.test.event.ListentIEvent;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ListenOnInterfaceTest extends AbstractUnitTest {
+    @Test
+    public void test() {
+        startContainer(ListentIEvent.class, FireIEvent.class);
+        getInstance(FireIEvent.class).doIt();
+        assertEquals(1, getInstance(ListentIEvent.class).getEvents().size());
+    }
+}

Added: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/EventImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/EventImpl.java?rev=1675309&view=auto
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/EventImpl.java (added)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/EventImpl.java Wed Apr 22 10:06:10 2015
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.event;
+
+public class EventImpl implements IEvent {
+}

Added: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/FireIEvent.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/FireIEvent.java?rev=1675309&view=auto
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/FireIEvent.java (added)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/FireIEvent.java Wed Apr 22 10:06:10 2015
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.event;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+
+public class FireIEvent {
+    @Inject
+    private Event<IEvent> eventEvent;
+
+    public void doIt() {
+        eventEvent.fire(new EventImpl());
+    }
+}

Added: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/IEvent.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/IEvent.java?rev=1675309&view=auto
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/IEvent.java (added)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/IEvent.java Wed Apr 22 10:06:10 2015
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.event;
+
+public interface IEvent {
+}

Added: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/ListentIEvent.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/ListentIEvent.java?rev=1675309&view=auto
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/ListentIEvent.java (added)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/event/ListentIEvent.java Wed Apr 22 10:06:10 2015
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.event;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+
+@ApplicationScoped
+public class ListentIEvent {
+    private Collection<IEvent> events = new LinkedList<IEvent>();
+
+    public void listen(@Observes IEvent event) {
+        events.add(event);
+    }
+
+    public Collection<IEvent> getEvents() {
+        return events;
+    }
+}