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

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


The following commit(s) were added to refs/heads/master by this push:
     new d2c961188e fix: correct selector column in discovery mapper (#7002)
d2c961188e is described below

commit d2c961188e5124bd8f8729fad9e74ac67a0ab634
Author: Southern <[email protected]>
AuthorDate: Thu Sep 3 12:43:31 2026 +0800

    fix: correct selector column in discovery mapper (#7002)
    
    Fix selectBySelectorNameAndPluginName to use selector.selector_name
      instead of the nonexistent selector.name column.
    
      Add a regression test for the mapper SQL definition.
    
    Co-authored-by: aias00 <[email protected]>
---
 .../main/resources/mappers/discovery-sqlmap.xml    |  2 +-
 .../admin/mapper/DiscoveryMapperSqlTest.java       | 66 ++++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/shenyu-admin/src/main/resources/mappers/discovery-sqlmap.xml 
b/shenyu-admin/src/main/resources/mappers/discovery-sqlmap.xml
index c4aa668d72..715b5335aa 100644
--- a/shenyu-admin/src/main/resources/mappers/discovery-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/discovery-sqlmap.xml
@@ -111,7 +111,7 @@
         INNER JOIN discovery_handler dh on d.id = dh.discovery_id
         INNER JOIN discovery_rel dr on dh.id = dr.discovery_handler_id
         INNER JOIN selector s on dr.selector_id = s.id and s.enabled = 1
-        where s.name = #{selectorName} and d.plugin_name = #{pluginName}
+        where s.selector_name = #{selectorName} and d.plugin_name = 
#{pluginName}
     </select>
 
     <insert id="insert" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/DiscoveryMapperSqlTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/DiscoveryMapperSqlTest.java
new file mode 100644
index 0000000000..c38f9aaade
--- /dev/null
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/DiscoveryMapperSqlTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.admin.mapper;
+
+import org.junit.jupiter.api.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.InputStream;
+import java.io.StringReader;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Regression tests for the discovery mapper SQL definitions.
+ */
+public final class DiscoveryMapperSqlTest {
+
+    @Test
+    public void selectBySelectorNameAndPluginNameUsesSelectorNameColumn() 
throws Exception {
+        Document document = loadMapperDocument();
+        NodeList statements = document.getElementsByTagName("select");
+        String statement = null;
+        for (int i = 0; i < statements.getLength(); i++) {
+            if 
("selectBySelectorNameAndPluginName".equals(statements.item(i).getAttributes().getNamedItem("id").getNodeValue()))
 {
+                statement = statements.item(i).getTextContent();
+                break;
+            }
+        }
+        assertNotNull(statement);
+        assertTrue(statement.contains("s.selector_name = #{selectorName}"));
+        assertTrue(statement.contains("d.plugin_name = #{pluginName}"));
+        assertFalse(statement.contains("s.name = #{selectorName}"));
+    }
+
+    private Document loadMapperDocument() throws Exception {
+        try (InputStream input = 
getClass().getClassLoader().getResourceAsStream("mappers/discovery-sqlmap.xml"))
 {
+            assertNotNull(input);
+            DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
+            
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd";,
 false);
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            builder.setEntityResolver((publicId, systemId) -> new 
InputSource(new StringReader("")));
+            return builder.parse(input);
+        }
+    }
+}

Reply via email to