Skip to content

Commit 7654c4c

Browse files
titusfortnerutamas
authored andcommitted
fix linting issues
1 parent e92cf41 commit 7654c4c

File tree

3 files changed

+74
-52
lines changed

3 files changed

+74
-52
lines changed

java/src/org/openqa/selenium/grid/server/BaseServerFlags.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ public class BaseServerFlags implements HasRoles {
3535

3636
@Parameter(
3737
names = {"--external-url"},
38-
description = "External URL where component is generally available. " +
39-
"Useful on complex network topologies when components are on different networks " +
40-
"and proxy servers are involved.")
38+
description =
39+
"External URL where component is generally available. "
40+
+ "Useful on complex network topologies when components are on different networks "
41+
+ "and proxy servers are involved.")
4142
@ConfigValue(section = SERVER_SECTION, name = "external-url", example = "http://10.0.1.1:33333")
4243
private String externalUrl;
4344

java/src/org/openqa/selenium/grid/server/BaseServerOptions.java

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,38 +84,48 @@ public int getMaxServerThreads() {
8484

8585
@ManagedAttribute(name = "Uri")
8686
public URI getExternalUri() {
87-
return config.get(SERVER_SECTION, "external-url")
88-
.map(url -> {
89-
try {
90-
return new URI(url);
91-
} catch (URISyntaxException e) {
92-
throw new RuntimeException("Supplied external URI is invalid: " + e.getMessage(), e);
93-
}
94-
})
95-
.orElseGet(() -> {
96-
// Assume the host given is addressable if it's been set
97-
String host =
98-
getHostname()
99-
.orElseGet(
100-
() -> {
101-
try {
102-
return new NetworkUtils().getNonLoopbackAddressOfThisMachine();
103-
} catch (WebDriverException e) {
104-
String name = HostIdentifier.getHostName();
105-
LOG.info("No network connection, guessing name: " + name);
106-
return name;
107-
}
108-
});
109-
110-
int port = getPort();
111-
112-
try {
113-
return new URI(
114-
(isSecure() || isSelfSigned()) ? "https" : "http", null, host, port, null, null, null);
115-
} catch (URISyntaxException e) {
116-
throw new ConfigException("Cannot determine external URI: " + e.getMessage());
117-
}
118-
});
87+
return config
88+
.get(SERVER_SECTION, "external-url")
89+
.map(
90+
url -> {
91+
try {
92+
return new URI(url);
93+
} catch (URISyntaxException e) {
94+
throw new RuntimeException(
95+
"Supplied external URI is invalid: " + e.getMessage(), e);
96+
}
97+
})
98+
.orElseGet(
99+
() -> {
100+
// Assume the host given is addressable if it's been set
101+
String host =
102+
getHostname()
103+
.orElseGet(
104+
() -> {
105+
try {
106+
return new NetworkUtils().getNonLoopbackAddressOfThisMachine();
107+
} catch (WebDriverException e) {
108+
String name = HostIdentifier.getHostName();
109+
LOG.info("No network connection, guessing name: " + name);
110+
return name;
111+
}
112+
});
113+
114+
int port = getPort();
115+
116+
try {
117+
return new URI(
118+
(isSecure() || isSelfSigned()) ? "https" : "http",
119+
null,
120+
host,
121+
port,
122+
null,
123+
null,
124+
null);
125+
} catch (URISyntaxException e) {
126+
throw new ConfigException("Cannot determine external URI: " + e.getMessage());
127+
}
128+
});
119129
}
120130

121131
public boolean getAllowCORS() {

java/test/org/openqa/selenium/grid/server/BaseServerOptionsTest.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,49 @@ void serverConfigBindsToHostByDefault() {
5050
@Test
5151
void externalUriFailsForNonUriStrings() {
5252
BaseServerOptions options =
53-
new BaseServerOptions(new MapConfig(Map.of("server", Map.of("external-url", "not a URL"))));
54-
55-
Exception exception = assertThrows(RuntimeException.class, () -> {
56-
options.getExternalUri();
57-
});
58-
59-
assertThat(exception.getMessage()).as("External URI must be parseable as URI.").isEqualTo("Supplied external URI is invalid: Illegal character in path at index 3: not a URL");
53+
new BaseServerOptions(new MapConfig(Map.of("server", Map.of("external-url", "not a URL"))));
54+
55+
Exception exception =
56+
assertThrows(
57+
RuntimeException.class,
58+
() -> {
59+
options.getExternalUri();
60+
});
61+
62+
assertThat(exception.getMessage())
63+
.as("External URI must be parseable as URI.")
64+
.isEqualTo(
65+
"Supplied external URI is invalid: Illegal character in path at index 3: not a URL");
6066
}
6167

6268
@Test
6369
void externalUriTakesPriorityOverDefaults() throws URISyntaxException {
6470
URI expected = new URI("http://10.0.1.1:33333");
6571

6672
BaseServerOptions options =
67-
new BaseServerOptions(new MapConfig(Map.of("server", Map.of(
68-
"external-url", expected.toString(),
69-
"host", "localhost",
70-
"port", 5555
71-
))));
73+
new BaseServerOptions(
74+
new MapConfig(
75+
Map.of(
76+
"server",
77+
Map.of(
78+
"external-url", expected.toString(), "host", "localhost", "port", 5555))));
7279

7380
assertThat(options.getExternalUri()).isEqualTo(expected);
7481
}
7582

7683
@Test
77-
void externalUriDefaultsToValueDerivedFromHostnameAndPortWhenNotDefined() throws URISyntaxException {
84+
void externalUriDefaultsToValueDerivedFromHostnameAndPortWhenNotDefined()
85+
throws URISyntaxException {
7886
URI expected = new URI("http://localhost:5555");
7987

8088
BaseServerOptions options =
81-
new BaseServerOptions(new MapConfig(Map.of("server", Map.of(
82-
"host", expected.getHost(),
83-
"port", expected.getPort()
84-
))));
89+
new BaseServerOptions(
90+
new MapConfig(
91+
Map.of(
92+
"server",
93+
Map.of(
94+
"host", expected.getHost(),
95+
"port", expected.getPort()))));
8596

8697
assertThat(options.getExternalUri()).isEqualTo(expected);
8798
}

0 commit comments

Comments
 (0)