|
4 | 4 |
|
5 | 5 | import java.io.File;
|
6 | 6 |
|
| 7 | +import org.eclipse.jetty.server.Server; |
| 8 | +import org.eclipse.jetty.server.handler.ResourceHandler; |
| 9 | +import org.junit.AfterClass; |
7 | 10 | import org.junit.Before;
|
8 | 11 | import org.junit.BeforeClass;
|
9 | 12 |
|
|
21 | 24 | @NoArgsConstructor(access = AccessLevel.PROTECTED)
|
22 | 25 | public class BaseIntegrationTest {
|
23 | 26 |
|
| 27 | + private static final String TEST_PAGE_SERVER_HOST = System.getProperty("testPageServerHost", "localhost"); |
| 28 | + |
| 29 | + private static final int TEST_PAGE_SERVER_PORT = Integer.parseInt(System.getProperty("testPageServerPort", "8080")); |
| 30 | + |
| 31 | + private static final String TEST_PAGE_SERVER_BASE_ADDRESS = String.format("http://%s:%d/", TEST_PAGE_SERVER_HOST, TEST_PAGE_SERVER_PORT); |
| 32 | + |
| 33 | + private static Server server; |
| 34 | + |
24 | 35 | private static Browser browser;
|
25 | 36 |
|
26 | 37 | @BeforeClass
|
27 |
| - public static void setUpBeforeClass() { |
| 38 | + public static void setupBrowser() { |
28 | 39 | if (browser == null) {
|
29 | 40 | browser = new TestBrowserFactory().createBrowser();
|
30 | 41 | }
|
31 | 42 | }
|
32 | 43 |
|
| 44 | + @BeforeClass |
| 45 | + public static void startTestPageServer() throws Exception { |
| 46 | + server = new Server(TEST_PAGE_SERVER_PORT); |
| 47 | + ResourceHandler resourceHandler = new ResourceHandler(); |
| 48 | + resourceHandler.setResourceBase(getTestResourceFolder().getCanonicalPath()); |
| 49 | + server.setHandler(resourceHandler); |
| 50 | + server.start(); |
| 51 | + } |
| 52 | + |
| 53 | + @AfterClass |
| 54 | + public static void stopTestPageServer() throws Exception { |
| 55 | + server.stop(); |
| 56 | + } |
| 57 | + |
33 | 58 | @Before
|
34 | 59 | public final void navigateToTestURL() {
|
35 | 60 | String htmlFilePath = getHTMLFilePath();
|
@@ -79,18 +104,13 @@ protected EventSystem eventSystem(){
|
79 | 104 | }
|
80 | 105 |
|
81 | 106 | protected static String getUrlFor(String fileName) {
|
| 107 | + assertThatFileResourceExists(fileName); |
| 108 | + return TEST_PAGE_SERVER_BASE_ADDRESS + fileName; |
| 109 | + } |
82 | 110 |
|
83 |
| - File testResourceFolder = getTestResourceFolder(); |
84 |
| - File testResourceFile = new File(testResourceFolder, fileName); |
85 |
| - |
| 111 | + private static void assertThatFileResourceExists(String fileName) { |
| 112 | + File testResourceFile = new File(getTestResourceFolder(), fileName); |
86 | 113 | assertThat(testResourceFile.isFile()).withFailMessage("file not found: " + testResourceFile).isTrue();
|
87 |
| - |
88 |
| - String systemDependentPath = testResourceFile.getAbsolutePath(); |
89 |
| - String replacedBackslashes = systemDependentPath.replaceAll("\\\\", "/"); |
90 |
| - String replacedWhitespaces = replacedBackslashes.replaceAll(" ", "%20"); |
91 |
| - |
92 |
| - return "file:///" + replacedWhitespaces; |
93 |
| - |
94 | 114 | }
|
95 | 115 |
|
96 | 116 | private static File getTestResourceFolder() {
|
|
0 commit comments