openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [openwebbeans-meecrowave-examples] 01/01: move Meecrowave examples to separate repo
Date Fri, 29 Jun 2018 07:14:27 GMT
This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans-meecrowave-examples.git

commit c9ab9f326cdd16c2afa3bd949471dda2769acec4
Author: Mark Struberg <struberg@apache.org>
AuthorDate: Fri Jun 29 09:13:00 2018 +0200

    move Meecrowave examples to separate repo
---
 .gitignore                                         |  9 +++
 README.adoc                                        | 12 +++
 pom.xml                                            | 86 ++++++++++++++++++++++
 rest-trivial/pom.xml                               | 15 ++++
 .../java/com/superbiz/jaxrs/HelloEndpoint.java     | 36 +++++++++
 .../com/superbiz/jaxrs/HelloEndpointTest.java      | 51 +++++++++++++
 rest/pom.xml                                       | 15 ++++
 .../java/com/superbiz/configuration/Defaults.java  | 31 ++++++++
 .../superbiz/configuration/DefaultsProducer.java   | 38 ++++++++++
 .../java/com/superbiz/jaxrs/HelloApplication.java  | 28 +++++++
 .../java/com/superbiz/jaxrs/HelloEndpoint.java     | 65 ++++++++++++++++
 .../java/com/superbiz/jaxrs/HelloEndpointTest.java | 52 +++++++++++++
 12 files changed, 438 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100755
