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 108fc1f  Tests.
108fc1f is described below

commit 108fc1f440e3c6515e492bf0455e5e95ecd2cdad
Author: JamesBognar <[email protected]>
AuthorDate: Sun May 13 18:56:42 2018 -0400

    Tests.
---
 .../java/org/apache/juneau/rest/test/Root.java     |  1 -
 .../org/apache/juneau/rest/test/xdocs2/test.txt    | 13 ---
 .../apache/juneau/rest/test/StaticFilesTest.java   | 93 ----------------------
 .../org/apache/juneau/rest/test/_TestSuite.java    |  1 -
 .../annotation/RestResourceStaticFilesTest.java    | 60 ++++++++++----
 .../apache/juneau/rest/annotation}/xdocs/test.txt  |  0
 .../rest/annotation}/xdocs/xsubdocs/test.txt       |  0
 7 files changed, 46 insertions(+), 122 deletions(-)

diff --git 
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
 
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
index 09f4056..45c5e99 100644
--- 
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
+++ 
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
@@ -40,7 +40,6 @@ import org.apache.juneau.rest.test.client.*;
                RequestBeanProxyResource.class,
                RestClient2Resource.class,
                SerializersResource.class,
-               StaticFilesResource.class,
                ThirdPartyProxyResource.class,
                UrisResource.class,
                ShutdownResource.class,
diff --git 
a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs2/test.txt
 
b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs2/test.txt
deleted file mode 100644
index b734fee..0000000
--- 
a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs2/test.txt
+++ /dev/null
@@ -1,13 +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.  
                                            *
- 
***************************************************************************************************************************
- OK-3
\ No newline at end of file
diff --git 
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/StaticFilesTest.java
 
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/StaticFilesTest.java
deleted file mode 100644
index 4e2167c..0000000
--- 
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/StaticFilesTest.java
+++ /dev/null
@@ -1,93 +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.                                              *
-// 
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.rest.client.*;
-import org.junit.*;
-
-public class StaticFilesTest extends RestTestcase {
-
-       private static String URL = "/testStaticFiles";
-
-       
//====================================================================================================
-       // Tests the @RestResource(staticFiles) annotation.
-       
//====================================================================================================
-       @Test
-       public void testXdocs() throws Exception {
-               RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
-               String r;
-               String url = URL + "/xdocs";
-
-               r = client.doGet(url + "/test.txt").getResponseAsString();
-               assertTrue(r.endsWith("OK-1"));
-               r = client.doGet(url + 
"/xsubdocs/test.txt").getResponseAsString();
-               assertTrue(r.endsWith("OK-2"));
-
-               // For security reasons, paths containing ".." should always 
return 404.
-               try {
-                       client.doGet(url + 
"/xsubdocs/../test.txt?noTrace=true").connect();
-                       fail("404 exception expected");
-               } catch (RestCallException e) {
-                       assertEquals(404, e.getResponseCode());
-               }
-
-               try {
-                       client.doGet(url + 
"/xsubdocs/%2E%2E/test.txt?noTrace=true").connect();
-                       fail("404 exception expected");
-               } catch (RestCallException e) {
-                       assertEquals(404, e.getResponseCode());
-               }
-       }
-
-       
//====================================================================================================
-       // Tests the @RestResource(staticFiles) annotation.
-       
//====================================================================================================
-       @Test
-       public void testXdocsPreventPathTraversal() throws Exception {
-               RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
-               String url = URL + "/xdocs";
-
-               // For security reasons, paths containing ".." should always 
return 404.
-               try {
-                       client.doGet(url + 
"/xsubdocs/../test.txt?noTrace=true").connect();
-                       fail("404 exception expected");
-               } catch (RestCallException e) {
-                       assertEquals(404, e.getResponseCode());
-               }
-
-               try {
-                       client.doGet(url + 
"/xsubdocs/%2E%2E/test.txt?noTrace=true").connect();
-                       fail("404 exception expected");
-               } catch (RestCallException e) {
-                       assertEquals(404, e.getResponseCode());
-               }
-       }
-
-       
//====================================================================================================
-       // Tests the @RestResource(staticFiles) annotation.
-       
//====================================================================================================
-       @Test
-       public void testXdocsWithHeader() throws Exception {
-               RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
-               String r;
-               String url = URL + "/xdocs2";
-
-               r = client.doGet(url + "/test.txt").getResponseAsString();
-               assertTrue(r.endsWith("OK-3"));
-               
-               r = client.doGet(url + "/test.txt").getResponseHeader("Foo");
-               assertEquals("Bar", r);
-       }
-}
diff --git 
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
 
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
index 0105ddf..d99f943 100644
--- 
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
+++ 
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
@@ -39,7 +39,6 @@ import org.junit.runners.Suite.*;
        RequestBeanProxyTest.class,
        RestClientTest.class,
        SerializersTest.class,
