Skip to content

Commit f7f1046

Browse files
committed
[WFLy-19465] refactoring the test case
1 parent f626adc commit f7f1046

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

spring-resteasy/src/test/java/org/jboss/as/quickstarts/resteasyspring/test/BasicRuntimeIT.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,18 @@
2727

2828
import static org.junit.Assert.assertEquals;
2929
import static org.junit.Assert.assertTrue;
30+
import static org.jboss.as.quickstarts.resteasyspring.test.TestUtils.getServerHost;
3031

3132
/**
3233
* The very basic runtime integration testing.
3334
* @author liweinan
3435
*/
3536
public class BasicRuntimeIT {
3637

37-
private static final String DEFAULT_SERVER_HOST = "http://localhost:8080/spring-resteasy/main";
38-
3938
@Test
4039
public void testHTTPEndpointIsAvailable() throws IOException, InterruptedException, URISyntaxException {
41-
String serverHost = System.getenv("SERVER_HOST");
42-
if (serverHost == null) {
43-
serverHost = System.getProperty("server.host");
44-
}
45-
if (serverHost == null) {
46-
serverHost = DEFAULT_SERVER_HOST;
47-
}
4840
final HttpRequest request = HttpRequest.newBuilder()
49-
.uri(new URI(serverHost+"/"))
41+
.uri(new URI(getServerHost()+"/"))
5042
.GET()
5143
.build();
5244
final HttpClient client = HttpClient.newBuilder()

spring-resteasy/src/test/java/org/jboss/as/quickstarts/resteasyspring/test/ResteasySpringIT.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.junit.Assert;
3434
import org.junit.BeforeClass;
3535
import org.junit.Test;
36+
import static org.jboss.as.quickstarts.resteasyspring.test.TestUtils.getServerHost;
3637

3738
/**
3839
* Basic unit tests for resteasy spring integration
@@ -42,18 +43,9 @@ public class ResteasySpringIT {
4243

4344
static URL url;
4445

45-
private static final String DEFAULT_SERVER_HOST = "http://localhost:8080/spring-resteasy/main";
46-
4746
@BeforeClass
4847
public static void setupUrl() throws MalformedURLException {
49-
String serverHost = System.getenv("SERVER_HOST");
50-
if (serverHost == null) {
51-
serverHost = System.getProperty("server.host");
52-
}
53-
if (serverHost == null) {
54-
serverHost = DEFAULT_SERVER_HOST;
55-
}
56-
url = URI.create(serverHost).toURL();
48+
url = URI.create(getServerHost()).toURL();
5749
}
5850

5951
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2024 JBoss by Red Hat.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.jboss.as.quickstarts.resteasyspring.test;
17+
18+
public class TestUtils {
19+
static final String DEFAULT_SERVER_HOST = "http://localhost:8080/spring-resteasy";
20+
static final String MAINPAGE_PATH = "/main";
21+
22+
static String getServerHost() {
23+
String serverHost = System.getenv("SERVER_HOST");
24+
if (serverHost == null) {
25+
serverHost = System.getProperty("server.host");
26+
}
27+
if (serverHost == null) {
28+
serverHost = DEFAULT_SERVER_HOST;
29+
}
30+
return serverHost + MAINPAGE_PATH;
31+
}
32+
}

0 commit comments

Comments
 (0)