Skip to content

Commit

Permalink
[WFLY-19450] refactoring test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sudeshnas93 committed Jun 25, 2024
1 parent fefce7d commit d5c3ded
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jboss.as.quickstarts.mail;

import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -26,6 +27,7 @@
import java.time.Duration;

import static org.junit.Assert.assertEquals;
import static org.jboss.as.quickstarts.mail.TestUtils.getServerHost;

/**
* The very basic runtime integration testing.
Expand All @@ -38,15 +40,9 @@ public class BasicRuntimeIT {

@Test
public void testHTTPEndpointIsAvailable() throws IOException, InterruptedException, URISyntaxException {
String serverHost = System.getenv("SERVER_HOST");
if (serverHost == null) {
serverHost = System.getProperty("server.host");
}
if (serverHost == null) {
serverHost = DEFAULT_SERVER_HOST;
}
HttpGet httpGet = new HttpGet(getServerHost());
final HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(serverHost))
.uri(new URI(getServerHost()))
.GET()
.build();
final HttpClient client = HttpClient.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

import static org.jboss.as.quickstarts.mail.TestUtils.getServerHost;

import java.time.Duration;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
Expand All @@ -37,15 +39,7 @@ public void testSetup() {
driver = new ChromeDriver(options);
driver.manage().window().maximize();

String serverHost = System.getenv("SERVER_HOST");
if (serverHost == null) {
serverHost = System.getProperty("server.host");
}
if (serverHost == null) {
serverHost = DEFAULT_SERVER_HOST;
}

driver.get(serverHost);
driver.get(getServerHost());
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
}

Expand Down
32 changes: 32 additions & 0 deletions mail/src/test/java/org/jboss/as/quickstarts/mail/TestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2024 JBoss by Red Hat.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.quickstarts.mail;

public class TestUtils {
static final String DEFAULT_SERVER_HOST = "http://localhost:8080/mail";
static final String API_PATH = "/home.jsf";

static String getServerHost() {
String serverHost = System.getenv("SERVER_HOST");
if (serverHost == null) {
serverHost = System.getProperty("server.host");
}
if (serverHost == null) {
serverHost = DEFAULT_SERVER_HOST;
}
return serverHost + API_PATH;
}
}

0 comments on commit d5c3ded

Please sign in to comment.