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

jianglongtao 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 a2e0fdd8820 Add PluginJarLoaderTest (#23423) (#24149)
a2e0fdd8820 is described below

commit a2e0fdd8820ef55486b21aa57089ade86e2b1044
Author: Cong Hu <[email protected]>
AuthorDate: Tue Mar 14 18:05:37 2023 +0800

    Add PluginJarLoaderTest (#23423) (#24149)
    
    * Add PluginJarLoaderTest (#23423)
    
    * Alter the jar used for testing (#23423)
    
    ---------
    
    Co-authored-by: 胡聪 <[email protected]>
---
 .../agent/core/plugin/jar/PluginJarLoaderTest.java |  50 +++++++++++++++++++++
 .../src/test/resources/plugins/test-plugin.jar     | Bin 0 -> 22 bytes
 2 files changed, 50 insertions(+)

diff --git 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoaderTest.java
 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoaderTest.java
new file mode 100644
index 00000000000..198ab0f7566
--- /dev/null
+++ 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoaderTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.agent.core.plugin.jar;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Collection;
+import java.util.Objects;
+import java.util.jar.JarFile;
+
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class PluginJarLoaderTest {
+    
+    @Test
+    public void assertLoad() throws IOException {
+        Collection<JarFile> jarFiles = PluginJarLoader.load(new 
File(getResourceURL()));
+        assertThat(jarFiles.size(), is(1));
+        assertThat(jarFiles.iterator().next().getName(), 
endsWith("test-plugin.jar"));
+    }
+    
+    private String getResourceURL() throws UnsupportedEncodingException {
+        return URLDecoder.decode(
+                
Objects.requireNonNull(PluginJarLoader.class.getClassLoader().getResource(""))
+                        .getFile(),
+                "UTF8");
+    }
+    
+}
diff --git a/agent/core/src/test/resources/plugins/test-plugin.jar 
b/agent/core/src/test/resources/plugins/test-plugin.jar
new file mode 100644
index 00000000000..15cb0ecb3e2
Binary files /dev/null and 
b/agent/core/src/test/resources/plugins/test-plugin.jar differ

Reply via email to