diff --git a/acl-plug/src/test/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java b/acl-plug/src/test/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java index 618c87e49d8ddff15a4a44656ce8718e452ad19e..bf3ec8da58ae0142a5d0b64af3da9ea6c1a16256 100644 --- a/acl-plug/src/test/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java +++ b/acl-plug/src/test/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java @@ -18,11 +18,14 @@ package org.apache.rocketmq.acl.plug.engine; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; + import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo; import org.apache.rocketmq.acl.plug.entity.AuthenticationResult; @@ -54,11 +57,20 @@ public class PlainAclPlugEngineTest { Map loginInfoMap; @Before - public void init() throws FileNotFoundException, NoSuchFieldException, SecurityException { + public void init() throws NoSuchFieldException, SecurityException, IOException { + Yaml ymal = new Yaml(); String home = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV)); - Yaml ymal = new Yaml(); - String filePath = home + "/conf/transport.yml"; - FileInputStream fis = new FileInputStream(new File(filePath)); + InputStream fis=null; + if(home == null){ + URL url = PlainAclPlugEngineTest.class.getResource("/conf/transport.yml"); + fis = url.openStream(); + url = PlainAclPlugEngineTest.class.getResource("/"); + home = url.toString(); + home = home.substring(0, home.length()-1).replace("file:/", ""); + }else { + String filePath = home + "/conf/transport.yml"; + fis = new FileInputStream(new File(filePath)); + } transport = ymal.loadAs(fis, BorkerAccessControlTransport.class); ControllerParameters controllerParametersEntity = new ControllerParameters();