Browse Source

Merge pull request #1155 in DESIGN/design from ~YAOH.WU/design:bugfix/10.0 to bugfix/10.0

* commit '578b9a8b94d4fe452c710cd18cc8f31236e872c4':
  hashCode 和 equals 单元测试
  修改 toString 方法展示完整信息
  REPORT-22114 远程设计配置界面优先以直接 url 地址填写的为准并尽可能保证联动
bugfix/10.0
Hades 5 years ago
parent
commit
1e0f85726d
  1. 1
      designer-base/src/main/java/com/fr/env/RemoteEnvPane.java
  2. 37
      designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java
  3. 48
      designer-base/src/test/java/com/fr/env/RemoteWorkspaceURLTest.java

1
designer-base/src/main/java/com/fr/env/RemoteEnvPane.java vendored

@ -643,6 +643,7 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteDesignerWorkspaceInfo> {
remoteWorkspaceURL.setPort(port); remoteWorkspaceURL.setPort(port);
remoteWorkspaceURL.setWeb(web); remoteWorkspaceURL.setWeb(web);
remoteWorkspaceURL.setServlet(servlet); remoteWorkspaceURL.setServlet(servlet);
remoteWorkspaceURL.resetUrl();
} }

37
designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java vendored

@ -1,10 +1,9 @@
package com.fr.env; package com.fr.env;
import com.fr.stable.AssistUtils;
import com.fr.stable.FCloneable; import com.fr.stable.FCloneable;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.util.Objects;
/** /**
* @author yaohwu * @author yaohwu
*/ */
@ -42,6 +41,7 @@ public class RemoteWorkspaceURL implements FCloneable {
private String port; private String port;
private String web; private String web;
private String servlet; private String servlet;
private String url;
/** /**
@ -51,7 +51,7 @@ public class RemoteWorkspaceURL implements FCloneable {
* @param url x:x/x/x/x * @param url x:x/x/x/x
*/ */
public RemoteWorkspaceURL(String url) { public RemoteWorkspaceURL(String url) {
this.url = url;
// 没有写协议名称 默认 使用 http 协议 // 没有写协议名称 默认 使用 http 协议
if (!url.startsWith(HTTPS) && !url.startsWith(HTTP)) { if (!url.startsWith(HTTPS) && !url.startsWith(HTTP)) {
url = HTTP + url; url = HTTP + url;
@ -116,11 +116,15 @@ public class RemoteWorkspaceURL implements FCloneable {
} }
public String getURL() { public String getURL() {
if (this.url != null) {
return url;
}
String prefix = isHttps ? HTTPS : HTTP; String prefix = isHttps ? HTTPS : HTTP;
String portColon = StringUtils.isNotEmpty(port) ? ":" : StringUtils.EMPTY; String portColon = StringUtils.isNotEmpty(port) ? ":" : StringUtils.EMPTY;
String webAppNameSlash = StringUtils.isNotEmpty(web) ? "/" : StringUtils.EMPTY; String webAppNameSlash = StringUtils.isNotEmpty(web) ? "/" : StringUtils.EMPTY;
String servletNameSlash = StringUtils.isNotEmpty(servlet) ? "/" : StringUtils.EMPTY; String servletNameSlash = StringUtils.isNotEmpty(servlet) ? "/" : StringUtils.EMPTY;
return prefix + host + portColon + port + webAppNameSlash + web + servletNameSlash + servlet; this.url = prefix + host + portColon + port + webAppNameSlash + web + servletNameSlash + servlet;
return this.url;
} }
@ -164,26 +168,24 @@ public class RemoteWorkspaceURL implements FCloneable {
return servlet; return servlet;
} }
public void resetUrl() {
this.url = null;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { return o instanceof RemoteWorkspaceURL && AssistUtils.equals(isHttps, ((RemoteWorkspaceURL) o).isHttps)
return true; && AssistUtils.equals(host, ((RemoteWorkspaceURL) o).host)
} && AssistUtils.equals(port, ((RemoteWorkspaceURL) o).port)
if (o == null || getClass() != o.getClass()) { && AssistUtils.equals(web, ((RemoteWorkspaceURL) o).web)
return false; && AssistUtils.equals(servlet, ((RemoteWorkspaceURL) o).servlet)
} && AssistUtils.equals(url, ((RemoteWorkspaceURL) o).url);
RemoteWorkspaceURL that = (RemoteWorkspaceURL) o;
return isHttps == that.isHttps &&
Objects.equals(host, that.host) &&
Objects.equals(port, that.port) &&
Objects.equals(web, that.web) &&
Objects.equals(servlet, that.servlet);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(isHttps, host, port, web, servlet); return AssistUtils.hashCode(isHttps, host, port, web, servlet, url);
} }
@Override @Override
@ -194,6 +196,7 @@ public class RemoteWorkspaceURL implements FCloneable {
", port='" + port + '\'' + ", port='" + port + '\'' +
", web='" + web + '\'' + ", web='" + web + '\'' +
", servlet='" + servlet + '\'' + ", servlet='" + servlet + '\'' +
", url='" + url + '\'' +
'}'; '}';
} }

48
designer-base/src/test/java/com/fr/env/RemoteEnvURLTest.java → designer-base/src/test/java/com/fr/env/RemoteWorkspaceURLTest.java vendored

@ -4,11 +4,57 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/** /**
* @author yaohwu * @author yaohwu
*/ */
public class RemoteEnvURLTest { public class RemoteWorkspaceURLTest {
@Test
public void testEqualAndHashCode() {
String a = "https://yaohwu:8080/webroot/app/c/d";
RemoteWorkspaceURL workspaceURL1 = new RemoteWorkspaceURL(a);
RemoteWorkspaceURL workspaceURL2 = new RemoteWorkspaceURL(a);
assertEquals(workspaceURL1.hashCode(), workspaceURL2.hashCode());
assertEquals(workspaceURL1, workspaceURL2);
workspaceURL2.resetUrl();
assertNotEquals(workspaceURL1.hashCode(), workspaceURL2.hashCode());
assertNotEquals(workspaceURL1, workspaceURL2);
}
@Test
public void testUrlReset() {
String a = "https://yaohwu:8080/webroot/app/c/d";
RemoteWorkspaceURL workspaceURL = new RemoteWorkspaceURL(a);
Assert.assertEquals(a, workspaceURL.getURL());
Assert.assertEquals("app", workspaceURL.getServlet());
Assert.assertEquals("webroot", workspaceURL.getWeb());
Assert.assertEquals("yaohwu", workspaceURL.getHost());
Assert.assertEquals("8080", workspaceURL.getPort());
Assert.assertTrue(workspaceURL.getHttps());
workspaceURL.setHttps(false);
workspaceURL.setHost("finereport");
Assert.assertEquals(a, workspaceURL.getURL());
Assert.assertEquals("app", workspaceURL.getServlet());
Assert.assertEquals("webroot", workspaceURL.getWeb());
Assert.assertEquals("finereport", workspaceURL.getHost());
Assert.assertEquals("8080", workspaceURL.getPort());
Assert.assertFalse(workspaceURL.getHttps());
workspaceURL.resetUrl();
Assert.assertEquals("http://finereport:8080/webroot/app", workspaceURL.getURL());
Assert.assertEquals("app", workspaceURL.getServlet());
Assert.assertEquals("webroot", workspaceURL.getWeb());
Assert.assertEquals("finereport", workspaceURL.getHost());
Assert.assertEquals("8080", workspaceURL.getPort());
Assert.assertFalse(workspaceURL.getHttps());
}
@Test @Test
public void testURLParser() { public void testURLParser() {
Loading…
Cancel
Save