[jackson-jaxrs-providers] 117/162: Refactoring unit tests to try to add smoke tests for customized jackson provider impls from jax-rs packages like resteasy
Timo Aaltonen
tjaalton at moszumanska.debian.org
Mon Sep 8 22:16:34 UTC 2014
This is an automated email from the git hooks/post-receive script.
tjaalton pushed a commit to branch master
in repository jackson-jaxrs-providers.
commit 9891d9fc806f923c9b89bfdaec595d7d5031e405
Author: Tatu Saloranta <tatu.saloranta at iki.fi>
Date: Thu Jan 30 20:23:24 2014 -0800
Refactoring unit tests to try to add smoke tests for customized jackson provider impls from jax-rs packages like resteasy
---
.../jackson/jaxrs/json/JaxrsTestBase.java | 51 ---------
.../jackson/jaxrs/json/ResourceTestBase.java | 48 --------
.../jackson/jaxrs/json/dw/ResourceTestBase.java | 122 +++++++++++++++++++++
...leEndpoint.java => SimpleEndpointTestBase.java} | 8 +-
...ations.java => WriteModificationsTestBase.java} | 7 +-
.../jaxrs/json/jersey/SimpleEndpointTest.java | 11 ++
.../jaxrs/json/jersey/WriteModificationsTest.java | 11 ++
7 files changed, 151 insertions(+), 107 deletions(-)
diff --git a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/JaxrsTestBase.java b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/JaxrsTestBase.java
index b7527cb..054c6b9 100644
--- a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/JaxrsTestBase.java
+++ b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/JaxrsTestBase.java
@@ -3,22 +3,8 @@ package com.fasterxml.jackson.jaxrs.json;
import java.io.IOException;
import java.util.*;
-import javax.servlet.DispatcherType;
-import javax.servlet.Filter;
-
import org.junit.Assert;
-
-
-// JAX-RS (jersey), Jetty stuff:
-import javax.ws.rs.core.Application;
-
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.ContextHandlerCollection;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-
-import com.sun.jersey.spi.container.servlet.ServletContainer;
import com.fasterxml.jackson.core.*;
public abstract class JaxrsTestBase
@@ -26,43 +12,6 @@ public abstract class JaxrsTestBase
{
/*
/**********************************************************
- /* Starting actual JAX-RS container
- /**********************************************************
- */
-
- protected Server startServer(int port, Class<? extends Application> appClass)
- {
- return startServer(port, appClass, null);
- }
-
- protected Server startServer(int port, Class<? extends Application> appClass,
- Class<? extends Filter> filterClass)
- {
- Server server = new Server(port);
- final ContextHandlerCollection contexts = new ContextHandlerCollection();
- server.setHandler(contexts);
- ServletHolder jaxrs = new ServletHolder(ServletContainer.class);
- jaxrs.setInitParameter("javax.ws.rs.Application", appClass.getName());
- final ServletContextHandler mainHandler = new ServletContextHandler(contexts, "/", true, false);
- mainHandler.addServlet(jaxrs, "/*");
-
- if (filterClass != null) {
- mainHandler.addFilter(filterClass, "/*", java.util.EnumSet.allOf(DispatcherType.class));
- }
-
- server.setHandler(mainHandler);
- try {
- server.start();
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return server;
- }
-
- /*
- /**********************************************************
/* Additional assertion methods
/**********************************************************
*/
diff --git a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/ResourceTestBase.java b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/ResourceTestBase.java
deleted file mode 100644
index df2168c..0000000
--- a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/ResourceTestBase.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.fasterxml.jackson.jaxrs.json;
-
-import java.io.*;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.ws.rs.core.Application;
-
-public class ResourceTestBase extends JaxrsTestBase
-{
- protected static abstract class JsonApplication extends Application
- {
- protected final Object _resource;
-
- protected JsonApplication(Object r) { _resource = r; }
-
- @Override
- public Set<Object> getSingletons() {
- HashSet<Object> singletons = new HashSet<Object>();
- singletons.add(new JacksonJsonProvider());
- singletons.add(_resource);
- return singletons;
- }
- }
-
- protected String aposToQuotes(String json) {
- return json.replace("'", "\"");
- }
-
- protected String readUTF8(InputStream in) throws IOException
- {
- return new String(readAll(in), "UTF-8");
- }
-
- protected byte[] readAll(InputStream in) throws IOException
- {
- ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
- byte[] buffer = new byte[500];
- int count;
-
- while ((count = in.read(buffer)) > 0) {
- bytes.write(buffer, 0, count);
- }
- in.close();
- return bytes.toByteArray();
- }
-}
diff --git a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/ResourceTestBase.java b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/ResourceTestBase.java
new file mode 100644
index 0000000..2705f92
--- /dev/null
+++ b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/ResourceTestBase.java
@@ -0,0 +1,122 @@
+package com.fasterxml.jackson.jaxrs.json.dw;
+
+import java.io.*;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.DispatcherType;
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+import javax.ws.rs.core.Application;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.ContextHandlerCollection;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import com.fasterxml.jackson.jaxrs.json.JaxrsTestBase;
+
+/**
+ * Intermediate base for tests that run actual full JAX-RS resource.
+ */
+public abstract class ResourceTestBase extends JaxrsTestBase
+{
+ protected static abstract class JsonApplication extends Application
+ {
+ protected final Object _jsonProvider;
+ protected final Object _resource;
+
+ protected JsonApplication(Object jsonProvider, Object resource) {
+ _jsonProvider = jsonProvider;
+ _resource = resource;
+ }
+
+ @Override
+ public Set<Object> getSingletons() {
+ HashSet<Object> singletons = new HashSet<Object>();
+ singletons.add(_jsonProvider);
+ singletons.add(_resource);
+ return singletons;
+ }
+ }
+
+ protected static abstract class JsonApplicationWithJackson extends JsonApplication
+ {
+ public JsonApplicationWithJackson(Object resource) {
+ super(new JacksonJsonProvider(), resource);
+ }
+ }
+
+ /*
+ /**********************************************************
+ /* Abstract and overridable config methods
+ /**********************************************************
+ */
+
+ protected abstract Class<? extends Servlet> servletContainerClass();
+
+ /*
+ /**********************************************************
+ /* Starting actual JAX-RS container
+ /**********************************************************
+ */
+
+ protected Server startServer(int port, Class<? extends Application> appClass) {
+ return startServer(port, appClass, null);
+ }
+
+ protected Server startServer(int port, Class<? extends Application> appClass,
+ Class<? extends Filter> filterClass)
+ {
+ Server server = new Server(port);
+ final ContextHandlerCollection contexts = new ContextHandlerCollection();
+ server.setHandler(contexts);
+ ServletHolder jaxrs = new ServletHolder(servletContainerClass());
+ jaxrs.setInitParameter("javax.ws.rs.Application", appClass.getName());
+ final ServletContextHandler mainHandler = new ServletContextHandler(contexts, "/", true, false);
+ mainHandler.addServlet(jaxrs, "/*");
+
+ if (filterClass != null) {
+ mainHandler.addFilter(filterClass, "/*", java.util.EnumSet.allOf(DispatcherType.class));
+ }
+
+ server.setHandler(mainHandler);
+ try {
+ server.start();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return server;
+ }
+
+ /*
+ /**********************************************************
+ /* Other helper methods
+ /**********************************************************
+ */
+
+ protected String aposToQuotes(String json) {
+ return json.replace("'", "\"");
+ }
+
+ protected String readUTF8(InputStream in) throws IOException
+ {
+ return new String(readAll(in), "UTF-8");
+ }
+
+ protected byte[] readAll(InputStream in) throws IOException
+ {
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
+ byte[] buffer = new byte[500];
+ int count;
+
+ while ((count = in.read(buffer)) > 0) {
+ bytes.write(buffer, 0, count);
+ }
+ in.close();
+ return bytes.toByteArray();
+ }
+}
diff --git a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/TestSimpleEndpoint.java b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/SimpleEndpointTestBase.java
similarity index 95%
rename from json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/TestSimpleEndpoint.java
rename to json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/SimpleEndpointTestBase.java
index 83c2c5e..76606d7 100644
--- a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/TestSimpleEndpoint.java
+++ b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/SimpleEndpointTestBase.java
@@ -12,9 +12,9 @@ import org.eclipse.jetty.server.Server;
import org.junit.Assert;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.jaxrs.json.ResourceTestBase;
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
-public class TestSimpleEndpoint extends ResourceTestBase
+public abstract class SimpleEndpointTestBase extends ResourceTestBase
{
final static int TEST_PORT = 6011;
@@ -38,7 +38,7 @@ public class TestSimpleEndpoint extends ResourceTestBase
}
}
- public static class SimpleResourceApp extends JsonApplication {
+ public static class SimpleResourceApp extends JsonApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}
@@ -62,7 +62,7 @@ public class TestSimpleEndpoint extends ResourceTestBase
}
}
- public static class SimpleRawApp extends JsonApplication {
+ public static class SimpleRawApp extends JsonApplicationWithJackson {
public SimpleRawApp() { super(new RawResource()); }
}
diff --git a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/TestWriteModifications.java b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/WriteModificationsTestBase.java
similarity index 97%
rename from json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/TestWriteModifications.java
rename to json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/WriteModificationsTestBase.java
index 7bfffb5..7d5cefa 100644
--- a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/TestWriteModifications.java
+++ b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/WriteModificationsTestBase.java
@@ -18,9 +18,8 @@ import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.jaxrs.cfg.EndpointConfigBase;
import com.fasterxml.jackson.jaxrs.cfg.ObjectWriterInjector;
import com.fasterxml.jackson.jaxrs.cfg.ObjectWriterModifier;
-import com.fasterxml.jackson.jaxrs.json.ResourceTestBase;
-public class TestWriteModifications extends ResourceTestBase
+public abstract class WriteModificationsTestBase extends ResourceTestBase
{
final static int TEST_PORT = 6021;
@@ -61,11 +60,11 @@ public class TestWriteModifications extends ResourceTestBase
}
}
- public static class SimpleResourceApp extends JsonApplication {
+ public static class SimpleResourceApp extends JsonApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}
- public static class SimpleIndentingApp extends JsonApplication {
+ public static class SimpleIndentingApp extends JsonApplicationWithJackson {
public SimpleIndentingApp() { super(new IndentingResource()); }
}
diff --git a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/jersey/SimpleEndpointTest.java b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/jersey/SimpleEndpointTest.java
new file mode 100644
index 0000000..c8bf2bb
--- /dev/null
+++ b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/jersey/SimpleEndpointTest.java
@@ -0,0 +1,11 @@
+package com.fasterxml.jackson.jaxrs.json.jersey;
+
+import javax.servlet.Servlet;
+
+import com.fasterxml.jackson.jaxrs.json.dw.SimpleEndpointTestBase;
+import com.sun.jersey.spi.container.servlet.ServletContainer;
+
+public class SimpleEndpointTest extends SimpleEndpointTestBase {
+ @Override
+ protected Class<? extends Servlet> servletContainerClass() { return ServletContainer.class; }
+}
diff --git a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/jersey/WriteModificationsTest.java b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/jersey/WriteModificationsTest.java
new file mode 100644
index 0000000..30bd3b0
--- /dev/null
+++ b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/jersey/WriteModificationsTest.java
@@ -0,0 +1,11 @@
+package com.fasterxml.jackson.jaxrs.json.jersey;
+
+import javax.servlet.Servlet;
+
+import com.fasterxml.jackson.jaxrs.json.dw.WriteModificationsTestBase;
+import com.sun.jersey.spi.container.servlet.ServletContainer;
+
+public class WriteModificationsTest extends WriteModificationsTestBase {
+ @Override
+ protected Class<? extends Servlet> servletContainerClass() { return ServletContainer.class; }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jackson-jaxrs-providers.git
More information about the pkg-java-commits
mailing list