-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add field to change HTTP port #13479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
c7798cd
1ce282e
157c573
df53f2f
59c2e07
9f04c77
47aeffd
92a0887
987ed00
bb33695
a569a88
6ca44e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,13 @@ public class RemotePreferences { | |
| private final IntegerProperty port; | ||
| private final BooleanProperty useRemoteServer; | ||
|
|
||
| private final IntegerProperty httpPort; | ||
| private final BooleanProperty enableHttpServer; | ||
|
|
||
| public RemotePreferences(int port, boolean useRemoteServer, boolean enableHttpServer) { | ||
| public RemotePreferences(int port, boolean useRemoteServer, int httpPort, boolean enableHttpServer) { | ||
| this.port = new SimpleIntegerProperty(port); | ||
| this.useRemoteServer = new SimpleBooleanProperty(useRemoteServer); | ||
| this.httpPort = new SimpleIntegerProperty(httpPort); | ||
| this.enableHttpServer = new SimpleBooleanProperty(enableHttpServer); | ||
| } | ||
|
|
||
|
|
@@ -60,6 +62,22 @@ public void setUseRemoteServer(boolean useRemoteServer) { | |
| this.useRemoteServer.setValue(useRemoteServer); | ||
| } | ||
|
|
||
| public int getHttpPort() { | ||
| return httpPort.getValue(); | ||
| } | ||
|
|
||
| public IntegerProperty httpPortProperty() { | ||
| return httpPort; | ||
| } | ||
|
|
||
| public void setHttpPort(int httpPort) { | ||
| this.httpPort.setValue(httpPort); | ||
| } | ||
|
|
||
| public boolean isDifferentHttpPort(int otherHttpPort) { | ||
| return getHttpPort() != otherHttpPort; | ||
| } | ||
|
|
||
| public boolean enableHttpServer() { | ||
| return enableHttpServer.getValue(); | ||
| } | ||
|
|
@@ -77,9 +95,19 @@ public static InetAddress getIpAddress() throws UnknownHostException { | |
| return InetAddress.getByName("localhost"); | ||
| } | ||
|
|
||
| private boolean isUriValid(String hostAddress, int port) { | ||
| try { | ||
| URI uri = new URI("http", null, hostAddress, port, null, null, null); | ||
| return true; | ||
| } catch (URISyntaxException e) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public @NonNull URI getHttpServerUri() { | ||
| try { | ||
| return new URI("http://" + RemotePreferences.getIpAddress().getHostAddress() + ":23119"); | ||
| isUriValid(RemotePreferences.getIpAddress().getHostAddress(), getHttpPort()); | ||
| return new URI("http://" + RemotePreferences.getIpAddress().getHostAddress() + ":" + getHttpPort()); | ||
|
||
| } catch (UnknownHostException | URISyntaxException e) { | ||
| LOGGER.error("Could not create HTTP server URI. Falling back to default.", e); | ||
| try { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,20 +13,31 @@ class RemotePreferencesTest { | |
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| preferences = new RemotePreferences(1000, true, false); | ||
| preferences = new RemotePreferences(1000, true, 3000, false); | ||
| } | ||
|
|
||
| @Test | ||
| void getPort() { | ||
| assertEquals(1000, preferences.getPort()); | ||
| } | ||
|
|
||
| @Test | ||
| void getHttpPort() { | ||
| assertEquals(3000, preferences.getHttpPort()); | ||
| } | ||
|
|
||
| @Test | ||
| void setPort() { | ||
| preferences.setPort(2000); | ||
| assertEquals(2000, preferences.getPort()); | ||
| } | ||
|
|
||
| @Test | ||
| void setHttpPort() { | ||
| preferences.setHttpPort(4000); | ||
| assertEquals(4000, preferences.getHttpPort()); | ||
| } | ||
|
|
||
| @Test | ||
| void useRemoteServer() { | ||
| assertTrue(preferences.useRemoteServer()); | ||
|
|
@@ -43,8 +54,18 @@ void isDifferentPortTrue() { | |
| assertTrue(preferences.isDifferentPort(2000)); | ||
| } | ||
|
|
||
| @Test | ||
| void isDifferentHttpPortTrue() { | ||
| assertTrue(preferences.isDifferentHttpPort(4000)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using assertTrue with a boolean condition instead of asserting the actual values. Should use assertEquals to compare the actual HTTP port values for better test clarity and error messages. |
||
| } | ||
|
|
||
| @Test | ||
| void isDifferentPortFalse() { | ||
| assertFalse(preferences.isDifferentPort(1000)); | ||
| } | ||
|
|
||
| @Test | ||
| void isDifferentHttpPortFalse() { | ||
| assertFalse(preferences.isDifferentHttpPort(3000)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using assertFalse with a boolean condition instead of asserting the actual values. Should use assertEquals to compare the actual HTTP port values for better test clarity and error messages. |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isUriValid method's return value is ignored, making the call redundant. The method should either be removed or its result should be used to handle invalid URIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change the return statement here to use isUriValid to return a URI object instead of a boolean.