MEECROWAVE-200 test for johnzon buffer handling


git-svn-id: https://svn.apache.org/repos/asf/openwebbeans/meecrowave/trunk@1862127 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/meecrowave-core/src/test/java/org/apache/meecrowave/MeecrowaveTest.java b/meecrowave-core/src/test/java/org/apache/meecrowave/MeecrowaveTest.java
index ea31993..a652d76 100644
--- a/meecrowave-core/src/test/java/org/apache/meecrowave/MeecrowaveTest.java
+++ b/meecrowave-core/src/test/java/org/apache/meecrowave/MeecrowaveTest.java
@@ -26,6 +26,7 @@
 import org.superbiz.app.Endpoint;
 import org.superbiz.app.InterfaceApi;
 import org.superbiz.app.RsApp;
+import org.superbiz.app.TestJsonEndpoint;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -118,7 +119,7 @@
             assertEquals("simplefalse", slurp(new URL("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/api/test")));
             assertEquals("simplefiltertrue", slurp(new URL("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/filter")));
             assertEquals(
-                    "sci:" + Bounced.class.getName() + Endpoint.class.getName() + InterfaceApi.class.getName() + RsApp.class.getName(),
+                    "sci:" + Bounced.class.getName() + Endpoint.class.getName() + InterfaceApi.class.getName() + RsApp.class.getName() + TestJsonEndpoint.class.getName(),
                     slurp(new URL("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/sci")));
         } catch (final IOException e) {
             fail(e.getMessage());
diff --git a/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/DebugJohnzonBufferStrategy.java b/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/DebugJohnzonBufferStrategy.java
new file mode 100644
index 0000000..f5e107d
--- /dev/null
+++ b/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/DebugJohnzonBufferStrategy.java
@@ -0,0 +1,31 @@
+package org.apache.meecrowave.johnzon;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.johnzon.core.BufferStrategy;
+import org.apache.johnzon.core.BufferStrategyFactory;
+
+public class DebugJohnzonBufferStrategy implements BufferStrategy {
+
+    private static AtomicInteger counter = new AtomicInteger(0);
+    private BufferStrategy delegate;
+
+    public DebugJohnzonBufferStrategy() {
+        counter.incrementAndGet();
+        delegate = BufferStrategyFactory.valueOf("BY_INSTANCE");
+    }
+
+
+    public static int getCounter() {
+        return counter.get();
+    }
+
+    public static void resetCounter() {
+        counter.set(0);
+    }
+
+    @Override
+    public BufferProvider<char[]> newCharProvider(int size) {
+        return delegate.newCharProvider(size);
+    }
+}
diff --git a/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/JohnzonBufferTest.java b/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/JohnzonBufferTest.java
new file mode 100644
index 0000000..4b709a3
--- /dev/null
+++ b/meecrowave-core/src/test/java/org/apache/meecrowave/johnzon/JohnzonBufferTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.meecrowave.johnzon;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.meecrowave.Meecrowave;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class JohnzonBufferTest {
+    @Test
+    public void test() {
+        DebugJohnzonBufferStrategy.resetCounter();
+        try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder()
+                .randomHttpPort()
+                .withJsonpBufferStrategy(DebugJohnzonBufferStrategy.class.getName())
+                .includePackages("org.superbiz.app.TestJsonEndpoint")).bake()) {
+            final Client client = ClientBuilder.newClient();
+            try {
+                String jsonResponse = client
+                        .target("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/testjsonendpoint/book")
+                        .request(MediaType.APPLICATION_JSON)
+                        .get(String.class);
+                assertEquals("{\"isbn\":\"dummyisbn\"}", jsonResponse);
+                //X TODO work in progress! assertEquals(1, DebugJohnzonBufferStrategy.getCounter());
+            } finally {
+                client.close();
+            }
+        }
+    }
+}
diff --git a/meecrowave-core/src/test/java/org/superbiz/app/TestJsonEndpoint.java b/meecrowave-core/src/test/java/org/superbiz/app/TestJsonEndpoint.java
new file mode 100644
index 0000000..e21b095
--- /dev/null
+++ b/meecrowave-core/src/test/java/org/superbiz/app/TestJsonEndpoint.java
@@ -0,0 +1,37 @@
+package org.superbiz.app;
+
+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;
+
+@ApplicationScoped
+@Path("/testjsonendpoint")
+public class TestJsonEndpoint {
+
+
+    @GET
+    @Path("book")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Book getBook() {
+        return new Book("dummyisbn");
+    }
+
+
+    public static class Book {
+        private String isbn;
+
+        public Book(String isbn) {
+            this.isbn = isbn;
+        }
+
+        public String getIsbn() {
+            return isbn;
+        }
+
+        public void setIsbn(String isbn) {
+            this.isbn = isbn;
+        }
+    }
+}
diff --git a/pom.xml b/pom.xml
index aec9d63..c745d05 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,7 +53,7 @@
     <tomcat.version>9.0.21</tomcat.version>
     <openwebbeans.version>2.0.11</openwebbeans.version>
     <cxf.version>3.3.2</cxf.version>
-    <johnzon.version>1.1.12</johnzon.version>
+    <johnzon.version>1.1.13-SNAPSHOT</johnzon.version>
     <log4j2.version>2.11.2</log4j2.version>
     <deltaspike.version>1.8.2</deltaspike.version>
     <jaxb.version>2.2.11</jaxb.version>