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 1b16b12  Tests.
1b16b12 is described below

commit 1b16b12a633ac4aab9f0216c1178d7be0bf0bfa1
Author: JamesBognar <[email protected]>
AuthorDate: Sun May 13 16:28:54 2018 -0400

    Tests.
---
 .../rest/test/OptionsWithoutNlsResource.java       |  46 ------
 .../rest/test/OverlappingMethodsResource.java      | 148 ------------------
 .../java/org/apache/juneau/rest/test/Root.java     |   2 -
 .../juneau/rest/test/OptionsWithoutNlsTest.java    |  45 ------
 .../juneau/rest/test/OverlappingMethodsTest.java   | 170 ---------------------
 .../org/apache/juneau/rest/test/_TestSuite.java    |   2 -
 .../test/java/org/apache/juneau/rest/NlsTest.java  |  43 +++++-
 .../RestMethodGuardsTest.java}                     |  73 ++++-----
 .../RestMethodMatchersTest.java}                   |  90 ++++++-----
 .../RestMethodPathTest.java}                       |  97 ++++++------
 10 files changed, 175 insertions(+), 541 deletions(-)

diff --git 
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OptionsWithoutNlsResource.java
 
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OptionsWithoutNlsResource.java
deleted file mode 100644
index 023815b..0000000
--- 
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OptionsWithoutNlsResource.java
+++ /dev/null
@@ -1,46 +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.apache.juneau.http.HttpMethodName.*;
-
-import org.apache.juneau.dto.swagger.*;
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
-       path="/testOptionsWithoutNls",
-       title="test"
-)
-public class OptionsWithoutNlsResource extends BasicRestServlet {
-       private static final long serialVersionUID = 1L;
-
-       
//====================================================================================================
-       // Should get to the options page without errors
-       
//====================================================================================================
-       @RestMethod(name=OPTIONS, path="/testOptions/*", description="test")
-       public Swagger testOptions(RestRequest req) {
-               return req.getSwagger();
-       }
-
-       
//====================================================================================================
-       // Missing resource bundle should cause {!!x} string.
-       
//====================================================================================================
-       @RestMethod(name=GET, path="/testMissingResourceBundle")
-       public String test(RestRequest req) {
-               return req.getMessage("bad", 1, 2, 3);
-       }
-}
diff --git 
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OverlappingMethodsResource.java
 
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OverlappingMethodsResource.java
deleted file mode 100644
index 3673ee1..0000000
--- 
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OverlappingMethodsResource.java
+++ /dev/null
@@ -1,148 +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.apache.juneau.http.HttpMethodName.*;
-
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
-       path="/testOverlappingMethods",
-       serializers=PlainTextSerializer.class
-)
-public class OverlappingMethodsResource extends BasicRestServlet {
-       private static final long serialVersionUID = 1L;
-
-       
//====================================================================================================
-       // Overlapping guards
-       
//====================================================================================================
-       @RestMethod(name=GET, path="/testOverlappingGuards1", 
guards=Test1Guard.class)
-       public String testOverlappingGuards1() {
-               return "test1_doGet";
-       }
-
-       
//====================================================================================================
-       // Overlapping guards
-       
//====================================================================================================
-       @RestMethod(name=GET, path="/testOverlappingGuards2", 
guards={Test1Guard.class, Test2Guard.class})
-       public String testOverlappingGuards2() {
-               return "test2_doGet";
-       }
-
-       public static class Test1Guard extends RestGuard {
-               @Override /* RestGuard */
-               public boolean isRequestAllowed(RestRequest req) {
-                       return req.getQuery().getString("t1","").equals("1");
-               }
-       }
-
-       public static class Test2Guard extends RestGuard {
-               @Override /* RestGuard */
-               public boolean isRequestAllowed(RestRequest req) {
-                       return req.getQuery().getString("t2","").equals("2");
-               }
-       }
-
-       
//====================================================================================================
-       // Overlapping matchers
-       
//====================================================================================================
-       @RestMethod(name=GET, path="/testOverlappingMatchers1", 
matchers=Test3aMatcher.class)
-       public String testOverlappingMatchers1() {
-               return "test3a";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingMatchers1", 
matchers=Test3bMatcher.class)
-       public String test3b_doGet() {
-               return "test3b";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingMatchers1")
-       public String test3c_doGet() {
-               return "test3c";
-       }
-
-       public static class Test3aMatcher extends RestMatcher {
-               @Override /* RestMatcher */
-               public boolean matches(RestRequest req) {
-                       return req.getQuery().getString("t1","").equals("1");
-               }
-       }
-
-       public static class Test3bMatcher extends RestMatcher {
-               @Override /* RestMatcher */
-               public boolean matches(RestRequest req) {
-                       return req.getQuery().getString("t2","").equals("2");
-               }
-       }
-
-       
//====================================================================================================
-       // Overlapping matchers
-       
//====================================================================================================
-       @RestMethod(name=GET, path="/testOverlappingMatchers2")
-       public String test4a_doGet() {
-               return "test4a";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingMatchers2", 
matchers={Test3aMatcher.class, Test3bMatcher.class})
-       public String test4b_doGet() {
-               return "test4b";
-       }
-
-       
//====================================================================================================
-       // Overlapping URL patterns
-       
//====================================================================================================
-       @RestMethod(name=GET, path="/testOverlappingUrlPatterns")
-       public String testOverlappingUrlPatterns1() {
-               return "test5a";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingUrlPatterns/*")
-       public String testOverlappingUrlPatterns2() {
-               return "test5b";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingUrlPatterns/foo")
-       public String testOverlappingUrlPatterns3() {
-               return "test5c";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingUrlPatterns/foo/*")
-       public String testOverlappingUrlPatterns4() {
-               return "test5d";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingUrlPatterns/{id}")
-       public String testOverlappingUrlPatterns5() {
-               return "test5e";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingUrlPatterns/{id}/*")
-       public String testOverlappingUrlPatterns6() {
-               return "test5f";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingUrlPatterns/{id}/foo")
-       public String testOverlappingUrlPatterns7() {
-               return "test5g";
-       }
-
-       @RestMethod(name=GET, path="/testOverlappingUrlPatterns/{id}/foo/*")
-       public String testOverlappingUrlPatterns8() {
-               return "test5h";
-       }
-}
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 de2a8fe..7d3cc7b 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
@@ -35,8 +35,6 @@ import org.apache.juneau.rest.test.client.*;
                HtmlDocLinksResource.class,
                InterfaceProxyResource.class,
                LargePojosResource.class,
-               OptionsWithoutNlsResource.class,
-               OverlappingMethodsResource.class,
                ParsersResource.class,
                PathResource.class,
                PathsResource.class,
diff --git 
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OptionsWithoutNlsTest.java
 
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OptionsWithoutNlsTest.java
deleted file mode 100644
index ce34166..0000000
--- 
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OptionsWithoutNlsTest.java
+++ /dev/null
@@ -1,45 +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.dto.swagger.*;
-import org.apache.juneau.rest.client.*;
-import org.junit.*;
-
-public class OptionsWithoutNlsTest extends RestTestcase {
-
-       private static String URL = "/testOptionsWithoutNls";
-       private RestClient client = TestMicroservice.DEFAULT_CLIENT;
-
-       
//====================================================================================================
-       // Should get to the options page without errors
-       
//====================================================================================================
-       @Test
-       public void testOptions() throws Exception {
-               RestCall r = client.doOptions(URL + "/testOptions");
-               Swagger o = r.getResponse(Swagger.class);
-               assertNotNull(o.getInfo());
-       }
-
-       
//====================================================================================================
-       // Missing resource bundle should cause {!!x} string.
-       
//====================================================================================================
-       @Test
-       public void testMissingResourceBundle() throws Exception {
-               RestCall r = client.doGet(URL + "/testMissingResourceBundle");
-               String o = r.getResponse(String.class);
-               assertEquals("{!!bad}", o);
-       }
-}
diff --git 
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OverlappingMethodsTest.java
 
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OverlappingMethodsTest.java
deleted file mode 100644
index 313fd7f..0000000
--- 
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/OverlappingMethodsTest.java
+++ /dev/null
@@ -1,170 +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 javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.microservice.testutils.TestUtils.*;
-import static org.junit.Assert.*;
-
-import org.apache.juneau.rest.client.*;
-import org.junit.*;
-
-public class OverlappingMethodsTest extends RestTestcase {
-
-       private static String URL = "/testOverlappingMethods";
-       private static boolean debug = false;
-
-       
//====================================================================================================
-       // Overlapping guards
-       
//====================================================================================================
-       @Test
-       public void testOverlappingGuards1() throws Exception {
-               RestClient client = 
TestMicroservice.client().accept("text/plain").build();
-               String r;
-               String url = URL + "/testOverlappingGuards1";
-
-               r = client.doGet(url + "?t1=1").getResponseAsString();
-               assertEquals("test1_doGet", r);
-
-               try {
-                       client.doGet(url + "?noTrace=true").connect();
-                       fail("Exception expected");
-               } catch (RestCallException e) {
-                       checkErrorResponse(debug, e, SC_FORBIDDEN, "Access 
denied by guard");
-               }
-
-               client.closeQuietly();
-       }
-
-       
//====================================================================================================
-       // Overlapping guards
-       
//====================================================================================================
-       @Test
-       public void testOverlappingGuards2() throws Exception {
-               RestClient client = 
TestMicroservice.client().accept("text/plain").build();
-               String r;
-               String url = URL + "/testOverlappingGuards2";
-               try {
-                       client.doGet(url + "?noTrace=true").connect();
-                       fail("Exception expected");
-               } catch (RestCallException e) {
-                       checkErrorResponse(debug, e, SC_FORBIDDEN, "Access 
denied by guard");
-               }
-
-               try {
-                       client.doGet(url + "?t1=1&noTrace=true").connect();
-                       fail("Exception expected");
-               } catch (RestCallException e) {
-                       checkErrorResponse(debug, e, SC_FORBIDDEN, "Access 
denied by guard");
-               }
-
-               try {
-                       client.doGet(url + "?t2=2&noTrace=true").connect();
-                       fail("Exception expected");
-               } catch (RestCallException e) {
-                       checkErrorResponse(debug, e, SC_FORBIDDEN, "Access 
denied by guard");
-               }
-
-               r = client.doGet(url + "?t1=1&t2=2").getResponseAsString();
-               assertEquals("test2_doGet", r);
-
-               client.closeQuietly();
-       }
-
-       
//====================================================================================================
-       // Overlapping matchers
-       
//====================================================================================================
-       @Test
-       public void testOverlappingMatchers1() throws Exception {
-               RestClient client = 
TestMicroservice.client().accept("text/plain").build();
-               String r;
-               String url = URL + "/testOverlappingMatchers1";
-
-               r = client.doGet(url + "?t1=1").getResponseAsString();
-               assertEquals("test3a", r);
-
-               r = client.doGet(url + "?t2=2").getResponseAsString();
-               assertEquals("test3b", r);
-
-               r = client.doGet(url).getResponseAsString();
-               assertEquals("test3c", r);
-
-               client.closeQuietly();
-       }
-
-       
//====================================================================================================
-       // Overlapping matchers
-       
//====================================================================================================
-       @Test
-       public void testOverlappingMatchers2() throws Exception {
-               RestClient client = 
TestMicroservice.client().accept("text/plain").build();
-               String r;
-               String url = URL + "/testOverlappingMatchers2";
-
-               r = client.doGet(url + "?t1=1").getResponseAsString();
-               assertEquals("test4b", r);
-
-               r = client.doGet(url + "?t2=2").getResponseAsString();
-               assertEquals("test4b", r);
-
-               r = client.doGet(url + "?t1=1&t2=2").getResponseAsString();
-               assertEquals("test4b", r);
-
-               r = client.doGet(url + "?tx=x").getResponseAsString();
-               assertEquals("test4a", r);
-
-               client.closeQuietly();
-       }
-
-       
//====================================================================================================
-       // Overlapping URL patterns
-       
//====================================================================================================
-       @Test
-       public void testOverlappingUrlPatterns() throws Exception {
-               RestClient client = 
TestMicroservice.client().accept("text/plain").build();
-               String r;
-               String url = URL + "/testOverlappingUrlPatterns";
-
-               // [/test5] = [test5a]
-               // [/test5/*] = [test5b]   -- Cannot get called.
-               // [/test5/foo] = [test5c]
-               // [/test5/foo/*] = [test5d]
-               // [/test5/{id}] = [test5e]
-               // [/test5/{id}/*] = [test5f]
-               // [/test5/{id}/foo] = [test5g]
-               // [/test5/{id}/foo/*] = [test5h]
-
-               r = client.doGet(url).getResponseAsString();
-               assertEquals("test5a", r);
-
-               r = client.doGet(url + "/foo").getResponseAsString();
-               assertEquals("test5c", r);
-
-               r = client.doGet(url + "/foo/x").getResponseAsString();
-               assertEquals("test5d", r);
-
-               r = client.doGet(url + "/x").getResponseAsString();
-               assertEquals("test5e", r);
-
-               r = client.doGet(url + "/x/x").getResponseAsString();
-               assertEquals("test5f", r);
-
-               r = client.doGet(url + "/x/foo").getResponseAsString();
-               assertEquals("test5g", r);
-
-               r = client.doGet(url + "/x/foo/x").getResponseAsString();
-               assertEquals("test5h", r);
-
-               client.closeQuietly();
-       }
-}
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 ecca8bf..dd1f200 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
@@ -34,8 +34,6 @@ import org.junit.runners.Suite.*;
        InterfaceProxyTest.class,
        JacocoDummyTest.class,
        LargePojosTest.class,
-       OptionsWithoutNlsTest.class,
-       OverlappingMethodsTest.class,
        ParsersTest.class,
        PathsTest.class,
        PathTest.class,
diff --git 
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
index c62b6e9..2c7e673 100644
--- 
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
+++ 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
@@ -15,6 +15,7 @@ package org.apache.juneau.rest;
 import static org.apache.juneau.http.HttpMethodName.*;
 
 import org.apache.juneau.*;
+import org.apache.juneau.dto.swagger.*;
 import org.apache.juneau.rest.annotation.*;
 import org.apache.juneau.rest.mock.*;
 import org.apache.juneau.serializer.*;
@@ -28,9 +29,9 @@ import org.junit.runners.*;
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class NlsTest {
 
-       
//====================================================================================================
+       
//=================================================================================================================
        // Test getting an NLS property defined on a class or method.
-       
//====================================================================================================
+       
//=================================================================================================================
 
        @RestResource(
                serializers={A01.class},
@@ -75,4 +76,42 @@ public class NlsTest {
        public void a02_fromMethod() throws Exception {
                a.request("GET", "/fromMethod").execute().assertBody("value2");
        }
+       
+       
//=================================================================================================================
+       // Test OPTIONS pages without NLS
+       
//=================================================================================================================
+       
+       @RestResource(title="test")
+       public static class B {
+               @RestMethod(name=OPTIONS, description="foo")
+               public Swagger testOptions(RestRequest req) {
+                       // Should get to the options page without errors
+                       return req.getSwagger();
+               }
+       }
+       static MockRest b = MockRest.create(B.class);
+       
+       @Test
+       public void b01_optionsPageWithoutNls() throws Exception {
+               b.request("OPTIONS", "/").execute().assertBodyContains("foo");
+       }
+
+       
//=================================================================================================================
+       // Test Missing resource bundles.
+       
//=================================================================================================================
+       
+       @RestResource
+       public static class C {
+               @RestMethod(name=GET)
+               public String test(RestRequest req) {
+                       // Missing resource bundle should cause {!!x} string.
+                       return req.getMessage("bad", 1, 2, 3);
+               }
+       }
+       static MockRest c = MockRest.create(C.class);
+
+       @Test
+       public void c01_missingResourceBundle() throws Exception {
+               c.request("GET", "/").execute().assertBody("{!!bad}");
+       }
 }
diff --git 
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestMethodGuardsTest.java
similarity index 53%
copy from 
juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
copy to 
juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestMethodGuardsTest.java
index c62b6e9..920b732 100644
--- 
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
+++ 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestMethodGuardsTest.java
@@ -10,69 +10,62 @@
 // * "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;
+package org.apache.juneau.rest.annotation;
 
 import static org.apache.juneau.http.HttpMethodName.*;
 
-import org.apache.juneau.*;
-import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.*;
 import org.apache.juneau.rest.mock.*;
-import org.apache.juneau.serializer.*;
 import org.junit.*;
 import org.junit.runners.*;
 
 /**
- * Tests various aspects of localization support.
+ * Tests that validate the behavior of @RestMethod(guards).
  */
 @SuppressWarnings({"javadoc"})
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class NlsTest {
+public class RestMethodGuardsTest {
+       
+       
//=================================================================================================================
+       // Overlapping guards
+       
//=================================================================================================================
 
-       
//====================================================================================================
-       // Test getting an NLS property defined on a class or method.
-       
//====================================================================================================
-
-       @RestResource(
-               serializers={A01.class},
-               properties={@Property(name="TestProperty",value="$L{key1}")},
-               messages="NlsTest"
-       )
+       @RestResource
        public static class A {
-               @RestMethod(name=GET, path="/fromClass")
+               @RestMethod(name=GET, path="/overlappingOneGuard", 
guards=Test1Guard.class)
                public String a01() {
-                       return null;
+                       return "OK1";
                }
-               @RestMethod(name=GET, path="/fromMethod",
-                       
properties={@Property(name="TestProperty",value="$L{key2}")}
-               )
+               @RestMethod(name=GET, path="/overlappingTwoGuards", 
guards={Test1Guard.class,Test2Guard.class})
                public String a02() {
-                       return null;
+                       return "OK2";
                }
-       }
-       static MockRest a = MockRest.create(A.class);
-
-       public static class A01 extends WriterSerializer {
-               public A01(PropertyStore ps) {
-                       super(ps, "text/plain", null);
+               public static class Test1Guard extends RestGuard {
+                       @Override /* RestGuard */
+                       public boolean isRequestAllowed(RestRequest req) {
+                               return 
req.getQuery().getString("t1","").equals("1");
+                       }
                }
-               @Override /* Serializer */
-               public WriterSerializerSession 
createSession(SerializerSessionArgs args) {
-                       return new WriterSerializerSession(args) {
-                               @Override /* SerializerSession */
-                               protected void doSerialize(SerializerPipe out, 
Object o) throws Exception {
-                                       
out.getWriter().write(getProperty("TestProperty", String.class));
-                               }
-                       };
+               public static class Test2Guard extends RestGuard {
+                       @Override /* RestGuard */
+                       public boolean isRequestAllowed(RestRequest req) {
+                               return 
req.getQuery().getString("t2","").equals("2");
+                       }
                }
        }
-
+       static MockRest a = MockRest.create(A.class);
+       
        @Test
-       public void a01_fromClass() throws Exception {
-               a.request("GET", "/fromClass").execute().assertBody("value1");
+       public void a01_overlappingOneGuard() throws Exception {
+               a.request("GET", 
"/overlappingOneGuard?t1=1").execute().assertBody("OK1");
+               a.request("GET", 
"/overlappingOneGuard?noTrace=true").execute().assertStatus(403).assertBodyContains("Access
 denied by guard");
        }
 
        @Test
-       public void a02_fromMethod() throws Exception {
-               a.request("GET", "/fromMethod").execute().assertBody("value2");
+       public void a01_overlappingTwoGuards() throws Exception {
+               a.request("GET", 
"/overlappingTwoGuards?noTrace=true").execute().assertStatus(403).assertBodyContains("Access
 denied by guard");
+               a.request("GET", 
"/overlappingTwoGuards?noTrace=true&t1=1").execute().assertStatus(403).assertBodyContains("Access
 denied by guard");
+               a.request("GET", 
"/overlappingTwoGuards?noTrace=true&t2=2").execute().assertStatus(403).assertBodyContains("Access
 denied by guard");
+               a.request("GET", 
"/overlappingTwoGuards?t1=1&t2=2").execute().assertBody("OK2");
        }
 }
diff --git 
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestMethodMatchersTest.java
similarity index 52%
copy from 
juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
copy to 
juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestMethodMatchersTest.java
index c62b6e9..ca97b0d 100644
--- 
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
+++ 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestMethodMatchersTest.java
@@ -10,69 +10,75 @@
 // * "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;
+package org.apache.juneau.rest.annotation;
 
 import static org.apache.juneau.http.HttpMethodName.*;
 
-import org.apache.juneau.*;
-import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.*;
 import org.apache.juneau.rest.mock.*;
-import org.apache.juneau.serializer.*;
 import org.junit.*;
 import org.junit.runners.*;
 
 /**
- * Tests various aspects of localization support.
+ * Tests that validate the behavior of @RestMethod(matchers).
  */
 @SuppressWarnings({"javadoc"})
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class NlsTest {
+public class RestMethodMatchersTest {
+       
+       
//=================================================================================================================
+       // Overlapping matchers
+       
//=================================================================================================================
 
-       
//====================================================================================================
-       // Test getting an NLS property defined on a class or method.
-       
//====================================================================================================
-
-       @RestResource(
-               serializers={A01.class},
-               properties={@Property(name="TestProperty",value="$L{key1}")},
-               messages="NlsTest"
-       )
+       @RestResource
        public static class A {
-               @RestMethod(name=GET, path="/fromClass")
-               public String a01() {
-                       return null;
+               @RestMethod(name=GET, path="/one", matchers=M1.class)
+               public String a01a() {
+                       return "OK-1a";
                }
-               @RestMethod(name=GET, path="/fromMethod",
-                       
properties={@Property(name="TestProperty",value="$L{key2}")}
-               )
-               public String a02() {
-                       return null;
+               @RestMethod(name=GET, path="/one", matchers=M2.class)
+               public String a01b() {
+                       return "OK-1b";
+               }
+               @RestMethod(name=GET, path="/one")
+               public String a01c() {
+                       return "OK-1c";
+               }
+               @RestMethod(name=GET, path="/two")
+               public String a02a() {
+                       return "OK-2a";
+               }
+               @RestMethod(name=GET, path="/two", matchers={M1.class, 
M2.class})
+               public String a02b() {
+                       return "OK-2b";
                }
-       }
-       static MockRest a = MockRest.create(A.class);
 
-       public static class A01 extends WriterSerializer {
-               public A01(PropertyStore ps) {
-                       super(ps, "text/plain", null);
+               public static class M1 extends RestMatcher {
+                       @Override /* RestMatcher */
+                       public boolean matches(RestRequest req) {
+                               return 
req.getQuery().getString("t1","").equals("1");
+                       }
                }
-               @Override /* Serializer */
-               public WriterSerializerSession 
createSession(SerializerSessionArgs args) {
-                       return new WriterSerializerSession(args) {
-                               @Override /* SerializerSession */
-                               protected void doSerialize(SerializerPipe out, 
Object o) throws Exception {
-                                       
out.getWriter().write(getProperty("TestProperty", String.class));
-                               }
-                       };
+               public static class M2 extends RestMatcher {
+                       @Override /* RestMatcher */
+                       public boolean matches(RestRequest req) {
+                               return 
req.getQuery().getString("t2","").equals("2");
+                       }
                }
        }
-
+       static MockRest a = MockRest.create(A.class);
+       
        @Test
-       public void a01_fromClass() throws Exception {
-               a.request("GET", "/fromClass").execute().assertBody("value1");
+       public void a01() throws Exception {
+               a.request("GET", "/one?t1=1").execute().assertBody("OK-1a");
+               a.request("GET", "/one?t2=2").execute().assertBody("OK-1b");
+               a.request("GET", "/one").execute().assertBody("OK-1c");
        }
-
        @Test
-       public void a02_fromMethod() throws Exception {
-               a.request("GET", "/fromMethod").execute().assertBody("value2");
+       public void a02() throws Exception {
+               a.request("GET", "/two?t1=1").execute().assertBody("OK-2b");
+               a.request("GET", "/two?t2=2").execute().assertBody("OK-2b");
+               a.request("GET", 
"/two?t1=1&t2=2").execute().assertBody("OK-2b");
+               a.request("GET", "/two?tx=x").execute().assertBody("OK-2a");
        }
 }
diff --git 
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestMethodPathTest.java
similarity index 54%
copy from 
juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
copy to 
juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestMethodPathTest.java
index c62b6e9..3a80023 100644
--- 
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/NlsTest.java
+++ 
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestMethodPathTest.java
@@ -10,69 +10,78 @@
 // * "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;
+package org.apache.juneau.rest.annotation;
 
 import static org.apache.juneau.http.HttpMethodName.*;
 
-import org.apache.juneau.*;
-import org.apache.juneau.rest.annotation.*;
 import org.apache.juneau.rest.mock.*;
-import org.apache.juneau.serializer.*;
 import org.junit.*;
 import org.junit.runners.*;
 
 /**
- * Tests various aspects of localization support.
+ * Tests that validate the behavior of @RestMethod(path).
  */
 @SuppressWarnings({"javadoc"})
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class NlsTest {
+public class RestMethodPathTest {
+       
+       
//=================================================================================================================
+       // Overlapping URL patterns
+       
//=================================================================================================================
 
-       
//====================================================================================================
-       // Test getting an NLS property defined on a class or method.
-       
//====================================================================================================
-
-       @RestResource(
-               serializers={A01.class},
-               properties={@Property(name="TestProperty",value="$L{key1}")},
-               messages="NlsTest"
-       )
+       @RestResource
        public static class A {
-               @RestMethod(name=GET, path="/fromClass")
-               public String a01() {
-                       return null;
+               @RestMethod(name=GET, path="/")
+               public String a01a() {
+                       return "a";
                }
-               @RestMethod(name=GET, path="/fromMethod",
-                       
properties={@Property(name="TestProperty",value="$L{key2}")}
-               )
-               public String a02() {
-                       return null;
+               @RestMethod(name=GET, path="/*")
+               public String a01b() {
+                       return "b";
                }
-       }
-       static MockRest a = MockRest.create(A.class);
-
-       public static class A01 extends WriterSerializer {
-               public A01(PropertyStore ps) {
-                       super(ps, "text/plain", null);
+               @RestMethod(name=GET, path="/foo")
+               public String a01c() {
+                       return "c";
                }
-               @Override /* Serializer */
-               public WriterSerializerSession 
createSession(SerializerSessionArgs args) {
-                       return new WriterSerializerSession(args) {
-                               @Override /* SerializerSession */
-                               protected void doSerialize(SerializerPipe out, 
Object o) throws Exception {
-                                       
out.getWriter().write(getProperty("TestProperty", String.class));
-                               }
-                       };
+               @RestMethod(name=GET, path="/foo/*")
+               public String a01d() {
+                       return "d";
+               }
+               @RestMethod(name=GET, path="/{id}")
+               public String a01e() {
+                       return "e";
+               }
+               @RestMethod(name=GET, path="/{id}/*")
+               public String a01f() {
+                       return "f";
+               }
+               @RestMethod(name=GET, path="/{id}/foo")
+               public String a01g() {
+                       return "g";
+               }
+               @RestMethod(name=GET, path="/{id}/foo/*")
+               public String a01h() {
+                       return "h";
                }
        }
+       static MockRest a = MockRest.create(A.class);
 
        @Test
-       public void a01_fromClass() throws Exception {
-               a.request("GET", "/fromClass").execute().assertBody("value1");
-       }
-
-       @Test
-       public void a02_fromMethod() throws Exception {
-               a.request("GET", "/fromMethod").execute().assertBody("value2");
+       public void a01_overlappingPaths() throws Exception {
+               // [/] = [test5a]
+               // [/*] = [test5b]   -- Cannot get called.
+               // [/foo] = [test5c]
+               // [/foo/*] = [test5d]
+               // [/{id}] = [test5e]
+               // [/{id}/*] = [test5f]
+               // [/{id}/foo] = [test5g]
+               // [/{id}/foo/*] = [test5h]
+               a.request("GET", "/").execute().assertBody("a");
+               a.request("GET", "/foo").execute().assertBody("c");
+               a.request("GET", "/foo/x").execute().assertBody("d");
+               a.request("GET", "/x").execute().assertBody("e");
+               a.request("GET", "/x/x").execute().assertBody("f");
+               a.request("GET", "/x/foo").execute().assertBody("g");
+               a.request("GET", "/x/foo/x").execute().assertBody("h");
        }
 }

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

Reply via email to