This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 528c29f Tests.
528c29f is described below
commit 528c29f75fbbae0d5b26e7143f234aaad3e43549
Author: JamesBognar <[email protected]>
AuthorDate: Sun May 6 20:23:23 2018 -0400
Tests.
---
.../apache/juneau/rest/BasicRestInfoProvider.java | 23 +-
.../java/org/apache/juneau/rest/RestContext.java | 4 +-
.../apache/juneau/rest/util/MockHttpSession.java | 113 ++++
...ServletRequest.java => MockServletRequest.java} | 140 +++--
...rvletResponse.java => MockServletResponse.java} | 25 +-
.../juneau/rest/BasicRestInfoProviderTest.java | 575 ++++++++++++++++++---
.../apache/juneau/rest/annotation/BodyTest.java | 147 ++++++
7 files changed, 915 insertions(+), 112 deletions(-)
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
index 148bdca..8c9cc6f 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
@@ -390,15 +390,17 @@ public class BasicRestInfoProvider implements
RestInfoProvider {
ObjectMap rom = responses.getObjectMap(rStatus, true);
- ObjectMap rmd = r.getMetaData();
- rom.appendIf(true, true, true, "description",
vr.resolve(rmd.getString("description")));
- rom.appendIf(true, true, true, "x-example",
parseAnything(vr.resolve(rmd.getString("example"))));
- rom.appendIf(true, true, true, "examples",
parseMap(rmd.getString("examples"), vr, false, true, "RestMethodReturn/examples
on class {0} method {1}", c, m));
- rom.appendIf(true, true, true, "schema",
parseMap(rmd.getString("schema"), vr, false, true, "RestMethodReturn/schema on
class {0} method {1}", c, m));
- rom.appendIf(true, true, true, "headers",
parseMap(rmd.getString("headers"), vr, false, true, "RestMethodReturn/headers
on class {0} method {1}", c, m));
-
- rom.put("schema", getSchema(req,
rom.getObjectMap("schema", true), js, m.getGenericReturnType()));
- addXExamples(req, sm, rom, "ok", js,
m.getGenericReturnType());
+ if (r.getType() != void.class) {
+ ObjectMap rmd = r.getMetaData();
+ rom.appendIf(true, true, true, "description",
vr.resolve(rmd.getString("description")));
+ rom.appendIf(true, true, true, "x-example",
parseAnything(vr.resolve(rmd.getString("example"))));
+ rom.appendIf(true, true, true, "examples",
parseMap(rmd.getString("examples"), vr, false, true, "RestMethodReturn/examples
on class {0} method {1}", c, m));
+ rom.appendIf(true, true, true, "schema",
parseMap(rmd.getString("schema"), vr, false, true, "RestMethodReturn/schema on
class {0} method {1}", c, m));
+ rom.appendIf(true, true, true, "headers",
parseMap(rmd.getString("headers"), vr, false, true, "RestMethodReturn/headers
on class {0} method {1}", c, m));
+
+ rom.put("schema", getSchema(req,
rom.getObjectMap("schema", true), js, m.getGenericReturnType()));
+ addXExamples(req, sm, rom, "ok", js,
m.getGenericReturnType());
+ }
// Finally, look for @ResponseHeader parameters defined
on method.
for (RestMethodParam mp :
context.getRestMethodParams(m)) {
@@ -455,6 +457,9 @@ public class BasicRestInfoProvider implements
RestInfoProvider {
}
response.put("schema",
getSchema(req, response.getObjectMap("schema", true), js, type));
+
+// if
(response.containsKey("x-example"))
+// addXExamples(req, sm,
response, response.getString("x-example"), js, type);
}
} else if (in == RESPONSE_STATUS) {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index e8f258d..b81705d 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -2827,7 +2827,7 @@ public final class RestContext extends BeanContext {
* @return A new builder object.
* @throws ServletException Something bad happened.
*/
- static RestContextBuilder create(Object resource) throws
ServletException {
+ public static RestContextBuilder create(Object resource) throws
ServletException {
return new RestContextBuilder(null, resource.getClass(),
null).init(resource);
}
@@ -3682,7 +3682,7 @@ public final class RestContext extends BeanContext {
* The call handler for this resource.
* <br>Never <jk>null</jk>.
*/
- RestCallHandler getCallHandler() {
+ public RestCallHandler getCallHandler() {
return callHandler;
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockHttpSession.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockHttpSession.java
new file mode 100644
index 0000000..9184df0
--- /dev/null
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockHttpSession.java
@@ -0,0 +1,113 @@
+//
***************************************************************************************************************************
+// * 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.juneau.rest.util;
+
+import java.util.*;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+/**
+ * An implementation of {@link HttpSession} for testing purposes.
+ */
+public class MockHttpSession implements HttpSession {
+
+ /**
+ * Creates a new HTTP session.
+ *
+ * @return A new HTTP session.
+ */
+ public static MockHttpSession create() {
+ return new MockHttpSession();
+ }
+
+ @Override /* HttpSession */
+ public long getCreationTime() {
+ return 0;
+ }
+
+ @Override /* HttpSession */
+ public String getId() {
+ return null;
+ }
+
+ @Override /* HttpSession */
+ public long getLastAccessedTime() {
+ return 0;
+ }
+
+ @Override /* HttpSession */
+ public ServletContext getServletContext() {
+ return null;
+ }
+
+ @Override /* HttpSession */
+ public void setMaxInactiveInterval(int interval) {
+ }
+
+ @Override /* HttpSession */
+ public int getMaxInactiveInterval() {
+ return 0;
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override /* HttpSession */
+ public HttpSessionContext getSessionContext() {
+ return null;
+ }
+
+ @Override /* HttpSession */
+ public Object getAttribute(String name) {
+ return null;
+ }
+
+ @Override /* HttpSession */
+ public Object getValue(String name) {
+ return null;
+ }
+
+ @Override /* HttpSession */
+ public Enumeration<String> getAttributeNames() {
+ return null;
+ }
+
+ @Override /* HttpSession */
+ public String[] getValueNames() {
+ return null;
+ }
+
+ @Override /* HttpSession */
+ public void setAttribute(String name, Object value) {
+ }
+
+ @Override /* HttpSession */
+ public void putValue(String name, Object value) {
+ }
+
+ @Override /* HttpSession */
+ public void removeAttribute(String name) {
+ }
+
+ @Override /* HttpSession */
+ public void removeValue(String name) {
+ }
+
+ @Override /* HttpSession */
+ public void invalidate() {
+ }
+
+ @Override /* HttpSession */
+ public boolean isNew() {
+ return false;
+ }
+}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockHttpServletRequest.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletRequest.java
similarity index 82%
rename from
juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockHttpServletRequest.java
rename to
juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletRequest.java
index 40c9dec..c0691fc 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockHttpServletRequest.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletRequest.java
@@ -24,14 +24,14 @@ import org.apache.juneau.internal.*;
/**
* An implementation of {@link HttpServletRequest} for testing purposes.
*/
-public class MockHttpServletRequest implements HttpServletRequest {
+public class MockServletRequest implements HttpServletRequest {
private String method = "GET";
private Map<String,String[]> parameterMap = new LinkedHashMap<>();
private Map<String,String[]> headerMap = new LinkedHashMap<>();
private Map<String,Object> attributeMap = new LinkedHashMap<>();
private String characterEncoding = "UTF-8";
- private byte[] body;
+ private byte[] body = new byte[0];
private String protocol = "HTTP/1.1";
private String scheme = "http";
private String serverName = "localhost";
@@ -51,14 +51,52 @@ public class MockHttpServletRequest implements
HttpServletRequest {
private Cookie[] cookies;
private String pathInfo;
private String pathTranslated;
- private String contextPath;
- private String queryString;
+ private String contextPath = "";
+ private String queryString = "";
private String remoteUser;
private Principal userPrincipal;
private String requestedSessionId;
- private String requestURI;
- private String servletPath;
- private HttpSession httpSession;
+ private String requestURI = "";
+ private String servletPath = "";
+ private HttpSession httpSession = MockHttpSession.create();
+
+ /**
+ * Creates a new servlet request.
+ *
+ * Initialized with the following:
+ * <ul>
+ * <li><code>"Accept: text/json+simple"</code>
+ * <li><code>"Content-Type: text/json"</code>
+ * </ul>
+ *
+ * @return A new request.
+ */
+ public static MockServletRequest create() {
+ MockServletRequest r = new MockServletRequest();
+ r.header("Accept", "text/json+simple").header("Content-Type",
"text/json");
+ return r;
+ }
+
+ /**
+ * Creates a new servlet request with the specified method name and
request path.
+ *
+ * Initialized with the following:
+ * <ul>
+ * <li><code>"Accept: text/json+simple"</code>
+ * <li><code>"Content-Type: text/json"</code>
+ * </ul>
+ *
+ * @param method The HTTP method name.
+ * @param path The request path.
+ * @param pathArgs Optional path arguments.
+ *
+ * @return A new request.
+ */
+ public static MockServletRequest create(String method, String path,
Object...pathArgs) {
+ return create()
+ .method(method)
+ .requestURI(StringUtils.format(path, pathArgs));
+ }
/**
* Fluent setter.
@@ -66,7 +104,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The method name for this request.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest method(String value) {
+ public MockServletRequest method(String value) {
this.method = value;
return this;
}
@@ -78,7 +116,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value Query parameter values.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest param(String name, String[] value) {
+ public MockServletRequest param(String name, String[] value) {
this.parameterMap.put(name, value);
return this;
}
@@ -90,7 +128,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value Query parameter value.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest param(String name, String value) {
+ public MockServletRequest param(String name, String value) {
this.parameterMap.put(name, new String[] {value});
return this;
}
@@ -102,7 +140,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value Header value.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest header(String name, String value) {
+ public MockServletRequest header(String name, String value) {
this.headerMap.put(name, new String[] {value});
return this;
}
@@ -114,7 +152,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value Request attribute value.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest attribute(String name, Object value) {
+ public MockServletRequest attribute(String name, Object value) {
this.attributeMap.put(name, value);
return this;
}
@@ -125,7 +163,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The body of the request.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest body(Object value) {
+ public MockServletRequest body(Object value) {
try {
if (value instanceof byte[])
this.body = (byte[])value;
@@ -147,7 +185,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The character encoding.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest characterEncoding(String value) {
+ public MockServletRequest characterEncoding(String value) {
this.characterEncoding = value;
return this;
}
@@ -158,7 +196,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The protocol.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest protocol(String value) {
+ public MockServletRequest protocol(String value) {
this.protocol = value;
return this;
}
@@ -169,7 +207,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The scheme.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest scheme(String value) {
+ public MockServletRequest scheme(String value) {
this.scheme = value;
return this;
}
@@ -180,7 +218,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The server name.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest serverName(String value) {
+ public MockServletRequest serverName(String value) {
this.serverName = value;
return this;
}
@@ -191,7 +229,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The server port.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest serverPort(int value) {
+ public MockServletRequest serverPort(int value) {
this.serverPort = value;
return this;
}
@@ -202,7 +240,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The remote address.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest remoteAddr(String value) {
+ public MockServletRequest remoteAddr(String value) {
this.remoteAddr = value;
return this;
}
@@ -213,7 +251,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The remote port.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest remoteHost(String value) {
+ public MockServletRequest remoteHost(String value) {
this.remoteHost = value;
return this;
}
@@ -224,7 +262,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The locale.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest locale(Locale value) {
+ public MockServletRequest locale(Locale value) {
this.locale = value;
return this;
}
@@ -235,7 +273,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The real path.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest realPath(String value) {
+ public MockServletRequest realPath(String value) {
this.realPath = value;
return this;
}
@@ -246,7 +284,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The remote port.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest remotePort(int value) {
+ public MockServletRequest remotePort(int value) {
this.remotePort = value;
return this;
}
@@ -257,7 +295,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The local name.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest localName(String value) {
+ public MockServletRequest localName(String value) {
this.localName = value;
return this;
}
@@ -268,7 +306,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The local address.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest localAddr(String value) {
+ public MockServletRequest localAddr(String value) {
this.localAddr = value;
return this;
}
@@ -279,7 +317,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The local port.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest localPort(int value) {
+ public MockServletRequest localPort(int value) {
this.localPort = value;
return this;
}
@@ -290,7 +328,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The request dispatcher.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest requestDispatcher(RequestDispatcher
value) {
+ public MockServletRequest requestDispatcher(RequestDispatcher value) {
this.requestDispatcher = value;
return this;
}
@@ -301,7 +339,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The servlet context.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest servletContext(ServletContext value) {
+ public MockServletRequest servletContext(ServletContext value) {
this.servletContext = value;
return this;
}
@@ -312,7 +350,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The dispatcher type.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest dispatcherType(DispatcherType value) {
+ public MockServletRequest dispatcherType(DispatcherType value) {
this.dispatcherType = value;
return this;
}
@@ -323,7 +361,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The auth type.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest authType(String value) {
+ public MockServletRequest authType(String value) {
this.authType = value;
return this;
}
@@ -334,7 +372,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The cookies.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest cookies(Cookie[] value) {
+ public MockServletRequest cookies(Cookie[] value) {
this.cookies = value;
return this;
}
@@ -345,7 +383,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The path info.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest pathInfo(String value) {
+ public MockServletRequest pathInfo(String value) {
this.pathInfo = value;
return this;
}
@@ -356,7 +394,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The path translated.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest pathTranslated(String value) {
+ public MockServletRequest pathTranslated(String value) {
this.pathTranslated = value;
return this;
}
@@ -367,7 +405,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The context path.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest contextPath(String value) {
+ public MockServletRequest contextPath(String value) {
this.contextPath = value;
return this;
}
@@ -378,7 +416,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The query string.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest queryString(String value) {
+ public MockServletRequest queryString(String value) {
this.queryString = value;
return this;
}
@@ -389,7 +427,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The remote user.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest remoteUser(String value) {
+ public MockServletRequest remoteUser(String value) {
this.remoteUser = value;
return this;
}
@@ -400,7 +438,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The user principal.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest userPrincipal(Principal value) {
+ public MockServletRequest userPrincipal(Principal value) {
this.userPrincipal = value;
return this;
}
@@ -411,7 +449,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The requested session ID.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest requestedSessionId(String value) {
+ public MockServletRequest requestedSessionId(String value) {
this.requestedSessionId = value;
return this;
}
@@ -422,7 +460,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The request URI.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest requestURI(String value) {
+ public MockServletRequest requestURI(String value) {
this.requestURI = value;
return this;
}
@@ -433,7 +471,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The servlet path.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest servletPath(String value) {
+ public MockServletRequest servletPath(String value) {
this.servletPath = value;
return this;
}
@@ -444,7 +482,7 @@ public class MockHttpServletRequest implements
HttpServletRequest {
* @param value The HTTP session.
* @return This object (for method chaining).
*/
- public MockHttpServletRequest httpSession(HttpSession value) {
+ public MockServletRequest httpSession(HttpSession value) {
this.httpSession = value;
return this;
}
@@ -796,4 +834,24 @@ public class MockHttpServletRequest implements
HttpServletRequest {
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass)
throws IOException, ServletException {
return null;
}
+
+ /**
+ * Specifies the <code>Content-Type</code> header value on the request.
+ *
+ * @param value The new value.
+ * @return This object (for method chaining).
+ */
+ public MockServletRequest contentType(String value) {
+ return header("Content-Type", value);
+ }
+
+ /**
+ * Specifies the <code>Accept</code> header value on the request.
+ *
+ * @param value The new value.
+ * @return This object (for method chaining).
+ */
+ public MockServletRequest accept(String value) {
+ return header("Accept", value);
+ }
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockHttpServletResponse.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletResponse.java
similarity index 93%
rename from
juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockHttpServletResponse.java
rename to
juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletResponse.java
index 5e5fc60..374f524 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockHttpServletResponse.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/MockServletResponse.java
@@ -23,7 +23,7 @@ import org.apache.juneau.internal.*;
/**
* An implementation of {@link HttpServletResponse} for testing purposes.
*/
-public class MockHttpServletResponse implements HttpServletResponse {
+public class MockServletResponse implements HttpServletResponse {
private String characterEncoding = "UTF-8";
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -34,6 +34,16 @@ public class MockHttpServletResponse implements
HttpServletResponse {
private String msg;
private Map<String,String[]> headerMap = new LinkedHashMap<>();
+
+ /**
+ * Creates a new servlet response.
+ *
+ * @return A new response.
+ */
+ public static MockServletResponse create() {
+ return new MockServletResponse();
+ }
+
/**
* Returns the content length.
*
@@ -237,4 +247,17 @@ public class MockHttpServletResponse implements
HttpServletResponse {
public Collection<String> getHeaderNames() {
return headerMap.keySet();
}
+
+ /**
+ * Returns the body of the request as a string.
+ *
+ * @return The body of the request as a string.
+ */
+ public String getBodyAsString() {
+ try {
+ return baos.toString("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BasicRestInfoProviderTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BasicRestInfoProviderTest.java
index 13c3db2..eb21173 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BasicRestInfoProviderTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BasicRestInfoProviderTest.java
@@ -36,14 +36,14 @@ public class BasicRestInfoProviderTest {
private Swagger getSwaggerWithFile(Object resource) throws Exception {
RestContext rc =
RestContext.create(resource).classpathResourceFinder(TestClasspathResourceFinder.class).build();
- RestRequest req = rc.getCallHandler().createRequest(new
MockHttpServletRequest());
+ RestRequest req = rc.getCallHandler().createRequest(new
MockServletRequest());
RestInfoProvider ip = rc.getInfoProvider();
return ip.getSwagger(req);
}
private static Swagger getSwagger(Object resource) throws Exception {
RestContext rc = RestContext.create(resource).build();
- RestRequest req = rc.getCallHandler().createRequest(new
MockHttpServletRequest());
+ RestRequest req = rc.getCallHandler().createRequest(new
MockServletRequest());
RestInfoProvider ip = rc.getInfoProvider();
return ip.getSwagger(req);
}
@@ -3033,7 +3033,7 @@ public class BasicRestInfoProviderTest {
}
@Test
- public void ns03_body_examples_swaggerOnMethns() throws Exception {
+ public void ns03_body_examples_swaggerOnMethods() throws Exception {
assertObjectEquals("{foo:'c'}", getSwagger(new
NS03()).getPaths().get("/path/{foo}/body").get("get").getParameter("body",null).getExamples());
assertObjectEquals("{foo:'c'}", getSwaggerWithFile(new
NS03()).getPaths().get("/path/{foo}/body").get("get").getParameter("body",null).getExamples());
}
@@ -3661,16 +3661,38 @@ public class BasicRestInfoProviderTest {
public void pa22(PA22 h) {}
@Header(name="H", schema="{type:'a'}")
- public static class PA23 {}
+ public static class PA23a {}
@RestMethod(name=GET,path="/schema1")
- public void pa23(PA23 h) {}
+ public void pa23a(PA23a h) {}
@Header(name="H", schema=" type:'a' ")
- public static class PA24 {}
+ public static class PA23b {}
@RestMethod(name=GET,path="/schema2")
- public void pa24(PA24 h) {}
+ public void pa23(PA23b h) {}
+
+ @Header(name="H")
+ public static class PA23c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void pa23c(PA23c b) {}
+
+ @Header(name="H")
+ public static class PA23d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void pa23d(PA23d b) {}
+
+ @Header(name="H")
+ public static class PA23e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void pa23e(PA23e b) {}
@Header(name="H", type="a")
public static class PA25 {}
@@ -3778,14 +3800,26 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("true", getSwagger(new
PA()).getPaths().get("/required").get("get").getParameter("header",
"H").getRequired());
}
@Test
- public void pa23_Header_onPojo_schema() throws Exception {
+ public void pa23a_Header_onPojo_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
PA()).getPaths().get("/schema1").get("get").getParameter("header",
"H").getSchema());
}
@Test
- public void pa24_Header_onPojo_schema() throws Exception {
+ public void pa23b_Header_onPojo_schema2() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
PA()).getPaths().get("/schema2").get("get").getParameter("header",
"H").getSchema());
}
@Test
+ public void pa23c_Header_onPojo_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new
PA()).getPaths().get("/schema3").get("get").getParameter("header",
"H").getSchema());
+ }
+ @Test
+ public void pa23d_Header_onPojo_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new
PA()).getPaths().get("/schema4").get("get").getParameter("header",
"H").getSchema());
+ }
+ @Test
+ public void pa23e_Header_onPojo_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
PA()).getPaths().get("/schema5").get("get").getParameter("header",
"H").getSchema());
+ }
+ @Test
public void pa25_Header_onPojo_type() throws Exception {
assertObjectEquals("'a'", getSwagger(new
PA()).getPaths().get("/type").get("get").getParameter("header", "H").getType());
}
@@ -3864,6 +3898,31 @@ public class BasicRestInfoProviderTest {
@RestMethod(name=GET,path="/schema2")
public void pb19b(@Header(name="H", schema={" type:'b' "})
String h) {}
+ public static class PB19c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void pb19c(@Header("H") PB19c b) {}
+
+ public static class PB19d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void pb19d(@Header("H") PB19d b) {}
+
+ public static class PB19e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void pb19e(@Header("H") PB19e b) {}
+
+ @RestMethod(name=GET,path="/schema6")
+ public void pb19f(@Header("H") Integer b) {}
+
+ @RestMethod(name=GET,path="/schema7")
+ public void pb19g(@Header("H") Boolean b) {}
+
@RestMethod(name=GET,path="/_default1")
public void pb20a(@Header(name="H", _default="a") String h) {}
@@ -3974,6 +4033,26 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("{type:'b'}", getSwagger(new
PB()).getPaths().get("/schema2").get("get").getParameter("header",
"H").getSchema());
}
@Test
+ public void pb19c_Header_onParameter_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new
PB()).getPaths().get("/schema3").get("get").getParameter("header",
"H").getSchema());
+ }
+ @Test
+ public void pb19d_Header_onParameter_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new
PB()).getPaths().get("/schema4").get("get").getParameter("header",
"H").getSchema());
+ }
+ @Test
+ public void pb19e_Header_onParameter_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
PB()).getPaths().get("/schema5").get("get").getParameter("header",
"H").getSchema());
+ }
+ @Test
+ public void pb19f_Header_onParameter_schema6() throws Exception {
+ assertObjectEquals("{format:'int32',type:'integer'}",
getSwagger(new
PB()).getPaths().get("/schema6").get("get").getParameter("header",
"H").getSchema());
+ }
+ @Test
+ public void pb19g_Header_onParameter_schema7() throws Exception {
+ assertObjectEquals("{type:'boolean'}", getSwagger(new
PB()).getPaths().get("/schema7").get("get").getParameter("header",
"H").getSchema());
+ }
+ @Test
public void pb20a_Header_onParameter__default1() throws Exception {
assertObjectEquals("'a'", getSwagger(new
PB()).getPaths().get("/_default1").get("get").getParameter("header",
"H").getDefault());
}
@@ -4130,17 +4209,39 @@ public class BasicRestInfoProviderTest {
public void qa18(QA18 q) {}
@Query(name="Q", schema=" {type:'a'} ")
- public static class QA19 {}
+ public static class QA19a {}
@RestMethod(name=GET,path="/schema1")
- public void qa19(QA19 q) {}
+ public void qa19a(QA19a q) {}
@Query(name="Q", schema={" type:'b' "})
- public static class QA20 {}
+ public static class QA19b {}
@RestMethod(name=GET,path="/schema2")
- public void qa20(QA20 q) {}
+ public void qa19b(QA19b q) {}
+ @Query("Q")
+ public static class QA19c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void qa19c(QA19c q) {}
+
+ @Query("Q")
+ public static class QA19d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void qa19d(QA19d q) {}
+
+ @Query("Q")
+ public static class QA19e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void qa19e(QA19e q) {}
+
@Query(name="Q", _default="a")
public static class QA21a {}
@@ -4271,14 +4372,26 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("true", getSwagger(new
QA()).getPaths().get("/uniqueItems").get("get").getParameter("query",
"Q").getUniqueItems());
}
@Test
- public void qa19_Query_onPojo_schema1() throws Exception {
+ public void qa19a_Query_onPojo_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
QA()).getPaths().get("/schema1").get("get").getParameter("query",
"Q").getSchema());
}
@Test
- public void qa20_Query_onPojo_schema2() throws Exception {
+ public void qa19b_Query_onPojo_schema2() throws Exception {
assertObjectEquals("{type:'b'}", getSwagger(new
QA()).getPaths().get("/schema2").get("get").getParameter("query",
"Q").getSchema());
}
@Test
+ public void qa19c_Query_onPojo_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new
QA()).getPaths().get("/schema3").get("get").getParameter("query",
"Q").getSchema());
+ }
+ @Test
+ public void qa19d_Query_onPojo_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new
QA()).getPaths().get("/schema4").get("get").getParameter("query",
"Q").getSchema());
+ }
+ @Test
+ public void qa19e_Query_onPojo_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
QA()).getPaths().get("/schema5").get("get").getParameter("query",
"Q").getSchema());
+ }
+ @Test
public void qa21a_Query_onPojo_default1() throws Exception {
assertEquals("a", getSwagger(new
QA()).getPaths().get("/_default1").get("get").getParameter("query",
"Q").getDefault());
}
@@ -4384,6 +4497,34 @@ public class BasicRestInfoProviderTest {
@RestMethod(name=GET,path="/schema2")
public void qb19b(@Query(name="Q", schema={ " type: 'b' "})
String q) {}
+ public static class TB18c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void tb18c(@Body TB18c b) {}
+
+ public static class TB18d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void tb18d(@Body TB18d b) {}
+
+ public static class TB18e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void tb18e(@Body TB18e b) {}
+
+ @RestMethod(name=GET,path="/schema6")
+ public void tb18f(@Body Integer b) {}
+
+ @RestMethod(name=GET,path="/schema7")
+ public void tb18g(@Body Boolean b) {}
+
+
+
+
@RestMethod(name=GET,path="/_default1")
public void qb20a(@Query(name="Q", _default="a") String q) {}
@@ -4658,16 +4799,38 @@ public class BasicRestInfoProviderTest {
public void ra19(RA19 f) {}
@FormData(name="F", schema=" {type:'a'} ")
- public static class RA20 {}
+ public static class RA20a {}
@RestMethod(name=GET,path="/schema1")
- public void ra20(RA20 f) {}
+ public void ra20a(RA20a f) {}
@FormData(name="F", schema={" type:'b' "})
- public static class RA21 {}
+ public static class RA20b {}
@RestMethod(name=GET,path="/schema2")
- public void ra21(RA21 f) {}
+ public void ra20b(RA20b f) {}
+
+ @FormData("F")
+ public static class RA20c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void ra20c(RA20c f) {}
+
+ @FormData("F")
+ public static class RA20d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void ra20d(RA20d f) {}
+
+ @FormData("F")
+ public static class RA20e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void ra20e(RA20e f) {}
@FormData(name="F", _default="a")
public static class RA22 {}
@@ -4803,14 +4966,26 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("true", getSwagger(new
RA()).getPaths().get("/uniqueItems").get("get").getParameter("formData",
"F").getUniqueItems());
}
@Test
- public void ra20_FormData_onPojo_schema1() throws Exception {
+ public void ra20a_FormData_onPojo_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
RA()).getPaths().get("/schema1").get("get").getParameter("formData",
"F").getSchema());
}
@Test
- public void ra21_FormData_onPojo_schema2() throws Exception {
+ public void ra20b_FormData_onPojo_schema2() throws Exception {
assertObjectEquals("{type:'b'}", getSwagger(new
RA()).getPaths().get("/schema2").get("get").getParameter("formData",
"F").getSchema());
}
@Test
+ public void ra20c_FormData_onPojo_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new
RA()).getPaths().get("/schema3").get("get").getParameter("formData",
"F").getSchema());
+ }
+ @Test
+ public void ra20d_FormData_onPojo_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new
RA()).getPaths().get("/schema4").get("get").getParameter("formData",
"F").getSchema());
+ }
+ @Test
+ public void ra20e_FormData_onPojo_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
RA()).getPaths().get("/schema5").get("get").getParameter("formData",
"F").getSchema());
+ }
+ @Test
public void ra22_FormData_onPojo__default1() throws Exception {
assertEquals("a", getSwagger(new
RA()).getPaths().get("/_default1").get("get").getParameter("formData",
"F").getDefault());
}
@@ -4911,11 +5086,36 @@ public class BasicRestInfoProviderTest {
public void rb20(@FormData(name="F", uniqueItems="true") String
f) {}
@RestMethod(name=GET,path="/schema1")
- public void rb21(@FormData(name="F", schema=" {type:'a'} ")
String f) {}
+ public void rb21a(@FormData(name="F", schema=" {type:'a'} ")
String f) {}
@RestMethod(name=GET,path="/schema2")
- public void rb22(@FormData(name="F", schema= {" type:'b' "})
String f) {}
+ public void rb21b(@FormData(name="F", schema= {" type:'b' "})
String f) {}
+
+ public static class RB21c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void rb21c(@FormData("F") RB21c b) {}
+
+ public static class RB21d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void rb21d(@FormData("F") RB21d b) {}
+
+ public static class RB21e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void rb21e(@FormData("F") RB21e b) {}
+
+ @RestMethod(name=GET,path="/schema6")
+ public void rb21f(@FormData("F") Integer b) {}
+ @RestMethod(name=GET,path="/schema7")
+ public void rb21g(@FormData("F") Boolean b) {}
+
@RestMethod(name=GET,path="/_default1")
public void rb23(@FormData(name="F", _default="a") String f) {}
@@ -5022,14 +5222,34 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("true", getSwagger(new
RB()).getPaths().get("/uniqueItems").get("get").getParameter("formData",
"F").getUniqueItems());
}
@Test
- public void rb21_FormData_onParameter_schema1() throws Exception {
+ public void rb21a_FormData_onParameter_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
RB()).getPaths().get("/schema1").get("get").getParameter("formData",
"F").getSchema());
}
@Test
- public void rb22_FormData_onParameter_schema2() throws Exception {
+ public void rb21b_FormData_onParameter_schema2() throws Exception {
assertObjectEquals("{type:'b'}", getSwagger(new
RB()).getPaths().get("/schema2").get("get").getParameter("formData",
"F").getSchema());
}
@Test
+ public void rb21c_FormData_onParameter_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new
RB()).getPaths().get("/schema3").get("get").getParameter("formData",
"F").getSchema());
+ }
+ @Test
+ public void rb21d_FormData_onParameter_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new
RB()).getPaths().get("/schema4").get("get").getParameter("formData",
"F").getSchema());
+ }
+ @Test
+ public void rb21e_FormData_onParameter_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
RB()).getPaths().get("/schema5").get("get").getParameter("formData",
"F").getSchema());
+ }
+ @Test
+ public void rb21f_FormData_onParameter_schema6() throws Exception {
+ assertObjectEquals("{format:'int32',type:'integer'}",
getSwagger(new
RB()).getPaths().get("/schema6").get("get").getParameter("formData",
"F").getSchema());
+ }
+ @Test
+ public void rb21g_FormData_onParameter_schema7() throws Exception {
+ assertObjectEquals("{type:'boolean'}", getSwagger(new
RB()).getPaths().get("/schema7").get("get").getParameter("formData",
"F").getSchema());
+ }
+ @Test
public void rb23_FormData_onParameter__default1() throws Exception {
assertEquals("a", getSwagger(new
RB()).getPaths().get("/_default1").get("get").getParameter("formData",
"F").getDefault());
}
@@ -5160,16 +5380,38 @@ public class BasicRestInfoProviderTest {
public void sa15(SA15 f) {}
@Path(name="P", schema=" {type:'a'} ")
- public static class SA16 {}
+ public static class SA16a {}
@RestMethod(name=GET,path="/schema1/{P}")
- public void sa16(SA16 f) {}
+ public void sa16a(SA16a f) {}
@Path(name="P", schema= {" type:'b' "})
- public static class SA17 {}
+ public static class SA16b {}
@RestMethod(name=GET,path="/schema2/{P}")
- public void sa17(SA17 f) {}
+ public void sa16b(SA16b f) {}
+
+ @Path("P")
+ public static class SA16c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3/{P}")
+ public void sa16c(SA16c b) {}
+
+ @Path("P")
+ public static class SA16d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4/{P}")
+ public void sa16d(SA16d b) {}
+
+ @Path("P")
+ public static class SA16e {}
+
+ @RestMethod(name=GET,path="/schema5/{P}")
+ public void sa16e(SA16e b) {}
@Path(name="P", _enum="a,b")
public static class SA18 {}
@@ -5261,14 +5503,26 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("true", getSwagger(new
SA()).getPaths().get("/exclusiveMinimum/{P}").get("get").getParameter("path",
"P").getExclusiveMinimum());
}
@Test
- public void sa16_Path_onPojo_schema1() throws Exception {
+ public void sa16a_Path_onPojo_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
SA()).getPaths().get("/schema1/{P}").get("get").getParameter("path",
"P").getSchema());
}
@Test
- public void sa17_Path_onPojo_schema2() throws Exception {
+ public void sa16b_Path_onPojo_schema2() throws Exception {
assertObjectEquals("{type:'b'}", getSwagger(new
SA()).getPaths().get("/schema2/{P}").get("get").getParameter("path",
"P").getSchema());
}
@Test
+ public void sa16c_Path_onPojo_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new
SA()).getPaths().get("/schema3/{P}").get("get").getParameter("path",
"P").getSchema());
+ }
+ @Test
+ public void sa16d_Path_onPojo_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new
SA()).getPaths().get("/schema4/{P}").get("get").getParameter("path",
"P").getSchema());
+ }
+ @Test
+ public void sa16e_Path_onPojo_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
SA()).getPaths().get("/schema5/{P}").get("get").getParameter("path",
"P").getSchema());
+ }
+ @Test
public void sa18_Path_onPojo__enum1() throws Exception {
assertObjectEquals("['a','b']", getSwagger(new
SA()).getPaths().get("/_enum1/{P}").get("get").getParameter("path",
"P").getEnum());
}
@@ -5338,11 +5592,36 @@ public class BasicRestInfoProviderTest {
public void sb15(@Path(name="P", exclusiveMinimum="true")
String h) {}
@RestMethod(name=GET,path="/schema1/{P}")
- public void sb16(@Path(name="P", schema=" {type:'a'} ") String
h) {}
+ public void sb16a(@Path(name="P", schema=" {type:'a'} ") String
h) {}
@RestMethod(name=GET,path="/schema2/{P}")
- public void sb17(@Path(name="P", schema= {" type:'b' "}) String
h) {}
+ public void sb16b(@Path(name="P", schema= {" type:'b' "})
String h) {}
+
+ public static class SB16c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3/{P}")
+ public void sb16c(@Path("P") SB16c b) {}
+
+ public static class SB16d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4/{P}")
+ public void sb16d(@Path("P") SB16d b) {}
+
+ public static class SB16e {}
+
+ @RestMethod(name=GET,path="/schema5/{P}")
+ public void sb16e(@Path("P") SB16e b) {}
+ @RestMethod(name=GET,path="/schema6/{P}")
+ public void sb16f(@Path("P") Integer b) {}
+
+ @RestMethod(name=GET,path="/schema7/{P}")
+ public void sb16g(@Path("P") Boolean b) {}
+
@RestMethod(name=GET,path="/_enum1/{P}")
public void sb18(@Path(name="P", _enum=" a,b ") String h) {}
@@ -5417,14 +5696,34 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("true", getSwagger(new
SB()).getPaths().get("/exclusiveMinimum/{P}").get("get").getParameter("path",
"P").getExclusiveMinimum());
}
@Test
- public void sb16_Path_onParameter_schema1() throws Exception {
+ public void sb16a_Path_onParameter_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
SB()).getPaths().get("/schema1/{P}").get("get").getParameter("path",
"P").getSchema());
}
@Test
- public void sb17_Path_onParameter_schema2() throws Exception {
+ public void sb16b_Path_onParameter_schema2() throws Exception {
assertObjectEquals("{type:'b'}", getSwagger(new
SB()).getPaths().get("/schema2/{P}").get("get").getParameter("path",
"P").getSchema());
}
@Test
+ public void sb16c_Path_onParameter_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new
SB()).getPaths().get("/schema3/{P}").get("get").getParameter("path",
"P").getSchema());
+ }
+ @Test
+ public void sb16d_Path_onParameter_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new
SB()).getPaths().get("/schema4/{P}").get("get").getParameter("path",
"P").getSchema());
+ }
+ @Test
+ public void sb16e_Path_onParameter_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
SB()).getPaths().get("/schema5/{P}").get("get").getParameter("path",
"P").getSchema());
+ }
+ @Test
+ public void sb16f_Path_onParameter_schema6() throws Exception {
+ assertObjectEquals("{format:'int32',type:'integer'}",
getSwagger(new
SB()).getPaths().get("/schema6/{P}").get("get").getParameter("path",
"P").getSchema());
+ }
+ @Test
+ public void sb16g_Path_onParameter_schema7() throws Exception {
+ assertObjectEquals("{type:'boolean'}", getSwagger(new
SB()).getPaths().get("/schema7/{P}").get("get").getParameter("path",
"P").getSchema());
+ }
+ @Test
public void sb18_Path_onParameter__enum1() throws Exception {
assertObjectEquals("['a','b']", getSwagger(new
SB()).getPaths().get("/_enum1/{P}").get("get").getParameter("path",
"P").getEnum());
}
@@ -5551,16 +5850,38 @@ public class BasicRestInfoProviderTest {
public void ta17(TA17 h) {}
@Body(schema="{type:'a'}")
- public static class TA18 {}
+ public static class TA18a {}
@RestMethod(name=GET,path="/schema1")
- public void ta18(TA18 h) {}
+ public void ta18a(TA18a h) {}
@Body(schema={" type:'b' "})
- public static class TA19 {}
+ public static class TA18b {}
@RestMethod(name=GET,path="/schema2")
- public void ta19(TA19 h) {}
+ public void ta18b(TA18b h) {}
+
+ @Body
+ public static class TA18c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void ta18c(TA18c b) {}
+
+ @Body
+ public static class TA18d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void ta18d(TA18d b) {}
+
+ @Body
+ public static class TA18e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void ta18e(TA18e b) {}
@Body(_default="'a'")
public static class TA20 {}
@@ -5696,14 +6017,26 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("true", getSwagger(new
TA()).getPaths().get("/uniqueItems").get("get").getParameter("body",
null).getUniqueItems());
}
@Test
- public void ta18_Body_onPojo_schema1() throws Exception {
+ public void ta18a_Body_onPojo_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
TA()).getPaths().get("/schema1").get("get").getParameter("body",
null).getSchema());
}
@Test
- public void ta19_Body_onPojo_schema2() throws Exception {
+ public void ta18b_Body_onPojo_schema2() throws Exception {
assertObjectEquals("{type:'b'}", getSwagger(new
TA()).getPaths().get("/schema2").get("get").getParameter("body",
null).getSchema());
}
@Test
+ public void ta18c_Body_onPojo_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new TA()).getPaths().get("/schema3").get("get").getParameter("body",
null).getSchema());
+ }
+ @Test
+ public void ta18d_Body_onPojo_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new TA()).getPaths().get("/schema4").get("get").getParameter("body",
null).getSchema());
+ }
+ @Test
+ public void ta18e_Body_onPojo_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
TA()).getPaths().get("/schema5").get("get").getParameter("body",
null).getSchema());
+ }
+ @Test
public void ta20_Body_onPojo__default() throws Exception {
assertObjectEquals("'a'", getSwagger(new
TA()).getPaths().get("/_default1").get("get").getParameter("body",
null).getDefault());
}
@@ -5836,15 +6169,40 @@ public class BasicRestInfoProviderTest {
@RestMethod(name=GET,path="/uniqueItems")
public void tb17(@Body(uniqueItems="true") TB17 b) {}
- public static class TB18 {}
+ public static class TB18a {}
@RestMethod(name=GET,path="/schema1")
- public void tb18(@Body(schema=" {type:'a'} ") TB18 b) {}
+ public void tb18a(@Body(schema=" {type:'a'} ") TB18a b) {}
- public static class TB19 {}
+ public static class TB18b {}
@RestMethod(name=GET,path="/schema2")
- public void tb19(@Body(schema={" type:'b' "}) TB19 b) {}
+ public void tb18b(@Body(schema={" type:'b' "}) TB18b b) {}
+
+ public static class TB18c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void tb18c(@Body TB18c b) {}
+
+ public static class TB18d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void tb18d(@Body TB18d b) {}
+
+ public static class TB18e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void tb18e(@Body TB18e b) {}
+
+ @RestMethod(name=GET,path="/schema6")
+ public void tb18f(@Body Integer b) {}
+
+ @RestMethod(name=GET,path="/schema7")
+ public void tb18g(@Body Boolean b) {}
public static class TB20 {}
@@ -5970,14 +6328,34 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("true", getSwagger(new
TB()).getPaths().get("/uniqueItems").get("get").getParameter("body",
null).getUniqueItems());
}
@Test
- public void tb18_Body_onParameter_schema1() throws Exception {
+ public void tb18a_Body_onParameter_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
TB()).getPaths().get("/schema1").get("get").getParameter("body",
null).getSchema());
}
@Test
- public void tb19_Body_onParameter_schema2() throws Exception {
+ public void tb18b_Body_onParameter_schema2() throws Exception {
assertObjectEquals("{type:'b'}", getSwagger(new
TB()).getPaths().get("/schema2").get("get").getParameter("body",
null).getSchema());
}
@Test
+ public void tb18c_Body_onParameter_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new TB()).getPaths().get("/schema3").get("get").getParameter("body",
null).getSchema());
+ }
+ @Test
+ public void tb18d_Body_onParameter_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new TB()).getPaths().get("/schema4").get("get").getParameter("body",
null).getSchema());
+ }
+ @Test
+ public void tb18e_Body_onParameter_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
TB()).getPaths().get("/schema5").get("get").getParameter("body",
null).getSchema());
+ }
+ @Test
+ public void tb18e_Body_onParameter_schema6() throws Exception {
+ assertObjectEquals("{format:'int32',type:'integer'}",
getSwagger(new TB()).getPaths().get("/schema6").get("get").getParameter("body",
null).getSchema());
+ }
+ @Test
+ public void tb18e_Body_onParameter_schema7() throws Exception {
+ assertObjectEquals("{type:'boolean'}", getSwagger(new
TB()).getPaths().get("/schema7").get("get").getParameter("body",
null).getSchema());
+ }
+ @Test
public void tb20_Body_onParameter__default1() throws Exception {
assertObjectEquals("'a'", getSwagger(new
TB()).getPaths().get("/_default1").get("get").getParameter("body",
null).getDefault());
}
@@ -6061,6 +6439,28 @@ public class BasicRestInfoProviderTest {
@RestMethod(name=GET,path="/schema2")
public void ua04b(UA04b r) {}
+ @Response
+ public static class UA04c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void ua04c(UA04c b) {}
+
+ @Response
+ public static class UA04d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void ua04d(UA04d b) {}
+
+ @Response
+ public static class UA04e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void ua04e(UA04e b) {}
+
@Response(headers=" {foo:{type:'a'}} ")
public static class UA05a {}
@@ -6123,6 +6523,18 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("{type:'b'}", getSwagger(new
UA()).getPaths().get("/schema2").get("get").getResponse(200).getSchema());
}
@Test
+ public void ua04c_Response_onPojo_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new
UA()).getPaths().get("/schema3").get("get").getResponse(200).getSchema());
+ }
+ @Test
+ public void ua04d_Response_onPojo_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new
UA()).getPaths().get("/schema4").get("get").getResponse(200).getSchema());
+ }
+ @Test
+ public void ua04e_Response_onPojo_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
UA()).getPaths().get("/schema5").get("get").getResponse(200).getSchema());
+ }
+ @Test
public void ua05a_Response_onPojo_headers1() throws Exception {
assertObjectEquals("{foo:{type:'a'}}", getSwagger(new
UA()).getPaths().get("/headers1").get("get").getResponse(200).getHeaders());
}
@@ -6174,15 +6586,40 @@ public class BasicRestInfoProviderTest {
@RestMethod(name=GET,path="/description2")
public void ub04(@Response(description={"a","b"}) UB04 r) {}
- public static class UB05 {}
+ public static class UB05a {}
@RestMethod(name=GET,path="/schema1")
- public void ub05(@Response(schema=" {type:'a'} ") UB05 r) {}
+ public void ub05a(@Response(schema=" {type:'a'} ") UB05a r) {}
- public static class UB06 {}
+ public static class UB05b {}
@RestMethod(name=GET,path="/schema2")
- public void ub06(@Response(schema={" type:'b' "}) UB06 r) {}
+ public void ub05b(@Response(schema={" type:'b' "}) UB05b r) {}
+
+ public static class UB05c {
+ public String f1;
+ }
+
+ @RestMethod(name=GET,path="/schema3")
+ public void ub05c(@Response UB05c b) {}
+
+ public static class UB05d extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+
+ @RestMethod(name=GET,path="/schema4")
+ public void ub05d(@Response UB05d b) {}
+
+ public static class UB05e {}
+
+ @RestMethod(name=GET,path="/schema5")
+ public void ub05e(@Response UB05e b) {}
+
+ @RestMethod(name=GET,path="/schema6")
+ public void ub05f(@Response Integer b) {}
+
+ @RestMethod(name=GET,path="/schema7")
+ public void ub05g(@Response Boolean b) {}
public static class UB07 {}
@@ -6232,14 +6669,34 @@ public class BasicRestInfoProviderTest {
assertEquals("a\nb", getSwagger(new
UB()).getPaths().get("/description2").get("get").getResponse(200).getDescription());
}
@Test
- public void ub05_Response_onParameter_schema1() throws Exception {
+ public void ub05a_Response_onParameter_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
UB()).getPaths().get("/schema1").get("get").getResponse(200).getSchema());
}
@Test
- public void ub06_Response_onParameter_schema2() throws Exception {
+ public void ub05b_Response_onParameter_schema2() throws Exception {
assertObjectEquals("{type:'b'}", getSwagger(new
UB()).getPaths().get("/schema2").get("get").getResponse(200).getSchema());
}
@Test
+ public void ub05c_Response_onParameter_schema3() throws Exception {
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}",
getSwagger(new
UB()).getPaths().get("/schema3").get("get").getResponse(200).getSchema());
+ }
+ @Test
+ public void ub05d_Response_onParameter_schema4() throws Exception {
+ assertObjectEquals("{type:'array',items:{type:'string'}}",
getSwagger(new
UB()).getPaths().get("/schema4").get("get").getResponse(200).getSchema());
+ }
+ @Test
+ public void ub05e_Response_onParameter_schema5() throws Exception {
+ assertObjectEquals("{type:'string'}", getSwagger(new
UB()).getPaths().get("/schema5").get("get").getResponse(200).getSchema());
+ }
+ @Test
+ public void ub05f_Response_onParameter_schema6() throws Exception {
+ assertObjectEquals("{format:'int32',type:'integer'}",
getSwagger(new
UB()).getPaths().get("/schema6").get("get").getResponse(200).getSchema());
+ }
+ @Test
+ public void ub05g_Response_onParameter_schema7() throws Exception {
+ assertObjectEquals("{type:'boolean'}", getSwagger(new
UB()).getPaths().get("/schema7").get("get").getResponse(200).getSchema());
+ }
+ @Test
public void ub07_Response_onParameter_headers1() throws Exception {
assertObjectEquals("{foo:{type:'a'}}", getSwagger(new
UB()).getPaths().get("/headers1").get("get").getResponse(200).getHeaders());
}
@@ -6297,16 +6754,16 @@ public class BasicRestInfoProviderTest {
public void uc04() throws UC04 {}
@Response(schema=" {type:'a'} ")
- public static class UC05 extends Throwable {}
+ public static class UC05a extends Throwable {}
@RestMethod(name=GET,path="/schema1")
- public void uc05() throws UC05 {}
+ public void uc05a() throws UC05a {}
@Response(schema={" type:'b' "})
- public static class UC06 extends Throwable {}
+ public static class UC05b extends Throwable {}
@RestMethod(name=GET,path="/schema2")
- public void uc06() throws UC06 {}
+ public void uc05b() throws UC05b {}
@Response(headers=" {foo:{type:'a'}} ")
public static class UC07 extends Throwable {}
@@ -6362,11 +6819,11 @@ public class BasicRestInfoProviderTest {
assertEquals("a\nb", getSwagger(new
UC()).getPaths().get("/description2").get("get").getResponse(500).getDescription());
}
@Test
- public void uc05_Response_onThrowable_schema1() throws Exception {
+ public void uc05a_Response_onThrowable_schema1() throws Exception {
assertObjectEquals("{type:'a'}", getSwagger(new
UC()).getPaths().get("/schema1").get("get").getResponse(500).getSchema());
}
@Test
- public void uc06_Response_onThrowable_schema2() throws Exception {
+ public void uc05b_Response_onThrowable_schema2() throws Exception {
assertObjectEquals("{type:'b'}", getSwagger(new
UC()).getPaths().get("/schema2").get("get").getResponse(500).getSchema());
}
@Test
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyTest.java
new file mode 100644
index 0000000..dd76d36
--- /dev/null
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyTest.java
@@ -0,0 +1,147 @@
+//
***************************************************************************************************************************
+// * 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.juneau.rest.annotation;
+
+import static org.apache.juneau.http.HttpMethodName.*;
+import static org.junit.Assert.*;
+
+import javax.servlet.http.*;
+
+import org.apache.juneau.json.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.util.*;
+import org.junit.*;
+import org.junit.runners.*;
+
+@SuppressWarnings("javadoc")
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class BodyTest {
+
+ private void call(Object resource, HttpServletRequest req,
HttpServletResponse res) throws Exception {
+ RestContext rc = RestContext.create(resource).build();
+ rc.getCallHandler().service(req, res);
+ }
+
+
//-----------------------------------------------------------------------------------------------------------------
+ // @Body on parameter
+
//-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource(serializers=JsonSerializer.Simple.class,
parsers=JsonParser.class)
+ public static class A {
+
+ @RestMethod(name=PUT, path="/string")
+ public String a01(@Body String b) {
+ return b;
+ }
+
+ @RestMethod(name=PUT, path="/integer")
+ public Integer a02(@Body Integer b) {
+ return b;
+ }
+
+ @RestMethod(name=PUT, path="/boolean")
+ public Boolean a03(@Body Boolean b) {
+ return b;
+ }
+
+ public static class A04 {
+ public String f1;
+ }
+
+ @RestMethod(name=PUT, path="/bean")
+ public A04 a04(@Body A04 b) {
+ return b;
+ }
+ }
+
+ @Test
+ public void a01_onParameter_string() throws Exception {
+ MockServletRequest req = MockServletRequest.create("PUT",
"/string").body("'foo'");
+ MockServletResponse res = MockServletResponse.create();
+ call(new A(), req, res);
+ assertEquals("'foo'", res.getBodyAsString());
+ }
+ @Test
+ public void a02_onParameter_integer() throws Exception {
+ MockServletRequest req = MockServletRequest.create("PUT",
"/integer").body("123");
+ MockServletResponse res = MockServletResponse.create();
+ call(new A(), req, res);
+ assertEquals("123", res.getBodyAsString());
+ }
+ @Test
+ public void a03_onParameter_boolean() throws Exception {
+ MockServletRequest req = MockServletRequest.create("PUT",
"/boolean").body("true");
+ MockServletResponse res = MockServletResponse.create();
+ call(new A(), req, res);
+ assertEquals("true", res.getBodyAsString());
+ }
+ @Test
+ public void a04_onParameter_bean() throws Exception {
+ MockServletRequest req = MockServletRequest.create("PUT",
"/bean").body("{f1:'a'}");
+ MockServletResponse res = MockServletResponse.create();
+ call(new A(), req, res);
+ assertEquals("{f1:'a'}", res.getBodyAsString());
+ }
+
+
//-----------------------------------------------------------------------------------------------------------------
+ // @Body on POJO
+
//-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource(serializers=JsonSerializer.Simple.class,
parsers=JsonParser.class)
+ public static class B {
+
+ @Body
+ public static class B01 {
+ private String val;
+
+ public B01(String val) {
+ this.val = val;
+ }
+
+ @Override
+ public String toString() {
+ return val;
+ }
+ }
+
+ @RestMethod(name=PUT, path="/string")
+ public B01 simple(B01 b) {
+ return b;
+ }
+
+ @Body
+ public static class B02 {
+ public String f1;
+ }
+
+ @RestMethod(name=PUT, path="/bean")
+ public B02 b02(B02 b) {
+ return b;
+ }
+ }
+
+ @Test
+ public void a01_onPojo_string() throws Exception {
+ MockServletRequest req = MockServletRequest.create("PUT",
"/string").body("'foo'");
+ MockServletResponse res = MockServletResponse.create();
+ call(new B(), req, res);
+ assertEquals("'foo'", res.getBodyAsString());
+ }
+ @Test
+ public void a04_onPojo_bean() throws Exception {
+ MockServletRequest req = MockServletRequest.create("PUT",
"/bean").body("{f1:'a'}");
+ MockServletResponse res = MockServletResponse.create();
+ call(new B(), req, res);
+ assertEquals("{f1:'a'}", res.getBodyAsString());
+ }
+}
--
To stop receiving notification emails like this one, please contact
[email protected].