index 0000000..b59638f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+target
+.classpath
+.project
+.settings
+.idea
+*.ipr
+*.iml
+*.log
+*~
diff --git a/README.adoc b/README.adoc
new file mode 100644
index 0000000..597fb3d
--- /dev/null
+++ b/README.adoc
@@ -0,0 +1,12 @@
+= Meecrowave Sample
+
+This project shows how to use meecrowave for simple applications.
+
+Here what it provides:
+
+0. A pom.xml with the dependencies for this sample and meecrowave-maven-plugin setup so you
can launch `mvn package meecrowave-run`.
+1. A sample JAX-RS application: in src/main/java/com/superbiz/sample/jaxrs
+2. A test using JAX-RS client API and the meecrowave mono rule (useful when you run multiple
tests) in src/test/java/com/superbiz/sample/jaxrs
+3. in src/main/java/com/superbiz/configuration/Defaults some enrichment of the meecrowave
Cli options for the application.
+
+To use it launch meecrowave main (org.apache.meecrowave.runner.Cli) with option `--app-default-name
foo`.
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..152d160
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache</groupId>
+        <artifactId>apache</artifactId>
+        <version>18</version>
+    </parent>
+
+    <groupId>org.apache.meecrowave</groupId>
+    <artifactId>meecrowave-examples</artifactId>
+    <packaging>pom</packaging>
+    <name>Apache Meecrowave Examples</name>
+    <description>A project showing some of the Apache Meecrowave features.</description>
+
+    <modules>
+        <module>rest-trivial</module>
+        <module>rest</module>
+    </modules>
+
+    <properties>
+        <meecrowave.version>1.2.2-SNAPSHOT</meecrowave.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.meecrowave</groupId>
+            <artifactId>meecrowave-core</artifactId>
+            <version>${meecrowave.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.meecrowave</groupId>
+            <artifactId>meecrowave-junit</artifactId>
+            <version>${meecrowave.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.meecrowave</groupId>
+                <artifactId>meecrowave-maven-plugin</artifactId>
+                <version>${meecrowave.version}</version>
+            </plugin>
+        </plugins>
+    </build>
+
+    <distributionManagement>
+        <repository>
+            <id>localhost</id>
+            <url>file://${basedir}/target/repo/</url>
+        </repository>
+        <snapshotRepository>
+            <id>localhost</id>
+            <url>file://${basedir}/target/snapshot-repo/</url>
+        </snapshotRepository>
+    </distributionManagement>
+</project>
diff --git a/rest-trivial/pom.xml b/rest-trivial/pom.xml
new file mode 100644
index 0000000..addad78
--- /dev/null
+++ b/rest-trivial/pom.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>samples</artifactId>
+        <groupId>org.apache.meecrowave</groupId>
+        <version>1.2.2-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>samples-rest-trivial</artifactId>
+    <name>Meecrowave Samples - REST (trivial)</name>
+
+</project>
\ No newline at end of file
diff --git a/rest-trivial/src/main/java/com/superbiz/jaxrs/HelloEndpoint.java b/rest-trivial/src/main/java/com/superbiz/jaxrs/HelloEndpoint.java
new file mode 100644
index 0000000..09fbcdd
--- /dev/null
+++ b/rest-trivial/src/main/java/com/superbiz/jaxrs/HelloEndpoint.java
@@ -0,0 +1,36 @@
+/*
+ * 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 com.superbiz.jaxrs;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("hello")
+@ApplicationScoped
+public class HelloEndpoint {
+
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public String sayHi() {
+        return "Hello World";
+    }
+}
diff --git a/rest-trivial/src/test/java/junit/com/superbiz/jaxrs/HelloEndpointTest.java b/rest-trivial/src/test/java/junit/com/superbiz/jaxrs/HelloEndpointTest.java
new file mode 100644
index 0000000..0b3f2e1
--- /dev/null
+++ b/rest-trivial/src/test/java/junit/com/superbiz/jaxrs/HelloEndpointTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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 junit.com.superbiz.jaxrs;
+
+import org.apache.meecrowave.Meecrowave;
+import org.apache.meecrowave.junit.MonoMeecrowave;
+import org.apache.meecrowave.testing.ConfigurationInject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(MonoMeecrowave.Runner.class)
+public class HelloEndpointTest {
+
+    @ConfigurationInject
+    private Meecrowave.Builder configuration;
+
+    @Test
+    public void hello() {
+        final Client client = ClientBuilder.newClient();
+        try {
+            assertEquals("Hello World", client.target("http://localhost:" + configuration.getHttpPort())
+                    .path("/hello")
+                    .request(APPLICATION_JSON_TYPE)
+                    .get(String.class));
+        } finally {
+            client.close();
+        }
+    }
+}
diff --git a/rest/pom.xml b/rest/pom.xml
new file mode 100644
index 0000000..0d27b79
--- /dev/null
+++ b/rest/pom.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>samples</artifactId>
+        <groupId>org.apache.meecrowave</groupId>
+        <version>1.2.2-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>samples-rest</artifactId>
+    <name>Meecrowave Samples - REST</name>
+
+</project>
\ No newline at end of file
diff --git a/rest/src/main/java/com/superbiz/configuration/Defaults.java b/rest/src/main/java/com/superbiz/configuration/Defaults.java
new file mode 100644
index 0000000..2053c19
--- /dev/null
+++ b/rest/src/main/java/com/superbiz/configuration/Defaults.java
@@ -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 com.superbiz.configuration;
+
+import org.apache.meecrowave.runner.Cli;
+import org.apache.meecrowave.runner.cli.CliOption;
+
+public class Defaults implements Cli.Options {
+    @CliOption(name = "app-default-name", description = "The name used to say hello if not
set")
+    private String name = "default value";
+
+    public String getName() {
+        return name;
+    }
+}
diff --git a/rest/src/main/java/com/superbiz/configuration/DefaultsProducer.java b/rest/src/main/java/com/superbiz/configuration/DefaultsProducer.java
new file mode 100644
index 0000000..6e40cf0
--- /dev/null
+++ b/rest/src/main/java/com/superbiz/configuration/DefaultsProducer.java
@@ -0,0 +1,38 @@
+/*
+ * 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 com.superbiz.configuration;
+
+import org.apache.meecrowave.Meecrowave;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+@Dependent
+public class DefaultsProducer {
+    @Inject
+    private Meecrowave.Builder builder;
+
+    @Produces
+    @ApplicationScoped
+    public Defaults defaults() {
+        return builder.getExtension(Defaults.class);
+    }
+}
diff --git a/rest/src/main/java/com/superbiz/jaxrs/HelloApplication.java b/rest/src/main/java/com/superbiz/jaxrs/HelloApplication.java
new file mode 100644
index 0000000..813b6b9
--- /dev/null
+++ b/rest/src/main/java/com/superbiz/jaxrs/HelloApplication.java
@@ -0,0 +1,28 @@
+/*
+ * 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 com.superbiz.jaxrs;
+
+import javax.enterprise.context.Dependent;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@Dependent
+@ApplicationPath("api")
+public class HelloApplication extends Application {
+}
diff --git a/rest/src/main/java/com/superbiz/jaxrs/HelloEndpoint.java b/rest/src/main/java/com/superbiz/jaxrs/HelloEndpoint.java
new file mode 100644
index 0000000..3c3fe57
--- /dev/null
+++ b/rest/src/main/java/com/superbiz/jaxrs/HelloEndpoint.java
@@ -0,0 +1,65 @@
+/*
+ * 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 com.superbiz.jaxrs;
+
+import com.superbiz.configuration.Defaults;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+import static java.util.Optional.ofNullable;
+
+@Path("hello")
+@ApplicationScoped
+public class HelloEndpoint {
+    @Inject
+    private Defaults defaults;
+
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public Hello sayHi(@QueryParam("name") final String name) {
+        return new Hello(ofNullable(name)
+                .orElse(defaults.getName()));
+    }
+
+    public static class Hello {
+        private String name;
+
+        public Hello() {
+            // no-op
+        }
+
+        private Hello(final String name) {
+            this.name = name;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(final String name) {
+            this.name = name;
+        }
+    }
+}
diff --git a/rest/src/test/java/com/superbiz/jaxrs/HelloEndpointTest.java b/rest/src/test/java/com/superbiz/jaxrs/HelloEndpointTest.java
new file mode 100644
index 0000000..b8c24ab
--- /dev/null
+++ b/rest/src/test/java/com/superbiz/jaxrs/HelloEndpointTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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 com.superbiz.jaxrs;
+
+import org.apache.meecrowave.Meecrowave;
+import org.apache.meecrowave.junit.MonoMeecrowave;
+import org.apache.meecrowave.testing.ConfigurationInject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(MonoMeecrowave.Runner.class)
+public class HelloEndpointTest {
+    @ConfigurationInject
+    private Meecrowave.Builder configuration;
+
+    @Test
+    public void hello() {
+        final Client client = ClientBuilder.newClient();
+        try {
+            assertEquals("me", client.target("http://localhost:" + configuration.getHttpPort())
+                    .path("api/hello")
+                    .queryParam("name", "me")
+                    .request(APPLICATION_JSON_TYPE)
+                    .get(HelloEndpoint.Hello.class)
+                    .getName());
+        } finally {
+            client.close();
+        }
+    }
+}


Mime
View raw message