diff --git a/apache-meecrowave/pom.xml b/apache-meecrowave/pom.xml new file mode 100644 index 0000000000..cf13aa1c1b --- /dev/null +++ b/apache-meecrowave/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + com.baeldung + apache-meecrowave + 0.0.1 + apache-meecrowave + A sample REST API application with Meecrowave + + + 1.8 + 1.8 + + + + + org.apache.meecrowave + meecrowave-core + 1.2.1 + + + + org.apache.meecrowave + meecrowave-jpa + 1.2.1 + + + + com.squareup.okhttp3 + okhttp + 3.10.0 + + + org.apache.meecrowave + meecrowave-junit + 1.2.0 + test + + + + junit + junit + 4.10 + test + + + + + + + org.apache.meecrowave + meecrowave-maven-plugin + 1.2.1 + + + + \ No newline at end of file diff --git a/apache-meecrowave/src/main/java/com/baeldung/meecrowave/Article.java b/apache-meecrowave/src/main/java/com/baeldung/meecrowave/Article.java new file mode 100644 index 0000000000..7925e8ff99 --- /dev/null +++ b/apache-meecrowave/src/main/java/com/baeldung/meecrowave/Article.java @@ -0,0 +1,30 @@ +package com.baeldung.meecrowave; + +public class Article { + private String name; + private String author; + + public Article() { + } + + public Article(String name, String author) { + this.author = author; + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } +} \ No newline at end of file diff --git a/apache-meecrowave/src/main/java/com/baeldung/meecrowave/ArticleEndpoints.java b/apache-meecrowave/src/main/java/com/baeldung/meecrowave/ArticleEndpoints.java new file mode 100644 index 0000000000..6cb7012c64 --- /dev/null +++ b/apache-meecrowave/src/main/java/com/baeldung/meecrowave/ArticleEndpoints.java @@ -0,0 +1,32 @@ +package com.baeldung.meecrowave; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +@RequestScoped +@Path("article") +public class ArticleEndpoints { + + @Inject + ArticleService articleService; + + @GET + public Response getArticle() { + return Response.ok() + .entity(new Article("name", "author")) + .build(); + + } + + @POST + public Response createArticle(Article article) { + return Response.status(Status.CREATED) + .entity(articleService.createArticle(article)) + .build(); + } +} \ No newline at end of file diff --git a/apache-meecrowave/src/main/java/com/baeldung/meecrowave/ArticleService.java b/apache-meecrowave/src/main/java/com/baeldung/meecrowave/ArticleService.java new file mode 100644 index 0000000000..7bd6b87345 --- /dev/null +++ b/apache-meecrowave/src/main/java/com/baeldung/meecrowave/ArticleService.java @@ -0,0 +1,10 @@ +package com.baeldung.meecrowave; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class ArticleService { + public Article createArticle(Article article) { + return article; + } +} diff --git a/apache-meecrowave/src/main/java/com/baeldung/meecrowave/Server.java b/apache-meecrowave/src/main/java/com/baeldung/meecrowave/Server.java new file mode 100644 index 0000000000..2aa7d0556f --- /dev/null +++ b/apache-meecrowave/src/main/java/com/baeldung/meecrowave/Server.java @@ -0,0 +1,16 @@ +package com.baeldung.meecrowave; + +import org.apache.meecrowave.Meecrowave; + +public class Server { + public static void main(String[] args) { + final Meecrowave.Builder builder = new Meecrowave.Builder(); + builder.setScanningPackageIncludes("com.baeldung.meecrowave"); + builder.setJaxrsMapping("/api/*"); + builder.setJsonpPrettify(true); + + try (Meecrowave meecrowave = new Meecrowave(builder)) { + meecrowave.bake().await(); + } + } +} diff --git a/apache-meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsTest.java b/apache-meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsTest.java new file mode 100644 index 0000000000..0dc9773490 --- /dev/null +++ b/apache-meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsTest.java @@ -0,0 +1,41 @@ +package com.baeldung.meecrowave; + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.apache.meecrowave.Meecrowave; +import org.apache.meecrowave.junit.MonoMeecrowave; +import org.apache.meecrowave.testing.ConfigurationInject; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +@RunWith(MonoMeecrowave.Runner.class) +public class ArticleEndpointsTest { + + @ConfigurationInject + private Meecrowave.Builder config; + private static OkHttpClient client; + + @BeforeClass + public static void setup() { + client = new OkHttpClient(); + } + + @Test + public void whenRetunedArticle_thenCorrect() throws IOException { + final String base = "http://localhost:"+config.getHttpPort(); + + Request request = new Request.Builder() + .url(base+"/article") + .build(); + Response response = client.newCall(request).execute(); + assertEquals(200, response.code()); + } +} diff --git a/meecrowave/pom.xml b/meecrowave/pom.xml new file mode 100644 index 0000000000..cf13aa1c1b --- /dev/null +++ b/meecrowave/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + com.baeldung + apache-meecrowave + 0.0.1 + apache-meecrowave + A sample REST API application with Meecrowave + + + 1.8 + 1.8 + + + + + org.apache.meecrowave + meecrowave-core + 1.2.1 + + + + org.apache.meecrowave + meecrowave-jpa + 1.2.1 + + + + com.squareup.okhttp3 + okhttp + 3.10.0 + + + org.apache.meecrowave + meecrowave-junit + 1.2.0 + test + + + + junit + junit + 4.10 + test + + + + + + + org.apache.meecrowave + meecrowave-maven-plugin + 1.2.1 + + + + \ No newline at end of file diff --git a/meecrowave/src/main/java/com/baeldung/meecrowave/Article.java b/meecrowave/src/main/java/com/baeldung/meecrowave/Article.java new file mode 100644 index 0000000000..7925e8ff99 --- /dev/null +++ b/meecrowave/src/main/java/com/baeldung/meecrowave/Article.java @@ -0,0 +1,30 @@ +package com.baeldung.meecrowave; + +public class Article { + private String name; + private String author; + + public Article() { + } + + public Article(String name, String author) { + this.author = author; + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } +} \ No newline at end of file diff --git a/meecrowave/src/main/java/com/baeldung/meecrowave/ArticleEndpoints.java b/meecrowave/src/main/java/com/baeldung/meecrowave/ArticleEndpoints.java new file mode 100644 index 0000000000..6cb7012c64 --- /dev/null +++ b/meecrowave/src/main/java/com/baeldung/meecrowave/ArticleEndpoints.java @@ -0,0 +1,32 @@ +package com.baeldung.meecrowave; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +@RequestScoped +@Path("article") +public class ArticleEndpoints { + + @Inject + ArticleService articleService; + + @GET + public Response getArticle() { + return Response.ok() + .entity(new Article("name", "author")) + .build(); + + } + + @POST + public Response createArticle(Article article) { + return Response.status(Status.CREATED) + .entity(articleService.createArticle(article)) + .build(); + } +} \ No newline at end of file diff --git a/meecrowave/src/main/java/com/baeldung/meecrowave/ArticleService.java b/meecrowave/src/main/java/com/baeldung/meecrowave/ArticleService.java new file mode 100644 index 0000000000..7bd6b87345 --- /dev/null +++ b/meecrowave/src/main/java/com/baeldung/meecrowave/ArticleService.java @@ -0,0 +1,10 @@ +package com.baeldung.meecrowave; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class ArticleService { + public Article createArticle(Article article) { + return article; + } +} diff --git a/meecrowave/src/main/java/com/baeldung/meecrowave/Server.java b/meecrowave/src/main/java/com/baeldung/meecrowave/Server.java new file mode 100644 index 0000000000..2aa7d0556f --- /dev/null +++ b/meecrowave/src/main/java/com/baeldung/meecrowave/Server.java @@ -0,0 +1,16 @@ +package com.baeldung.meecrowave; + +import org.apache.meecrowave.Meecrowave; + +public class Server { + public static void main(String[] args) { + final Meecrowave.Builder builder = new Meecrowave.Builder(); + builder.setScanningPackageIncludes("com.baeldung.meecrowave"); + builder.setJaxrsMapping("/api/*"); + builder.setJsonpPrettify(true); + + try (Meecrowave meecrowave = new Meecrowave(builder)) { + meecrowave.bake().await(); + } + } +} diff --git a/meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsTest.java b/meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsTest.java new file mode 100644 index 0000000000..0dc9773490 --- /dev/null +++ b/meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsTest.java @@ -0,0 +1,41 @@ +package com.baeldung.meecrowave; + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.apache.meecrowave.Meecrowave; +import org.apache.meecrowave.junit.MonoMeecrowave; +import org.apache.meecrowave.testing.ConfigurationInject; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +@RunWith(MonoMeecrowave.Runner.class) +public class ArticleEndpointsTest { + + @ConfigurationInject + private Meecrowave.Builder config; + private static OkHttpClient client; + + @BeforeClass + public static void setup() { + client = new OkHttpClient(); + } + + @Test + public void whenRetunedArticle_thenCorrect() throws IOException { + final String base = "http://localhost:"+config.getHttpPort(); + + Request request = new Request.Builder() + .url(base+"/article") + .build(); + Response response = client.newCall(request).execute(); + assertEquals(200, response.code()); + } +} diff --git a/pom.xml b/pom.xml index 51a762a888..728611a8a3 100644 --- a/pom.xml +++ b/pom.xml @@ -149,7 +149,7 @@ spring-boot-persistence spring-boot-security spring-boot-mvc - spring-boot-logging-log4j2 + spring-boot-logging-log4j2 spring-cloud-data-flow spring-cloud spring-core @@ -267,11 +267,12 @@ java-spi performance-tests twilio - spring-boot-ctx-fluent + spring-boot-ctx-fluent java-ee-8-security-api spring-webflux-amqp antlr maven-archetype + apache-meecrowave