Adds basic test case

Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/7db5e761
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/7db5e761
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/7db5e761

Branch: refs/heads/master
Commit: 7db5e76133e22e86e0af0687fe1b3f1b80bfc09a
Parents: f1dbc5a
Author: Lukasz Lenart <lukasz.len...@gmail.com>
Authored: Fri Sep 4 09:24:18 2015 +0200
Committer: Lukasz Lenart <lukasz.len...@gmail.com>
Committed: Fri Sep 4 09:24:18 2015 +0200

----------------------------------------------------------------------
 .../config/entities/AllowedMethodsTest.java     | 55 ++++++++++++++++++++
 1 file changed, 55 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/7db5e761/core/src/test/java/com/opensymphony/xwork2/config/entities/AllowedMethodsTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/com/opensymphony/xwork2/config/entities/AllowedMethodsTest.java
 
b/core/src/test/java/com/opensymphony/xwork2/config/entities/AllowedMethodsTest.java
new file mode 100644
index 0000000..78f3094
--- /dev/null
+++ 
b/core/src/test/java/com/opensymphony/xwork2/config/entities/AllowedMethodsTest.java
@@ -0,0 +1,55 @@
+package com.opensymphony.xwork2.config.entities;
+
+import junit.framework.TestCase;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class AllowedMethodsTest extends TestCase {
+
+    public void testLiteralMethods() throws Exception {
+        // given
+        String method = "myMethod";
+        Set<String> literals = new HashSet<>();
+        literals.add(method);
+
+        // when
+        AllowedMethods allowedMethods = AllowedMethods.build(literals);
+
+        // then
+        assertEquals(1, allowedMethods.list().size());
+        assertTrue(allowedMethods.isAllowed(method));
+        assertFalse(allowedMethods.isAllowed("someOtherMethod"));
+    }
+
+    public void testWidlcardMethods() throws Exception {
+        // given
+        String method = "my{1}";
+        Set<String> literals = new HashSet<>();
+        literals.add(method);
+
+        // when
+        AllowedMethods allowedMethods = AllowedMethods.build(literals);
+
+        // then
+        assertEquals(1, allowedMethods.list().size());
+        assertTrue(allowedMethods.isAllowed("myMethod"));
+        assertFalse(allowedMethods.isAllowed("someOtherMethod"));
+    }
+
+    public void testRegexMethods() throws Exception {
+        // given
+        String method = "regex:my([a-zA-Z].*)";
+        Set<String> literals = new HashSet<>();
+        literals.add(method);
+
+        // when
+        AllowedMethods allowedMethods = AllowedMethods.build(literals);
+
+        // then
+        assertEquals(1, allowedMethods.list().size());
+        assertTrue(allowedMethods.isAllowed("myMethod"));
+        assertFalse(allowedMethods.isAllowed("someOtherMethod"));
+    }
+
+}

Reply via email to