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 2017/07/02 14:46:59 UTC

svn commit: r1800565 - /openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java

Author: rmannibucau
Date: Sun Jul  2 14:46:58 2017
New Revision: 1800565

URL: http://svn.apache.org/viewvc?rev=1800565&view=rev
Log:
adding OctectStreamMediaTypeTest for Mark

Added:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java
      - copied, changed from r1800462, openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/ContextInProxiedInstancesTest.java

Copied: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java (from r1800462, openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/ContextInProxiedInstancesTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java?p2=openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java&p1=openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/ContextInProxiedInstancesTest.java&r1=1800462&r2=1800565&rev=1800565&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/ContextInProxiedInstancesTest.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java Sun Jul  2 14:46:58 2017
@@ -22,80 +22,75 @@ import org.apache.tomcat.util.http.fileu
 import org.junit.Test;
 
 import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.Initialized;
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.spi.CDI;
-import javax.servlet.ServletContext;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 
 import static org.junit.Assert.assertEquals;
 
-public class ContextInProxiedInstancesTest {
+public class OctectStreamMediaTypeTest {
     @Test
     public void fields() throws IOException {
         try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder()
                 .randomHttpPort()
-                .includePackages(ContextInProxiedInstancesTest.class.getName())).bake()) {
-            // proxies can use @Context
-            try (final InputStream stream = new URL("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/app").openStream()) {
-                assertEquals("app", Streams.asString(stream, "UTF-8"));
+                .includePackages(OctectStreamMediaTypeTest.class.getName())).bake()) {
+            try (final InputStream stream = new URL(
+                    "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/OctectStreamMediaTypeTest/response").openStream()) {
+                assertEquals("resp", Streams.asString(stream, "UTF-8"));
             }
-            try (final InputStream stream = new URL("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/req").openStream()) {
-                assertEquals("req", Streams.asString(stream, "UTF-8"));
+            try (final InputStream stream = new URL(
+                    "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/OctectStreamMediaTypeTest/streaming").openStream()) {
+                assertEquals("stream", Streams.asString(stream, "UTF-8"));
             }
-            // not proxied can also
-            try (final InputStream stream = new URL("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/dep").openStream()) {
-                assertEquals("dep", Streams.asString(stream, "UTF-8"));
+            try (final InputStream stream = new URL(
+                    "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/OctectStreamMediaTypeTest/string").openStream()) {
+                assertEquals("string", Streams.asString(stream, "UTF-8"));
             }
-            assertEquals(Dep.class, CDI.current().select(Dep.class).get().getClass()); // ensure it is not proxied but injection works (thanks CXF)
+            /* too ambiguous to have it working, you can add it in ignored list of johnzon provider if you want to handle it particularly
+            try (final InputStream stream = new URL(
+                    "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/OctectStreamMediaTypeTest/bytes").openStream()) {
+                assertEquals("bytes", Streams.asString(stream, "UTF-8"));
+            }
+            */
         }
     }
 
-    @Path("app")
+    @Path("OctectStreamMediaTypeTest")
     @ApplicationScoped
     public static class App {
-        @Context
-        private UriInfo uri;
-
-        public void init(@Observes @Initialized(ApplicationScoped.class) final ServletContext sc) {
-            // init without a Message
+        @GET
+        @Path("response")
+        @Produces(MediaType.APPLICATION_OCTET_STREAM)
+        public Response getResponse() {
+            return Response.ok("resp").build();
         }
 
         @GET
-        public String get() {
-            return uri.getPath();
+        @Path("streaming")
+        @Produces(MediaType.APPLICATION_OCTET_STREAM)
+        public StreamingOutput getStreamingOutput() {
+            return output -> output.write("stream".getBytes(StandardCharsets.UTF_8));
         }
-    }
-
-    @Path("req")
-    @RequestScoped
-    public static class Req {
-        @Context
-        private UriInfo uri;
 
         @GET
-        public String get() {
-            return uri.getPath();
+        @Path("string")
+        @Produces(MediaType.APPLICATION_OCTET_STREAM)
+        public String getString() {
+            return "string";
         }
-    }
-
-    @Path("dep")
-    @Dependent
-    public static class Dep {
-        @Context
-        private UriInfo uri;
 
         @GET
-        public String get() {
-            return uri.getPath();
+        @Path("bytes")
+        @Produces(MediaType.APPLICATION_OCTET_STREAM)
+        public byte[] getBytes() {
+            return "bytes".getBytes(StandardCharsets.UTF_8);
         }
     }
 }