-       StaticFilesTest.class,
        ThirdPartyProxyTest.class,
        TransformsTest.class,
 })
diff --git 
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java
 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourceStaticFilesTest.java
similarity index 51%
rename from 
juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java
rename to 
juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourceStaticFilesTest.java
index 1b0856b..46bd897 100644
--- 
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java
+++ 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourceStaticFilesTest.java
@@ -10,28 +10,60 @@
 // * "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.test;
+package org.apache.juneau.rest.annotation;
 
 import static org.apache.juneau.http.HttpMethodName.*;
 
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.mock.*;
+import org.junit.*;
+import org.junit.runners.*;
 
 /**
- * JUnit automated testcase resource.
+ * Tests that validate the behavior of @RestResource(staticFiles).
  */
-@RestResource(
-       path="/testStaticFiles",
-       staticFiles={"xdocs:xdocs","xdocs2:xdocs2:{Foo:'Bar'}"}
-)
-public class StaticFilesResource extends RestServlet {
-       private static final long serialVersionUID = 1L;
+@SuppressWarnings({"javadoc"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class RestResourceStaticFilesTest {
 
        
//====================================================================================================
-       // Tests the @RestResource(staticFiles) annotation.
+       // Basic tests
        
//====================================================================================================
-       @RestMethod(name=GET, path="/*")
-       public String testXdocs() {
-               return null;
+
+       @RestResource(staticFiles={"xdocs:xdocs","xdocs2:xdocs2:{Foo:'Bar'}"})
+       public static class A {
+               @RestMethod(name=GET)
+               public String test() {
+                       return null;
+               }
+       }
+       static MockRest a = MockRest.create(A.class);
+
+       @Test
+       public void a01() throws Exception {
+               a.request("GET", 
"/xdocs/test.txt").execute().assertBodyContains("OK-1");
+               a.request("GET", 
"/xdocs/xsubdocs/test.txt").execute().assertBodyContains("OK-2");
+       }
+       @Test
+       public void a02_preventPathTraversals() throws Exception {
+               a.request("GET", 
"/xdocs/xsubdocs/../test.txt?noTrace=true").execute().assertStatus(404);
+               a.request("GET", 
"/xdocs/xsubdocs/%2E%2E/test.txt?noTrace=true").execute().assertStatus(404);
+       }
+
+       
//====================================================================================================
+       // Static files with response headers.
+       
//====================================================================================================
+
+       @RestResource(staticFiles={"xdocs:xdocs:{Foo:'Bar'}"})
+       public static class B {
+               @RestMethod(name=GET)
+               public String test() {
+                       return null;
+               }
+       }
+       static MockRest b = MockRest.create(B.class);
+
+       @Test
+       public void b01() throws Exception {
+               b.request("GET", 
"/xdocs/test.txt").execute().assertHeader("Foo","Bar").assertBodyContains("OK-1");
        }
 }
diff --git 
a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt
 
b/juneau-rest/juneau-rest-server/src/test/resources/org/apache/juneau/rest/annotation/xdocs/test.txt
similarity index 100%
rename from 
juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt
rename to 
juneau-rest/juneau-rest-server/src/test/resources/org/apache/juneau/rest/annotation/xdocs/test.txt
diff --git 
a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xsubdocs/test.txt
 
b/juneau-rest/juneau-rest-server/src/test/resources/org/apache/juneau/rest/annotation/xdocs/xsubdocs/test.txt
similarity index 100%
rename from 
juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xsubdocs/test.txt
rename to 
juneau-rest/juneau-rest-server/src/test/resources/org/apache/juneau/rest/annotation/xdocs/xsubdocs/test.txt

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to