You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/02/19 12:22:13 UTC

[shardingsphere] branch master updated: Remove useless method of YamlEngine (#9444)

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

panjuan 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 5b83a79  Remove useless method of YamlEngine (#9444)
5b83a79 is described below

commit 5b83a7966fa23a25df6b38f911e235c1ba3d4f7f
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Fri Feb 19 20:21:40 2021 +0800

    Remove useless method of YamlEngine (#9444)
---
 .../infra/yaml/engine/YamlEngine.java              | 14 -------------
 .../config/YamlEngineUserConfigurationTest.java    |  9 --------
 .../infra/yaml/engine/YamlEngineTest.java          | 24 ----------------------
 3 files changed, 47 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngine.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngine.java
index 600ced1..3176d2e 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngine.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.infra.yaml.engine;
 
-import com.google.common.base.Strings;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
@@ -34,8 +33,6 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
 
 /**
  * YAML engine.
@@ -105,17 +102,6 @@ public final class YamlEngine {
      * Secure unmarshal YAML.
      *
      * @param yamlContent YAML content
-     * @param acceptedClasses accepted classes
-     * @return map from YAML
-     */
-    public static Map<?, ?> secureUnmarshal(final String yamlContent, final Collection<Class<?>> acceptedClasses) {
-        return Strings.isNullOrEmpty(yamlContent) ? new LinkedHashMap<>() : (Map) new Yaml(new ShardingSphereFilterYamlConstructor(acceptedClasses)).load(yamlContent);
-    }
-    
-    /**
-     * Secure unmarshal YAML.
-     *
-     * @param yamlContent YAML content
      * @param acceptedClass accepted class
      * @param <T> type of class
      * @return object from YAML
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/config/YamlEngineUserConfigurationTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/config/YamlEngineUserConfigurationTest.java
index 01c4cb0..fdfe10e 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/config/YamlEngineUserConfigurationTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/config/YamlEngineUserConfigurationTest.java
@@ -21,8 +21,6 @@ import org.apache.shardingsphere.infra.metadata.auth.builtin.yaml.config.YamlUse
 import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
 import org.junit.Test;
 
-import java.util.Collections;
-import java.util.Map;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -36,13 +34,6 @@ public final class YamlEngineUserConfigurationTest {
         assertThat(actual.getPassword(), is("pwd"));
     }
     
-    @SuppressWarnings("unchecked")
-    @Test
-    public void assertSecureUnmarshalMap() {
-        Map<String, Object> actual = (Map<String, Object>) YamlEngine.secureUnmarshal("password: pwd", Collections.emptyList());
-        assertThat(actual.get("password").toString(), is("pwd"));
-    }
-    
     @Test
     public void assertSecureUnmarshalProperties() {
         Properties actual = YamlEngine.secureUnmarshal("password: pwd", Properties.class);
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngineTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngineTest.java
index 7e82ef4..86088b6 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngineTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngineTest.java
@@ -29,9 +29,7 @@ import java.io.IOException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.LinkedList;
-import java.util.Map;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -74,13 +72,6 @@ public final class YamlEngineTest {
     }
     
     @Test
-    @SuppressWarnings("unchecked")
-    public void assertSecureUnmarshalWithYamlContent() {
-        Map<String, Object> actual = (Map<String, Object>) YamlEngine.secureUnmarshal("name: test", Collections.emptyList());
-        assertThat(actual.get("name").toString(), is("test"));
-    }
-    
-    @Test
     public void assertSecureUnmarshalProperties() {
         Properties actual = YamlEngine.secureUnmarshal("password: pwd", Properties.class);
         assertThat(actual.getProperty("password"), is("pwd"));
@@ -93,21 +84,6 @@ public final class YamlEngineTest {
         assertThat(YamlEngine.marshal(actual), is("name: test\n"));
     }
     
-    @Test(expected = ConstructorException.class)
-    public void assertSecureUnmarshalMapWithIllegalClasses() {
-        YamlEngine.secureUnmarshal("url: !!java.net.URLClassLoader [[!!java.net.URL [\"http://localhost\"]]]", Collections.emptyList());
-    }
-    
-    @SuppressWarnings("unchecked")
-    @Test
-    public void assertSecureUnmarshalMapWithAcceptedClasses() {
-        Collection<Class<?>> acceptedClasses = new LinkedList<>();
-        acceptedClasses.add(URLClassLoader.class);
-        acceptedClasses.add(URL.class);
-        Map<String, URLClassLoader> actual = (Map) YamlEngine.secureUnmarshal("url: !!java.net.URLClassLoader [[!!java.net.URL [\"http://localhost\"]]]", acceptedClasses);
-        assertThat(actual.get("url").getClass().getName(), is(URLClassLoader.class.getName()));
-    }
-    
     @Test
     public void assertSecureUnmarshalWithAcceptedClass() throws IOException {
         URL url = getClass().getClassLoader().getResource("yaml/accepted-class.yaml");