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

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 4a3348b  [ISSUE #2983] Fix judgment of the contains condition of all 
plugins d… (#2989)
4a3348b is described below

commit 4a3348b9edd1e35c6a86e3e3cd92301f470bcd00
Author: lianjunwei <[email protected]>
AuthorDate: Mon Mar 7 16:15:45 2022 +0800

    [ISSUE #2983] Fix judgment of the contains condition of all plugins d… 
(#2989)
    
    * [ISSUE #2983] Fix judgment of the contains condition of all plugins does 
not work.
    
    * [ISSUE #2983] Add commit. Delete bad taste code.
    
    Co-authored-by: lianjunwei <[email protected]>
---
 .../condition/judge/ContainsPredicateJudge.java    |  2 +-
 .../judge/ContainsPredicateJudgeTest.java          | 46 ----------------------
 .../condition/judge/PredicateJudgeFactoryTest.java |  8 ++++
 3 files changed, 9 insertions(+), 47 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/condition/judge/ContainsPredicateJudge.java
 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/condition/judge/ContainsPredicateJudge.java
index 53dc5ee..f9f6d3a 100644
--- 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/condition/judge/ContainsPredicateJudge.java
+++ 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/condition/judge/ContainsPredicateJudge.java
@@ -28,6 +28,6 @@ public class ContainsPredicateJudge implements PredicateJudge 
{
 
     @Override
     public Boolean judge(final ConditionData conditionData, final String 
realData) {
-        return conditionData.getParamValue().trim().contains(realData);
+        return realData.contains(conditionData.getParamValue().trim());
     }
 }
diff --git 
a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/condition/judge/ContainsPredicateJudgeTest.java
 
b/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/condition/judge/ContainsPredicateJudgeTest.java
deleted file mode 100644
index ff24360..0000000
--- 
a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/condition/judge/ContainsPredicateJudgeTest.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.shenyu.plugin.base.condition.judge;
-
-import junit.framework.TestCase;
-import org.apache.shenyu.common.dto.ConditionData;
-import org.apache.shenyu.common.enums.OperatorEnum;
-import org.apache.shenyu.common.enums.ParamTypeEnum;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-public class ContainsPredicateJudgeTest extends TestCase {
-
-    private ConditionData conditionDataForIp;
-
-    @BeforeEach
-    public void setUp() {
-        conditionDataForIp = new ConditionData();
-        conditionDataForIp.setParamType(ParamTypeEnum.IP.getName());
-        conditionDataForIp.setParamValue("127.0.0.1,128.0.0.1");
-    }
-
-    @Test
-    public void testContainsJudgeForIp() {
-        conditionDataForIp.setOperator(OperatorEnum.CONTAINS.getAlias());
-        Assertions.assertTrue(PredicateJudgeFactory.judge(conditionDataForIp, 
"127.0.0.1"));
-        Assertions.assertTrue(PredicateJudgeFactory.judge(conditionDataForIp, 
"128.0.0.1"));
-        Assertions.assertFalse(PredicateJudgeFactory.judge(conditionDataForIp, 
"0.1.128.0"));
-    }
-}
diff --git 
a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/condition/judge/PredicateJudgeFactoryTest.java
 
b/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/condition/judge/PredicateJudgeFactoryTest.java
index 5681ce0..9bd002a 100644
--- 
a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/condition/judge/PredicateJudgeFactoryTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/condition/judge/PredicateJudgeFactoryTest.java
@@ -115,4 +115,12 @@ public final class PredicateJudgeFactoryTest {
         assertTrue(PredicateJudgeFactory.judge(conditionData, "/http?/test"));
     }
 
+    @Test
+    public void testContainsJudge() {
+        conditionData.setOperator(OperatorEnum.CONTAINS.getAlias());
+        assertTrue(PredicateJudgeFactory.judge(conditionData, 
"/http/**/test"));
+        assertTrue(PredicateJudgeFactory.judge(conditionData, 
"/test/http/**"));
+        assertFalse(PredicateJudgeFactory.judge(conditionData, "/http1/**"));
+    }
+
 }

Reply via email to