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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3d0d188df1d Add test cases for URLArgumentPlaceholderTypeFactory 
(#30151)
3d0d188df1d is described below

commit 3d0d188df1df3057560ccd0d80fbf2d98c605627
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Feb 17 15:10:58 2024 +0800

    Add test cases for URLArgumentPlaceholderTypeFactory (#30151)
    
    * Add test cases for URLArgumentPlaceholderTypeFactory
    
    * Add URLProviderNotFoundExceptionTest
---
 infra/url/core/pom.xml                             |  6 +++
 .../arg/URLArgumentPlaceholderTypeFactoryTest.java | 45 ++++++++++++++++++++++
 .../URLProviderNotFoundExceptionTest.java          | 36 +++++++++++++++++
 3 files changed, 87 insertions(+)

diff --git a/infra/url/core/pom.xml b/infra/url/core/pom.xml
index 8535218b3b5..da1e8b658a7 100644
--- a/infra/url/core/pom.xml
+++ b/infra/url/core/pom.xml
@@ -37,5 +37,11 @@
             <artifactId>shardingsphere-infra-exception-core</artifactId>
             <version>${project.version}</version>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-test-util</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/arg/URLArgumentPlaceholderTypeFactoryTest.java
 
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/arg/URLArgumentPlaceholderTypeFactoryTest.java
new file mode 100644
index 00000000000..103de0ac88c
--- /dev/null
+++ 
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/arg/URLArgumentPlaceholderTypeFactoryTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.shardingsphere.infra.url.arg;
+
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
+import org.junit.jupiter.api.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class URLArgumentPlaceholderTypeFactoryTest {
+    
+    @Test
+    void assertValueOfWithValidQueryProperties() {
+        
assertThat(URLArgumentPlaceholderTypeFactory.valueOf(PropertiesBuilder.build(new
 Property("placeholder-type", "environment"))), 
is(URLArgumentPlaceholderType.ENVIRONMENT));
+    }
+    
+    @Test
+    void assertValueOfWithInvalidQueryProperties() {
+        
assertThat(URLArgumentPlaceholderTypeFactory.valueOf(PropertiesBuilder.build(new
 Property("placeholder-type", "invalid"))), 
is(URLArgumentPlaceholderType.NONE));
+    }
+    
+    @Test
+    void assertValueOfWithEmptyQueryProperties() {
+        assertThat(URLArgumentPlaceholderTypeFactory.valueOf(new 
Properties()), is(URLArgumentPlaceholderType.NONE));
+    }
+}
diff --git 
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/exception/URLProviderNotFoundExceptionTest.java
 
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/exception/URLProviderNotFoundExceptionTest.java
new file mode 100644
index 00000000000..79a9f9cbef8
--- /dev/null
+++ 
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/exception/URLProviderNotFoundExceptionTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.shardingsphere.infra.url.exception;
+
+import org.junit.jupiter.api.Test;
+
+import java.sql.SQLException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class URLProviderNotFoundExceptionTest {
+    
+    @Test
+    void assertToSQLException() {
+        SQLException sqlException = new 
URLProviderNotFoundException("invalid:xxx").toSQLException();
+        assertThat(sqlException.getMessage(), is("Can not find url provider 
for `invalid:xxx`."));
+        assertThat(sqlException.getSQLState(), is("42S02"));
+        assertThat(sqlException.getErrorCode(), is(12012));
+    }
+}

Reply via email to