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 e6c9cf0 Javadocs.
e6c9cf0 is described below
commit e6c9cf0e434e9d88d3bdd3412941e5faa0d4709d
Author: JamesBognar <[email protected]>
AuthorDate: Fri May 29 11:10:03 2020 -0400
Javadocs.
---
juneau-doc/docs/ReleaseNotes/8.1.4.html | 8 +-
juneau-doc/docs/Topics/10.juneau-rest-mock.html | 14 +-
.../Topics/10.juneau-rest-mock/01.MockRest.html | 275 ---------------------
.../10.juneau-rest-mock/01.MockRestClient.html | 162 ++++++++++++
.../Topics/10.juneau-rest-mock/02.MockRemote.html | 126 ----------
5 files changed, 169 insertions(+), 416 deletions(-)
diff --git a/juneau-doc/docs/ReleaseNotes/8.1.4.html
b/juneau-doc/docs/ReleaseNotes/8.1.4.html
index 1d9c4b2..a114811 100644
--- a/juneau-doc/docs/ReleaseNotes/8.1.4.html
+++ b/juneau-doc/docs/ReleaseNotes/8.1.4.html
@@ -477,6 +477,10 @@
</li>p>
</ul>
-<h5 class='topic w800'>juneau-doc</h5>
+<h5 class='topic w800'>juneau-rest-mock</h5>
<ul class='spaced-list'>
-</ul>
+ <li>
+ The <c>MockRest</c> and <c>MockRemote</c> classes have been
remove entirely and all existing functions
+ have been moved into the improved {@link
oajr.mock2.MockRestClient} class. All REST test mocking can be
+ done through this single class.
+</ui>
diff --git a/juneau-doc/docs/Topics/10.juneau-rest-mock.html
b/juneau-doc/docs/Topics/10.juneau-rest-mock.html
index c4969da..7161095 100644
--- a/juneau-doc/docs/Topics/10.juneau-rest-mock.html
+++ b/juneau-doc/docs/Topics/10.juneau-rest-mock.html
@@ -13,7 +13,7 @@
***************************************************************************************************************************/
-->
-{8.1.0-new}
+{8.1.0-new,8.1.4-updated}
juneau-rest-mock
<h5 class='figure'>Maven Dependency</h5>
@@ -41,15 +41,3 @@ juneau-rest-mock
Each of the APIs provide the ability to fully test your server and
client REST interfaces without the
need for a running servlet container.
</p>
-
-<p>
- The API consists of the following classes:
-</p>
-<ul class='javatree'>
- <li class='jp'>{@link oajr.mock2}
- <ul>
- <li class='jc'>{@link oajr.mock2.MockRest} - API for unit
testing {@link oajr.annotation.Rest @Rest}-annotated classes.
- <li class='jc'>{@link oajr.mock2.MockRemote} - API for unit
testing {@link oaj.http.remote.Remote @Remote}-annotated classes.
- </ul>
-</ul>
-
diff --git a/juneau-doc/docs/Topics/10.juneau-rest-mock/01.MockRest.html
b/juneau-doc/docs/Topics/10.juneau-rest-mock/01.MockRest.html
deleted file mode 100644
index 2813d2f..0000000
--- a/juneau-doc/docs/Topics/10.juneau-rest-mock/01.MockRest.html
+++ /dev/null
@@ -1,275 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
-
***************************************************************************************************************************/
- -->
-
-{8.1.0-new}
-MockRest
-
-<p>
- The {@link oajr.mock2.MockRest} class is used for performing serverless
unit testing of {@link oajr.annotation.Rest @Rest}-annotated
- classes. These include both parent resource classes that extend from
{@link oajr.RestServlet} and child resources that do not.
-</p>
-<p>
- The API consists of the following classes:
-</p>
-<ul class='javatree'>
- <li class='jp'>{@link oajr.mock2}
- <ul>
- <li class='jc'>{@link oajr.mock2.MockRest}
- <br>The API for instantiating mocks of REST resource
classes.
- <li class='jc'>{@link oajr.mock2.MockServletRequest}
- <br>An implementation of {@link
javax.servlet.http.HttpServletRequest} with additional convenience methods for
building requests.
- <li class='jc'>{@link oajr.mock2.MockServletResponse}
- <br>An implementation of {@link
javax.servlet.http.HttpServletRequest} with additional convenience methods for
testing responses.
- </ul>
-</ul>
-<p>
- The following shows a simple example of invoking a PUT method on a
simple REST interface and asserting
- the correct status code and response body:
-</p>
-<p class='bpcode w800'>
- <jk>public class</jk> MockTest {
-
- <jc>// Our REST resource to test.</jc>
- <ja>@Rest</ja>(
- serializers=SimpleJsonSerializer.<jk>class</jk>,
- parsers=JsonParser.<jk>class</jk>
- )
- <jk>public static class</jk> EchoRest {
-
- <ja>@RestMethod</ja>(
- name=<jsf>PUT</jsf>,
- path=<js>"/echo"</js>
- )
- <jk>public</jk> String echo(<ja>@Body</ja> String body)
{
- <jk>return</jk> body;
- }
- }
-
- <jc>// Our JUnit test.</jc>
- <ja>@Test</ja>
- <jk>public void</jk> testEcho() <jk>throws</jk> Exception {
-
- MockRest mr =
MockRest.<jsm>build</jsm>(EchoRest.<jk>class</jk>);
-
- mr
- .put(<js>"/echo"</js>, <js>"'foo'"</js>)
- .execute()
- .assertStatus(200)
- .assertBody(<js>"'foo'"</js>);
- }
- }
-</p>
-<p>
- Breaking apart the fluent method call above will help you understand
how this works.
-</p>
-<p class='bpcode w800'>
- <ja>@Test</ja>
- <jk>public void</jk> testEcho() <jk>throws</jk> Exception {
-
- <jc>// Instantiate our mock.</jc>
- MockRest mr =
MockRest.<jsm>build</jsm>(EchoRest.<jk>class</jk>);
-
- <jc>// Create a request.</jc>
- MockServletRequest req = mr.put(<js>"/echo"</js>,
<js>"'foo'"</js>);
-
- <jc>// Execute it (by calling RestCallHandler.service(...) and
then returning the response object).</jc>
- MockServletResponse res = req.execute();
-
- <jc>// Run assertion tests on the results.</jc>
- res.assertStatus(200);
- res.assertBody(<js>"'foo'"</js>);
- }
-</p>
-<p>
- The concept of the design is simple. The {@link oajr.mock2.MockRest}
class is used to create instances of {@link oajr.mock2.MockServletRequest}
- and {@link oajr.mock2.MockServletResponse} which are passed directly to
the call handler on the resource class {@link
oajr.RestCallHandler#execute(HttpServletRequest,HttpServletResponse)}.
- In effect, you're fully testing your REST API as if it were running in
a live servlet container, yet not
- actually having to run in a servlet container.
-</p>
-<p>
- The <c>create(Object)</c> method can take in either <c>Class</c>
objects or pre-instantiated beans.
- The latter is particularly useful for testing Spring beans.
-</p>
-<hr>
-<p>
- By default, the {@link oajr.mock2.MockRest} class specifies the
following request headers:
-</p>
-<p class='bpcode w800'>
- Accept: application/json+simple
- Content-Type: application/json
-</p>
-<p>
- The reason for using <js>"application/json+simple"</js> as the default
is that it significantly simplifies
- testing by allowing you to compare response content with simple Java
strings without having to escape lots
- of quotes:
-</p>
-<p class='bpcode w800'>
- <jc>// Using Simple JSON</jc>
- mr.assertBody(<js>"{foo:'bar':baz:123}"</js>);
-
- <jc>// Using normal JSON</jc>
- mr.assertBody(<js>"{\"foo\":\"bar\",\"baz\":123}"</js>);
-</p>
-<p>
- Other media types headers can be specified via any of the following
methods:
-</p>
-<ul class='javatree'>
- <li class='jm'>{@link oajr.mock2.MockRest#build(Object,Marshall)
build(Object,Marshall)} - Use media types defined on a marshall.
- <li class='jm'>{@link
oajr.mock2.MockRest#build(Object,Serializer,Parser)
build(Object,Serializer,Parser)} - Use media types defined on a serializer and
parser.
- <li class='jm'>{@link oajr.mock2.MockRest.Builder#accept(String)
accept(String)} - Explicitly set the <c>Accept</c> header.
- <li class='jm'>{@link oajr.mock2.MockRest.Builder#contentType(String)
contentType(String)} - Explicitly set the <c>Content-Type</c> header.
-</ul>
-<p>
- Various other convenience methods for common media types are also
provided.
-</p>
-<p>
- The following examples are functionally equivalent for specifying XML
serialization:
-</p>
-<p class='bpcode w800'>
- MockRest mr;
-
- mr = MockRest.<jsm>build</jsm>(EchoRest.<jk>class</jk>,
Xml.<jsf>DEFAULT</jsf>);
-
- mr = MockRest.<jsm>build</jsm>(EchoRest.<jk>class</jk>,
XmlSerializer.<jsf>DEFAULT</jsf>, XmlParser.<jsf>DEFAULT</jsf>);
-
- mr =
MockRest.<jsm>create</jsm>(EchoRest.<jk>class</jk>).marshall(Xml.<jsf>DEFAULT</jsf>).build();
-
- mr =
MockRest.<jsm>create</jsm>(EchoRest.<jk>class</jk>).serializer(XmlSerializer.<jsf>DEFAULT</jsf>).parser(XmlParser.<jsf>DEFAULT</jsf>).build();
-
- mr =
MockRest.<jsm>create</jsm>(EchoRest.<jk>class</jk>).accept(<js>"text/xml"</js>).contentType(<js>"text/xml"</js>).build();
-
- mr = MockRest.<jsm>create</jsm>(EchoRest.<jk>class</jk>).xml().build();
-</p>
-<hr>
-<p>
- The {@link oajr.mock2.MockRest} class provides the following methods
for creating requests:
-</p>
-<ul class='javatree'>
- <li class='jc'>{@link oajr.mock2.MockRest}
- <ul>
- <li class='jm'>{@link
oajr.mock2.MockRest#request(String,String) request(String,String)}
- <li class='jm'>{@link
oajr.mock2.MockRest#request(String,String,Object)
request(String,String,Object)}
- <li class='jm'>{@link oajr.mock2.MockRest#get(String)
get(String)}
- <li class='jm'>{@link oajr.mock2.MockRest#put(String,Object)
put(String,Object)}
- <li class='jm'>{@link oajr.mock2.MockRest#post(String,Object)
post(String,Object)}
- <li class='jm'>{@link oajr.mock2.MockRest#delete(String)
delete(String)}
- <li class='jm'>{@link oajr.mock2.MockRest#patch(String,Object)
patch(String,Object)}
- <li class='jm'>{@link oajr.mock2.MockRest#options(String)
options(String)}
- </ul>
-</ul>
-<p>
- For HTTP methods that pass a request body (i.e.
<c>PUT</c>,<c>POST</c><c>PATCH</c>), the body object can be any of the
following types:
-</p>
-<ul>
- <li><c><jk>byte</jk>[]</c>
- <li>{@link java.io.Reader}
- <li>{@link java.io.InputStream}
- <li>{@link java.lang.CharSequence}
-</ul>
-<p>
- All other body object types are converted to strings using the
<c>toString()</c> method.
-</p>
-<p>
- A common tactic is to override a bean's <c>toString()</c> method to
return Simple JSON so that
- instances can be passed to the methods above.
-</p>
-<p class='bpcode w800'>
- <jk>public class</jk> MyBean {
-
- ...
-
- <ja>@Override</ja>
- <jk>public</jk> String toString() {
- SimpleJson.<jsf>DEFAULT</jsf>.toString(<jk>this</jk>);
- }
- }
-</p>
-<p>
- The {@link oajr.mock2.MockServletRequest} class provides default
implementations for all the methods defined
- on the {@link javax.servlet.http.HttpServletRequest} in addition to
many convenience methods.
-</p>
-<p>
- The following fluent convenience methods are provided for setting
common <c>Accept</c> and <c>Content-Type</c> headers.
-</p>
-<ul class='javatree'>
- <li class='jc'>{@link oajr.mock2.MockServletRequest}
- <ul>
- <li class='jm'>{@link oajr.mock2.MockServletRequest#json()
json()}
- <li class='jm'>{@link oajr.mock2.MockServletRequest#xml() xml()}
- <li class='jm'>{@link oajr.mock2.MockServletRequest#html()
html()}
- <li class='jm'>{@link oajr.mock2.MockServletRequest#plainText()
plainText()}
- <li class='jm'>{@link oajr.mock2.MockServletRequest#msgpack()
msgpack()}
- <li class='jm'>{@link oajr.mock2.MockServletRequest#uon() uon()}
- <li class='jm'>{@link oajr.mock2.MockServletRequest#urlEnc()
urlEnc()}
- <li class='jm'>{@link oajr.mock2.MockServletRequest#yaml()
yaml()}
- </ul>
-</ul>
-<p>
- The following fluent convenience methods are provided for building up
your request.
-</p>
-<ul class='javatree'>
- <li class='jc'>{@link oajr.mock2.MockServletRequest}
- <ul>
- <li class='jm'>{@link
oajr.mock2.MockServletRequest#header(String,Object) header(String,Object)}
- <li class='jm'>{@link
oajr.mock2.MockServletRequest#query(String,Object) query(String,Object}}
- <li class='jm'>{@link
oajr.mock2.MockServletRequest#formData(String,Object) formData(String,Object)}
- <li class='jm'>{@link
oajr.mock2.MockServletRequest#attribute(String,Object) attribute(String,Object)}
- <li class='jm'>{@link
oajr.mock2.MockServletRequest#body(Object) body(Object)}
- </ul>
-</ul>
-<p>
- Fluent setters are provided for all common request headers:
-</p>
-<ul class='javatree'>
- <li class='jc'>{@link oajr.mock2.MockServletRequest}
- <ul>
- <li class='jm'>{@link
oajr.mock2.MockServletRequest#accept(Object) accept(Object)}
- <li class='jm'>{@link
oajr.mock2.MockServletRequest#acceptCharset(Object) acceptCharset(Object)}
- <li class='jm'>{@link
oajr.mock2.MockServletRequest#acceptEncoding(Object) acceptEncoding(Object)}
- <li class='jm'>{@link
oajr.mock2.MockServletRequest#acceptLanguage(Object) acceptLanguage(Object)}
- <li class='jm'>...
- </ul>
-</ul>
-<p>
- The {@link oajr.mock2.MockServletResponse} class provides default
implementations for all the methods defined
- on the {@link javax.servlet.http.HttpServletResponse} in addition to
many convenience methods.
-</p>
-<ul class='javatree'>
- <li class='jc'>{@link oajr.mock2.MockServletResponse}
- <ul>
- <li class='jm'>{@link oajr.mock2.MockServletResponse#getBody()
getBody()}
- <li class='jm'>{@link
oajr.mock2.MockServletResponse#getBodyAsString() getBodyAsString()}
- <li class='jm'>{@link
oajr.mock2.MockServletResponse#assertStatus(int) assertStatus(int)}
- <li class='jm'>{@link
oajr.mock2.MockServletResponse#assertBody(String) assertBody(String)}
- <li class='jm'>{@link
oajr.mock2.MockServletResponse#assertBodyContains(String...)
assertBodyContains(String...)}
- <li class='jm'>{@link
oajr.mock2.MockServletResponse#assertBodyMatches(String)
assertBodyMatches(String)}
- <li class='jm'>{@link
oajr.mock2.MockServletResponse#assertBodyMatchesRE(String)
assertBodyMatchesRE(String)}
- <li class='jm'>{@link
oajr.mock2.MockServletResponse#assertHeader(String,String)
assertHeader(String,String)}
- <li class='jm'>{@link
oajr.mock2.MockServletResponse#assertHeaderContains(String,String...)
assertHeaderContains(String,String...)}
- </ul>
-</ul>
-<hr>
-<p>
- The {@link oajr.mock2.MockRest} class has a debug mode that will cause
your HTTP requests and responses to
- be sent to the console:
-</p>
-<p class='bpcode w800'>
- MockRest mr = MockRest
- .<jsm>create</jsm>(MyRest.<jk>class</jk>)
- .debug()
- .simpleJson()
- .build();
-</p>
-
diff --git a/juneau-doc/docs/Topics/10.juneau-rest-mock/01.MockRestClient.html
b/juneau-doc/docs/Topics/10.juneau-rest-mock/01.MockRestClient.html
new file mode 100644
index 0000000..fed94f7
--- /dev/null
+++ b/juneau-doc/docs/Topics/10.juneau-rest-mock/01.MockRestClient.html
@@ -0,0 +1,162 @@
+<!--
+/***************************************************************************************************************************
+ * 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.
+
***************************************************************************************************************************/
+ -->
+
+{8.1.4-new}
+MockRestClient
+
+<p>
+ The {@link oajr.mock2.MockRestClient} class is used for performing
serverless unit testing of {@link oajr.annotation.Rest @Rest}-annotated
+ and {@link aoj.http.remote.Remote @Remote}-annotated classes.
+</p>
+<p>
+ The {@link oajr.mock2.MockRestClient} itself extends from {@link
oajr.client.RestClient} providing it with the rich
+ feature set of that API.
+ The following shows a simple example of invoking a PUT method on a
simple REST interface and asserting
+ the correct status code and response body:
+</p>
+<p class='bpcode w800'>
+ <jk>public class</jk> MockTest {
+
+ <jc>// A simple bean with one field.</jc>
+ <jk>public static class</jk> MyBean {
+ <jk>public int</jk> <jf>foo</jf> = 1;
+ }
+
+ <jc>// Our REST resource to test.</jc>
+ <jc>// Simply echos the response.</jc>
+ <ja>@Rest</ja>(
+ serializers=SimpleJsonSerializer.<jk>class</jk>,
+ parsers=JsonParser.<jk>class</jk>
+ )
+ <jk>public static class</jk> EchoRest {
+
+ <ja>@RestMethod</ja>(
+ name=<jsf>PUT</jsf>,
+ path=<js>"/echo"</js>
+ )
+ <jk>public</jk> MyBean echo(<ja>@Body</ja> MyBean bean)
{
+ <jk>return</jk> bean;
+ }
+ }
+
+ <jc>// Our JUnit test.</jc>
+ <ja>@Test</ja>
+ <jk>public void</jk> testEcho() <jk>throws</jk> Exception {
+
+ MyBean myBean = <jk>new</jk> MyBean();
+
+ <jc>// Do a round-trip on the bean through the REST
interface</jc>
+ myBean = MockRestClient
+ .<jsm>create</jsm>(EchoRest.<jk>class</jk>)
+ .simpleJson()
+ .build()
+ .put(<js>"/echo"</js>, myBean)
+ .run()
+ .assertStatus().is(200)
+ .assertBody().is(<js>"{foo:1}"</js>)
+ .getBody().as(MyBean.<jk>class</jk>);
+
+ <jsm>assertEquals</jsm>(1, myBean.<jf>foo</jf>);
+ }
+ }
+</p>
+<p>
+ Breaking apart the fluent method call above will help you understand
how this works.
+</p>
+<p class='bpcode w800'>
+ <ja>@Test</ja>
+ <jk>public void</jk> testEcho() <jk>throws</jk> Exception {
+
+ <jc>// Instantiate our mock client.</jc>
+ MockRestClient client = MockRestClient
+ .<jsm>create</jsm>(EchoRest.<jk>class</jk>)
+ .simpleJson()
+ .build();
+
+ <jc>// Create a request.</jc>
+ RestRequest req = client.put(<js>"/echo"</js>, myBean);
+
+ <jc>// Execute it (by calling RestCallHandler.service(...) and
then returning the response object).</jc>
+ RestResponse res = req.run();
+
+ <jc>// Run assertion tests on the results.</jc>
+ res.assertStatus().is(200);
+ res.assertBody().is(<js>"'foo'"</js>);
+
+ myBean = res.getBody().as(MyBean.<jk>class</jk>);
+ }
+</p>
+<p>
+ The concept of the design is simple. The {@link
oajr.mock2.MockRestClient} class is used to create instances of {@link
oajr.mock2.MockServletRequest}
+ and {@link oajr.mock2.MockServletResponse} which are passed directly to
the call handler on the resource class {@link
oajr.RestCallHandler#execute(HttpServletRequest,HttpServletResponse)}.
+ In effect, you're fully testing your REST API as if it were running in
a live servlet container, yet not
+ actually having to run in a servlet container.
+ All aspects of the client and server side code are tested, yet no
servlet container is required. The actual
+ over-the-wire transmission is the only aspect being bypassed.
+</p>
+<p>
+ The <c>create(Object)</c> method can take in either <c>Class</c>
objects or pre-instantiated beans.
+ The latter is particularly useful for testing Spring beans.
+</p>
+<hr>
+<p>
+ The {@link oajr.mock2.MockRestClient} class has a debug mode that will
cause your HTTP requests and responses to
+ be sent to the console:
+</p>
+<p class='bpcode w800'>
+ MockRestClient mr = MockRestClient
+ .<jsm>create</jsm>(MyRest.<jk>class</jk>)
+ .debug()
+ .simpleJson()
+ .build();
+</p>
+<hr>
+<p>
+ The {@link oajr.mock2.MockRestclient} class can also be used for
testing of {@link oaj.http.annotation.Remote}-annotated
+ interfaces against {@link oajr.annotation.Rest @Rest}-annotated
resources.
+</p>
+<h5 class='figure'>Example:</h5>
+<p class='bpcode w800'>
+ <jc>// Our remote resource to test.</jc>
+ <ja>@Remote</ja>
+ <jk>public interface</jk> MyRemoteInterface {
+
+ <ja>@RemoteMethod</ja>(httpMethod=<js>"GET"</js>,
path=<js>"/echoQuery"</js>)
+ <jk>public int</jk>
echoQuery(<ja>@Query</ja>(name=<js>"id"</js>) <jk>int</jk> id);
+ }
+
+ <jc>// Our mocked-up REST interface to test against.</jc>
+ <ja>@Rest</ja>
+ <jk>public class</jk> MyRest {
+
+ <ja>@RestMethod</ja>(name=GET, path=<js>"/echoQuery"</js>)
+ <jk>public int</jk> echoQuery(<ja>@Query</ja>(<js>"id"</js>)
String id) {
+ <jk>return</jk> id;
+ }
+ }
+
+ <ja>@Test</ja>
+ <jk>public void</jk> testProxy() {
+ MyRemoteInterface mri = MockRestClient
+ .create(MyRest.<jk>class</jk>)
+ .json()
+ .build()
+ .getRemote(MyRemoteInterface.<jk>class</jk>);
+
+ <jsm>assertEquals</jsm>(123, mri.echoQuery(123));
+ }
+</p>
+
+
diff --git a/juneau-doc/docs/Topics/10.juneau-rest-mock/02.MockRemote.html
b/juneau-doc/docs/Topics/10.juneau-rest-mock/02.MockRemote.html
deleted file mode 100644
index 7990ffe..0000000
--- a/juneau-doc/docs/Topics/10.juneau-rest-mock/02.MockRemote.html
+++ /dev/null
@@ -1,126 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
-
***************************************************************************************************************************/
- -->
-
-{8.1.0-new, 8.1.2-updated,8.1.4-updated}
-MockRemote
-
-<p>
- The {@link oajr.mock2.MockRemote} class is used for serverless unit
testing of {@link oaj.http.remote.Remote @Remote}-annotated
- classes.
-</p>
-<p>
- The {@link oajr.mock2.MockRemote} API requires a {@link
oajr.annotation.Rest @Rest}-annotated class to be used as
- an underlying mocked resource to process the request and return a
response.
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <jc>// Our remote resource to test.</jc>
- <ja>@Remote</ja>
- <jk>public interface</jk> MyRemoteInterface {
-
- <ja>@RemoteMethod</ja>(httpMethod=<js>"GET"</js>,
path=<js>"/echoQuery"</js>)
- <jk>public int</jk>
echoQuery(<ja>@Query</ja>(name=<js>"id"</js>) <jk>int</jk> id);
- }
-
- <jc>// Our mocked-up REST interface to test against.</jc>
- <ja>@Rest</ja>
- <jk>public class</jk> MyRest {
-
- <ja>@RestMethod</ja>(name=GET, path=<js>"/echoQuery"</js>)
- <jk>public int</jk> echoQuery(<ja>@Query</ja>(<js>"id"</js>)
String id) {
- <jk>return</jk> id;
- }
- }
-
- <ja>@Test</ja>
- <jk>public void</jk> testProxy() {
- MyRemoteInterface mri =
MockRemote.buildJson(MyRemoteInterface.<jk>class</jk>, MyRest.<jk>class</jk>);
- <jsm>assertEquals</jsm>(123, mri.echoQuery(123));
- }
-</p>
-<p>
- It looks simple, but there's a lot going on here.
-</p>
-<p>
- Remote resource interfaces are normally created through the {@link
oajr.client2.RestClient#getRemote(Class)} method.
- The {@link oajr.mock2.MockRemote} will create a {@link
oajr.client2.RestClient} using a specialized <c>HttpClientConnectionManager</c>
- designed to transform client-side
<c>HttpRequest</c>/<c>HttpResponse</c> objects into server-side
- {@link oajr.mock2.MockServletRequest}/{@link
oajr.mock2.MockServletResponse} objects and then pass those to the {@link
oajr.mock2.MockRest}
- object described in the previous section.
-</p>
-<p>
- All aspects of the client and server side code are tested, yet no
servlet container is required. The actual
- over-the-wire serialization is the only aspect being bypassed.
-</p>
-<hr>
-<p>
- By default, the {@link oajr.mock2.MockRemote#buildJson(Class,Object)}
method uses JSON marshalling.
- Other types of marshalling can be used with the following methods:
-</p>
-<ul class='javatree'>
- <li class='jc'>{@link oajr.mock2.MockRemote}
- <ul>
- <li class='jm'>{@link
oajr.mock2.MockRemote#buildSimpleJson(Class,Object)
buildSimpleJson(Class,Object)} - Simplified JSON
- <li class='jm'>{@link
oajr.mock2.MockRemote#create(Class,Object) create(Class,Object)} - Select
language through further setters.
- <li class='jm'>{@link oajr.mock2.MockRemote#html() html()}
- <li class='jm'>{@link oajr.mock2.MockRemote#htmlParser()
htmlParser()}
- <li class='jm'>{@link oajr.mock2.MockRemote#htmlSerializer()
htmlSerializer()}
- <li class='jm'>{@link oajr.mock2.MockRemote#json() json()}
- <li class='jm'>{@link oajr.mock2.MockRemote#jsonParser()
jsonParser()}
- <li class='jm'>{@link oajr.mock2.MockRemote#jsonSerializer()
jsonSerializer()}
- <li class='jm'>{@link oajr.mock2.MockRemote#marshall(Marshall)
marshall(Marshall)}
- <li class='jm'>{@link oajr.mock2.MockRemote#msgPack()
msgPack()}
- <li class='jm'>{@link oajr.mock2.MockRemote#msgPackParser()
msgPackParser()}
- <li class='jm'>{@link oajr.mock2.MockRemote#msgPackSerializer()
msgPackSerializer()}
- <li class='jm'>{@link oajr.mock2.MockRemote#openApi()
openApi()}
- <li class='jm'>{@link oajr.mock2.MockRemote#openApiParser()
openApiParser()}
- <li class='jm'>{@link oajr.mock2.MockRemote#openApiSerializer()
openApiSerializer()}
- <li class='jm'>{@link oajr.mock2.MockRemote#parser(Class)
parser(Class)}
- <li class='jm'>{@link oajr.mock2.MockRemote#parser(Parser)
parser(Parser)}
- <li class='jm'>{@link oajr.mock2.MockRemote#plainText()
plainText()}
- <li class='jm'>{@link oajr.mock2.MockRemote#plainTextParser()
plainTextParser()}
- <li class='jm'>{@link
oajr.mock2.MockRemote#plainTextSerializer() plainTextSerializer()}
- <li class='jm'>{@link oajr.mock2.MockRemote#serializer(Class)
serializer(Class)}
- <li class='jm'>{@link
oajr.mock2.MockRemote#serializer(Serializer) serializer(Serializer)}
- <li class='jm'>{@link oajr.mock2.MockRemote#simpleJson()
simpleJson()}
- <li class='jm'>{@link oajr.mock2.MockRemote#simpleJsonParser()
simpleJsonParser()}
- <li class='jm'>{@link
oajr.mock2.MockRemote#simpleJsonSerializer() simpleJsonSerializer()}
- <li class='jm'>{@link oajr.mock2.MockRemote#uon() uon()}
- <li class='jm'>{@link oajr.mock2.MockRemote#uonParser()
uonParser()}
- <li class='jm'>{@link oajr.mock2.MockRemote#uonSerializer()
uonSerializer()}
- <li class='jm'>{@link oajr.mock2.MockRemote#urlEnc() urlEnc()}
- <li class='jm'>{@link oajr.mock2.MockRemote#urlEncParser()
urlEncParser()}
- <li class='jm'>{@link oajr.mock2.MockRemote#urlEncSerializer()
urlEncSerializer()}
- <li class='jm'>{@link oajr.mock2.MockRemote#xml() xml()}
- <li class='jm'>{@link oajr.mock2.MockRemote#xmlParser()
#xmlParser()}
- <li class='jm'>{@link oajr.mock2.MockRemote#xmlSerializer()
#xmlSerializer()}
- </ul>
-</ul>
-<hr>
-<p>
- The {@link oajr.mock2.MockRemote} class has a debug mode that will
cause your HTTP requests and responses to
- be sent to the console on both the client and server sides:
-</p>
-<p class='bpcode w800'>
- <ja>@Test</ja>
- <jk>public void</jk> testProxy() {
- MyRemoteInterface mri = MockRemote
- .create(MyRemoteInterface.<jk>class</jk>,
MyRest.<jk>class</jk>)
- .debug()
- .build();
- <jsm>assertEquals</jsm>(123, mri.echoQuery(123));
- }
-</p>
-