You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2024/12/23 18:17:08 UTC

(struts) branch feature/wildcard-packages created (now 3be56a484)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch feature/wildcard-packages
in repository https://gitbox.apache.org/repos/asf/struts.git


      at 3be56a484 Adds additional test cases to match Struts packages

This branch includes the following new commits:

     new 3be56a484 Adds additional test cases to match Struts packages

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(struts) 01/01: Adds additional test cases to match Struts packages

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch feature/wildcard-packages
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 3be56a4840b7c0ad63efb6becd41fe12077bad08
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Mon Dec 23 19:16:57 2024 +0100

    Adds additional test cases to match Struts packages
---
 .../apache/struts2/util/WildcardHelperTest.java    | 84 ++++++++++++++--------
 1 file changed, 55 insertions(+), 29 deletions(-)

diff --git a/core/src/test/java/org/apache/struts2/util/WildcardHelperTest.java b/core/src/test/java/org/apache/struts2/util/WildcardHelperTest.java
index be2a0a6b0..e856bfce8 100644
--- a/core/src/test/java/org/apache/struts2/util/WildcardHelperTest.java
+++ b/core/src/test/java/org/apache/struts2/util/WildcardHelperTest.java
@@ -24,34 +24,60 @@ import java.util.HashMap;
 
 public class WildcardHelperTest extends XWorkTestCase {
 
-	public void testMatch() {
-
-		WildcardHelper wild = new WildcardHelper();
-		HashMap<String, String> matchedPatterns = new HashMap<>();
-		int[] pattern = wild.compilePattern("wes-rules");
-		assertEquals(wild.match(matchedPatterns,"wes-rules", pattern), true);
-		assertEquals(wild.match(matchedPatterns, "rules-wes", pattern), false);
-
-		pattern = wild.compilePattern("wes-*");
-		assertEquals(wild.match(matchedPatterns,"wes-rules", pattern), true);
-		assertEquals("rules".equals(matchedPatterns.get("1")), true);
-		assertEquals(wild.match(matchedPatterns, "rules-wes", pattern), false);
-
-		pattern = wild.compilePattern("path/**/file");
-		assertEquals(wild.match(matchedPatterns, "path/to/file", pattern), true);
-		assertEquals("to".equals(matchedPatterns.get("1")), true);
-		assertEquals(wild.match(matchedPatterns, "path/to/another/location/of/file", pattern), true);
-		assertEquals("to/another/location/of".equals(matchedPatterns.get("1")), true);
-
-		pattern = wild.compilePattern("path/*/file");
-		assertEquals(wild.match(matchedPatterns, "path/to/file", pattern), true);
-		assertEquals("to".equals(matchedPatterns.get("1")), true);
-		assertEquals(wild.match(matchedPatterns, "path/to/another/location/of/file", pattern), false);
-
-		pattern = wild.compilePattern("path/*/another/**/file");
-		assertEquals(wild.match(matchedPatterns, "path/to/another/location/of/file", pattern), true);
-		assertEquals("to".equals(matchedPatterns.get("1")), true);
-		assertEquals("location/of".equals(matchedPatterns.get("2")), true);
-	}
+    private WildcardHelper wildcardHelper;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        wildcardHelper = new WildcardHelper();
+    }
+
+    public void testMatch() {
+        HashMap<String, String> matchedPatterns = new HashMap<>();
+        int[] pattern = wildcardHelper.compilePattern("wes-rules");
+        assertEquals(wildcardHelper.match(matchedPatterns, "wes-rules", pattern), true);
+        assertEquals(wildcardHelper.match(matchedPatterns, "rules-wes", pattern), false);
+
+        pattern = wildcardHelper.compilePattern("wes-*");
+        assertEquals(wildcardHelper.match(matchedPatterns, "wes-rules", pattern), true);
+        assertEquals("rules".equals(matchedPatterns.get("1")), true);
+        assertEquals(wildcardHelper.match(matchedPatterns, "rules-wes", pattern), false);
+
+        pattern = wildcardHelper.compilePattern("path/**/file");
+        assertEquals(wildcardHelper.match(matchedPatterns, "path/to/file", pattern), true);
+        assertEquals("to".equals(matchedPatterns.get("1")), true);
+        assertEquals(wildcardHelper.match(matchedPatterns, "path/to/another/location/of/file", pattern), true);
+        assertEquals("to/another/location/of".equals(matchedPatterns.get("1")), true);
+
+        pattern = wildcardHelper.compilePattern("path/*/file");
+        assertEquals(wildcardHelper.match(matchedPatterns, "path/to/file", pattern), true);
+        assertEquals("to".equals(matchedPatterns.get("1")), true);
+        assertEquals(wildcardHelper.match(matchedPatterns, "path/to/another/location/of/file", pattern), false);
+
+        pattern = wildcardHelper.compilePattern("path/*/another/**/file");
+        assertEquals(wildcardHelper.match(matchedPatterns, "path/to/another/location/of/file", pattern), true);
+        assertEquals("to".equals(matchedPatterns.get("1")), true);
+        assertEquals("location/of".equals(matchedPatterns.get("2")), true);
+    }
+
+    public void testMatchStrutsPackages() {
+        // given
+        HashMap<String, String> matchedPatterns = new HashMap<>();
+        int[] pattern = wildcardHelper.compilePattern("org.apache.struts2.*");
+
+        // when & then
+        assertTrue(wildcardHelper.match(matchedPatterns, "org.apache.struts2.XWorkTestCase", pattern));
+        assertEquals("org.apache.struts2.XWorkTestCase", matchedPatterns.get("0"));
+        assertEquals("XWorkTestCase", matchedPatterns.get("1"));
+
+        assertTrue(wildcardHelper.match(matchedPatterns, "org.apache.struts2.core.SomeClass", pattern));
+        assertEquals("org.apache.struts2.core.SomeClass", matchedPatterns.get("0"));
+        assertEquals("core.SomeClass", matchedPatterns.get("1"));
+
+        assertTrue(wildcardHelper.match(matchedPatterns, "org.apache.struts2.", pattern));
+        assertEquals("org.apache.struts2.", matchedPatterns.get("0"));
+        assertEquals("", matchedPatterns.get("1"));
+    }
 
 }