diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/AbstractSeleniumTest.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/AbstractSeleniumTest.java index bc3c5ce079a..bf5ea15b39a 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/AbstractSeleniumTest.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/AbstractSeleniumTest.java @@ -40,6 +40,7 @@ import com.sap.sailing.selenium.core.WindowManager; import com.sap.sailing.selenium.pages.PageObject; import com.sap.sse.common.Duration; import com.sap.sse.common.impl.MillisecondsTimePoint; +import com.sun.jersey.api.container.httpserver.HttpServerFactory; /** *

Abstract base class for unit tests with Selenium. This class is already annotated as required to get executed @@ -64,6 +65,8 @@ public abstract class AbstractSeleniumTest { private static final String CLEAR_STATE_URL = "sailingserver/test-support/clearState"; //$NON-NLS-1$ + private static final String SWITCH_WHITELABEL_URL = "sailingserver/test-support/switch/whitelabel/"; //$NON-NLS-1$ + private static final String OBTAIN_ACCESS_TOKEN_URL = "security/api/restsecurity/access_token"; private static final String CREATE_SESSION_URL = "sailingserver/test-support/createSession"; @@ -136,8 +139,41 @@ public abstract class AbstractSeleniumTest { */ protected void clearState(String contextRoot) { clearState(contextRoot, false); + setWhitelabel(false, contextRoot); } + protected void setWhitelabel(boolean status, String contextRoot) { + try { + URL url = new URL(contextRoot + SWITCH_WHITELABEL_URL + Boolean.toString(status)); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("PUT"); + connection.connect(); + if (connection.getResponseCode() != 200) { + throw new RuntimeException(connection.getResponseMessage()); + } + } catch (IOException exception) { + throw new RuntimeException(exception); + } + } + + protected boolean getWhitelabel(String contextRoot) { + try { + URL url = new URL(contextRoot + SWITCH_WHITELABEL_URL + "status"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + if (connection.getResponseCode() != 200) { + throw new RuntimeException(connection.getResponseMessage()); + } + String response = (String)connection.getContent(); + return Boolean.valueOf(response); + } catch (IOException exception) { + throw new RuntimeException(exception); + } + } + + + protected void setUpAuthenticatedSession(WebDriver webDriver) { // To be able to set a cookie we need to load a page having the target origin webDriver.get(getContextRoot()); diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/home/WhitelabelTest.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/home/WhitelabelTest.java index bc6e71565fb..95af17954e0 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/home/WhitelabelTest.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/home/WhitelabelTest.java @@ -94,12 +94,13 @@ public class WhitelabelTest extends AbstractSeleniumTest { } details.linkRace(new RaceDescriptor("M", DEFAULT_FLEET, true, false, 0), new TrackedRaceDescriptor(REGATTA_49ER_WITH_SUFFIX, BOAT_CLASS_49ER, MEDAL_RACE_49ER)); } + setWhitelabel(true, getContextRoot()); } @Test public void testHomepageWhitelabel() throws UnsupportedEncodingException { - HomePage homePage = HomePage.goToPage(getWebDriver(), getContextRoot(), true); + HomePage homePage = HomePage.goToPage(getWebDriver(), getContextRoot()); assertThat(homePage.getPageTitle(), not(containsString("SAP")));