From 813dbd43a9d44000c73fc3825a777f1d75abd653 Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Sat, 8 Dec 2018 14:11:37 +0100 Subject: [PATCH] :dizzy: Adding CDI API package Signed-off-by: Matthias Wessendorf --- api/pom.xml | 3 - cdi/pom.xml | 103 ++++++++++++++++++ .../java/io/cloudevents/cdi/EventType.java | 29 +++++ .../cloudevents/cdi/EventTypeQualifier.java | 32 ++++++ cdi/src/main/resources/META-INF/beans.xml | 0 .../java/io/cloudevents/AbstractTestBase.java | 32 ++++++ .../java/io/cloudevents/CloudEventTest.java | 47 ++++++++ .../java/io/cloudevents/MockProvider.java | 33 ++++++ .../io/cloudevents/beans/MyCustomEvent.java | 19 ++++ .../java/io/cloudevents/beans/Observer.java | 35 ++++++ .../java/io/cloudevents/beans/Receiver.java | 21 ++++ .../java/io/cloudevents/beans/Router.java | 45 ++++++++ http/vertx/pom.xml | 3 - pom.xml | 7 ++ 14 files changed, 403 insertions(+), 6 deletions(-) create mode 100644 cdi/pom.xml create mode 100644 cdi/src/main/java/io/cloudevents/cdi/EventType.java create mode 100644 cdi/src/main/java/io/cloudevents/cdi/EventTypeQualifier.java create mode 100644 cdi/src/main/resources/META-INF/beans.xml create mode 100644 cdi/src/test/java/io/cloudevents/AbstractTestBase.java create mode 100644 cdi/src/test/java/io/cloudevents/CloudEventTest.java create mode 100644 cdi/src/test/java/io/cloudevents/MockProvider.java create mode 100644 cdi/src/test/java/io/cloudevents/beans/MyCustomEvent.java create mode 100644 cdi/src/test/java/io/cloudevents/beans/Observer.java create mode 100644 cdi/src/test/java/io/cloudevents/beans/Receiver.java create mode 100644 cdi/src/test/java/io/cloudevents/beans/Router.java diff --git a/api/pom.xml b/api/pom.xml index be85acd4..35c5194f 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -61,9 +61,6 @@ 2.9.6 - 1.8 - 1.8 - UTF-8 diff --git a/cdi/pom.xml b/cdi/pom.xml new file mode 100644 index 00000000..5425f177 --- /dev/null +++ b/cdi/pom.xml @@ -0,0 +1,103 @@ + + + + 4.0.0 + + + io.cloudevents + cloudevents-parent + 0.1.1-SNAPSHOT + ../ + + + cdi + CloudEvents - CDI + jar + + + + + org.jboss.arquillian + arquillian-bom + 1.1.11.Final + import + pom + + + + + + + + javax + javaee-api + 7.0 + provided + + + + io.cloudevents + cloudevents-api + ${project.version} + provided + + + junit + junit + 4.12 + test + + + + + org.mockito + mockito-core + 2.19.0 + test + + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + + org.jboss.arquillian.container + arquillian-weld-ee-embedded-1.1 + 1.0.0.Final + test + + + + org.jboss.weld + weld-core + 2.3.5.Final + test + + + + org.assertj + assertj-core + 3.6.1 + test + + + + + + \ No newline at end of file diff --git a/cdi/src/main/java/io/cloudevents/cdi/EventType.java b/cdi/src/main/java/io/cloudevents/cdi/EventType.java new file mode 100644 index 00000000..f4f96775 --- /dev/null +++ b/cdi/src/main/java/io/cloudevents/cdi/EventType.java @@ -0,0 +1,29 @@ +/** + * Copyright 2018 The CloudEvents Authors + * + * Licensed 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 io.cloudevents.cdi; + +import javax.inject.Qualifier; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Qualifier +@Target({ ElementType.PARAMETER, ElementType.FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface EventType { + String name() default ""; +} diff --git a/cdi/src/main/java/io/cloudevents/cdi/EventTypeQualifier.java b/cdi/src/main/java/io/cloudevents/cdi/EventTypeQualifier.java new file mode 100644 index 00000000..6164c8aa --- /dev/null +++ b/cdi/src/main/java/io/cloudevents/cdi/EventTypeQualifier.java @@ -0,0 +1,32 @@ +/** + * Copyright 2018 The CloudEvents Authors + * + * Licensed 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 io.cloudevents.cdi; + +import javax.enterprise.util.AnnotationLiteral; + +public class EventTypeQualifier extends AnnotationLiteral implements EventType { + + private static final long serialVersionUID = 1L; + private final String eventName; + + public EventTypeQualifier(final String name) { + eventName=name; + } + + public String name() { + return eventName; + } +} diff --git a/cdi/src/main/resources/META-INF/beans.xml b/cdi/src/main/resources/META-INF/beans.xml new file mode 100644 index 00000000..e69de29b diff --git a/cdi/src/test/java/io/cloudevents/AbstractTestBase.java b/cdi/src/test/java/io/cloudevents/AbstractTestBase.java new file mode 100644 index 00000000..e4b12de4 --- /dev/null +++ b/cdi/src/test/java/io/cloudevents/AbstractTestBase.java @@ -0,0 +1,32 @@ +/** + * Copyright 2018 The CloudEvents Authors + * + * Licensed 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 io.cloudevents; + +import io.cloudevents.impl.DefaultCloudEventImpl; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; + +public abstract class AbstractTestBase { + + public static JavaArchive createFrameworkDeployment() { + + return ShrinkWrap.create(JavaArchive.class) + .addPackage(DefaultCloudEventImpl.class.getPackage()) + .addPackage(MockProvider.class.getPackage()) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } +} diff --git a/cdi/src/test/java/io/cloudevents/CloudEventTest.java b/cdi/src/test/java/io/cloudevents/CloudEventTest.java new file mode 100644 index 00000000..af073a52 --- /dev/null +++ b/cdi/src/test/java/io/cloudevents/CloudEventTest.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 The CloudEvents Authors + * + * Licensed 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 io.cloudevents; + +import io.cloudevents.beans.Receiver; +import io.cloudevents.beans.Router; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import javax.inject.Inject; + +@RunWith(Arquillian.class) +public class CloudEventTest extends AbstractTestBase { + + + @Inject + private Router router; + + @Deployment + public static JavaArchive createDeployment() { + return AbstractTestBase.createFrameworkDeployment() + .addPackage(Router.class.getPackage()); + } + + @Test + public void testDispatch(final Receiver receiver) throws Exception { + router.routeMe(); + Mockito.verify(receiver, Mockito.times(1)).ack(); + } +} diff --git a/cdi/src/test/java/io/cloudevents/MockProvider.java b/cdi/src/test/java/io/cloudevents/MockProvider.java new file mode 100644 index 00000000..b6a6a6f9 --- /dev/null +++ b/cdi/src/test/java/io/cloudevents/MockProvider.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 The CloudEvents Authors + * + * Licensed 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 io.cloudevents; + +import io.cloudevents.beans.Receiver; +import org.mockito.Mockito; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; + +@ApplicationScoped +public class MockProvider { + + private Receiver receiver = Mockito.mock(Receiver.class); + + @Produces + public Receiver receiver() { + return receiver; + } +} \ No newline at end of file diff --git a/cdi/src/test/java/io/cloudevents/beans/MyCustomEvent.java b/cdi/src/test/java/io/cloudevents/beans/MyCustomEvent.java new file mode 100644 index 00000000..c4fde003 --- /dev/null +++ b/cdi/src/test/java/io/cloudevents/beans/MyCustomEvent.java @@ -0,0 +1,19 @@ +/** + * Copyright 2018 The CloudEvents Authors + * + * Licensed 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 io.cloudevents.beans; + +public class MyCustomEvent { +} diff --git a/cdi/src/test/java/io/cloudevents/beans/Observer.java b/cdi/src/test/java/io/cloudevents/beans/Observer.java new file mode 100644 index 00000000..46b3fc45 --- /dev/null +++ b/cdi/src/test/java/io/cloudevents/beans/Observer.java @@ -0,0 +1,35 @@ +/** + * Copyright 2018 The CloudEvents Authors + * + * Licensed 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 io.cloudevents.beans; + +import io.cloudevents.CloudEvent; +import io.cloudevents.cdi.EventType; + +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +public class Observer { + + @Inject + private Receiver receiver; + + public void receiveCloudEvent(@Observes @EventType(name = "Cloud.Storage.Item.Created") CloudEvent cloudEvent) { + + receiver.ack(); + + } + +} diff --git a/cdi/src/test/java/io/cloudevents/beans/Receiver.java b/cdi/src/test/java/io/cloudevents/beans/Receiver.java new file mode 100644 index 00000000..47f2c5c9 --- /dev/null +++ b/cdi/src/test/java/io/cloudevents/beans/Receiver.java @@ -0,0 +1,21 @@ +/** + * Copyright 2018 The CloudEvents Authors + * + * Licensed 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 io.cloudevents.beans; + +public interface Receiver { + + void ack(); +} diff --git a/cdi/src/test/java/io/cloudevents/beans/Router.java b/cdi/src/test/java/io/cloudevents/beans/Router.java new file mode 100644 index 00000000..12e17802 --- /dev/null +++ b/cdi/src/test/java/io/cloudevents/beans/Router.java @@ -0,0 +1,45 @@ +/** + * Copyright 2018 The CloudEvents Authors + * + * Licensed 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 io.cloudevents.beans; + +import io.cloudevents.CloudEvent; +import io.cloudevents.CloudEventBuilder; +import io.cloudevents.cdi.EventTypeQualifier; + +import javax.enterprise.event.Event; +import javax.inject.Inject; + +import java.net.URI; +import java.util.UUID; + +public class Router { + + @Inject + private Event> cloudEvent; + + public void routeMe() throws Exception { + + CloudEvent event = new CloudEventBuilder() + .type("Cloud.Storage.Item.Created") + .source(new URI("/trigger")) + .id(UUID.randomUUID().toString()) + .build(); + + cloudEvent.select( + new EventTypeQualifier("Cloud.Storage.Item.Created")) + .fire(event); + } +} diff --git a/http/vertx/pom.xml b/http/vertx/pom.xml index 437dbdbd..4086f29e 100644 --- a/http/vertx/pom.xml +++ b/http/vertx/pom.xml @@ -113,9 +113,6 @@ 3.6.0 2.9.6 2.22.0 - 1.8 - 1.8 - UTF-8 3.11.0 5.3.2 diff --git a/pom.xml b/pom.xml index 424779d8..969612d8 100644 --- a/pom.xml +++ b/pom.xml @@ -57,8 +57,15 @@ api + cdi http/vertx + + 1.8 + 1.8 + UTF-8 + +