From bf8da8edde00c67a174761e4d44d4a5dab42abfe Mon Sep 17 00:00:00 2001 From: lucian Date: Thu, 11 Jun 2020 11:44:17 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-33369=20=E5=9C=A8A=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9=E6=B2=A1=E6=9C=89=E7=82=B9=E7=A1=AE?= =?UTF-8?q?=E5=AE=9A=E3=80=82=E5=9C=A8B=E7=9B=AE=E5=BD=95=E7=A1=AE?= =?UTF-8?q?=E5=AE=9A=EF=BC=8CA=E7=9A=84=E4=BF=AE=E6=94=B9=E4=B9=9F?= =?UTF-8?q?=E4=BC=9A=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 29 +++++++++++++------ .../com/fr/design/EnvChangeEntranceTest.java | 25 +++++++++++++--- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java index cfe0840af1..ce32e2323c 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -53,6 +53,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.HashSet; @@ -385,7 +386,7 @@ public class EnvChangeEntrance { public void doOk() { envListOkAction(envListPane, PopTipStrategy.LATER); // 切换完成后清理密码 - updateSelectEnv(DesignerEnvManager.getEnvManager().getCurEnvName()); + updateNotRememberPwdEnv(); } @Override @@ -416,7 +417,7 @@ public class EnvChangeEntrance { if (!envListOkAction(envListPane, PopTipStrategy.NOW)) { DesignerExiter.getInstance().execute(); } else { - updateSelectEnv(DesignerEnvManager.getEnvManager().getCurEnvName()); + updateNotRememberPwdEnv(); } } @@ -428,17 +429,19 @@ public class EnvChangeEntrance { envListDialog.setVisible(true); } - /** + /** * 切换环境后 刷新远程目录需要忘记密码的情况 - * @param envName 环境名 */ - private void updateSelectEnv(String envName) { + private void updateNotRememberPwdEnv() { DesignerEnvManager mgr = DesignerEnvManager.getEnvManager(); - DesignerWorkspaceInfo info = mgr.getWorkspaceInfo(envName); - if (info != null) { - WorkspaceConnectionInfo connection = info.getConnection(); - if (connection != null && !connection.isRememberPwd()) { + Iterator iterator = mgr.getEnvNameIterator(); + while (iterator.hasNext()) { + String envName = iterator.next(); + DesignerWorkspaceInfo info = mgr.getWorkspaceInfo(envName); + + if (isNotRememberPwd(info)) { + WorkspaceConnectionInfo connection = info.getConnection(); DesignerWorkspaceInfo workspaceInfo = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo( connection.getUrl(), connection.getUserName(), StringUtils.EMPTY, connection.getCertPath(), connection.getCertSecretKey(), false)); mgr.putEnv(envName, workspaceInfo); @@ -446,6 +449,14 @@ public class EnvChangeEntrance { } } + private boolean isNotRememberPwd(DesignerWorkspaceInfo info) { + if (info != null && info.getType() == DesignerWorkspaceType.Remote) { + WorkspaceConnectionInfo connection = info.getConnection(); + return connection != null && !connection.isRememberPwd(); + } + return false; + } + /** * 提示显示策略 diff --git a/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java b/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java index 672f17e374..d9d6e44844 100644 --- a/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java +++ b/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java @@ -2,6 +2,7 @@ package com.fr.design; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; +import com.fr.design.env.LocalDesignerWorkspaceInfo; import com.fr.design.env.RemoteDesignerWorkspaceInfo; import com.fr.env.CheckServiceDialog; import com.fr.invoke.Reflect; @@ -58,7 +59,7 @@ public class EnvChangeEntranceTest { } @Test - public void testUpdateSelectEnv() { + public void testUpdateNotRememberPwdEnv() { DesignerEnvManager manager = new DesignerEnvManager(); @@ -71,16 +72,32 @@ public class EnvChangeEntranceTest { manager.putEnv("test1", RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "password", "", "", true))); manager.putEnv("test2", RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "password", "", "", false))); + manager.putEnv("test3", LocalDesignerWorkspaceInfo.create("name", "path")); - Reflect.on(entrance).call("updateSelectEnv", "test1"); - Reflect.on(entrance).call("updateSelectEnv", "test2"); - + Reflect.on(entrance).call("updateNotRememberPwdEnv"); Assert.assertEquals(manager.getWorkspaceInfo("test1").getConnection(), RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "password", "", "", true)).getConnection()); Assert.assertEquals(manager.getWorkspaceInfo("test2").getConnection(), RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "", "", "", false)).getConnection()); + Assert.assertEquals(manager.getWorkspaceInfo("test3").getName(), "name"); + Assert.assertEquals(manager.getWorkspaceInfo("test3").getPath(), "path"); PowerMock.verifyAll(); } + @Test + public void testIsNotRememberPwd() { + EnvChangeEntrance entrance = EnvChangeEntrance.getInstance(); + + DesignerWorkspaceInfo info1 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "password", "", "", true)); + DesignerWorkspaceInfo info2 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "111", "", "", false)); + DesignerWorkspaceInfo info3 = LocalDesignerWorkspaceInfo.create("name", "path"); + DesignerWorkspaceInfo info4 = null; + + Assert.assertFalse((boolean) Reflect.on(entrance).call("isNotRememberPwd", info1).get()); + Assert.assertTrue((boolean) Reflect.on(entrance).call("isNotRememberPwd", info2).get()); + Assert.assertFalse((boolean) Reflect.on(entrance).call("isNotRememberPwd", info3).get()); + Assert.assertFalse((boolean) Reflect.on(entrance).call("isNotRememberPwd", info4).get()); + } + } \ No newline at end of file