KEYCLOAK-4368 Enable htmlUnit for adapter tests (not examples though)

This commit is contained in:
Hynek Mlnarik 2017-02-26 16:32:20 +01:00
parent 07f99a946d
commit 1970e03361
5 changed files with 29 additions and 21 deletions

View file

@ -65,7 +65,7 @@ public class SendUsernameServlet {
return Response.status(Response.Status.FORBIDDEN).entity("Forbidden").build(); return Response.status(Response.Status.FORBIDDEN).entity("Forbidden").build();
} }
return Response.ok(getOutput()).header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_TYPE + ";charset=UTF-8").build(); return Response.ok(getOutput()).header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML_TYPE + ";charset=UTF-8").build();
} }
@POST @POST

View file

@ -61,6 +61,11 @@
<artifactId>commons-configuration</artifactId> <artifactId>commons-configuration</artifactId>
<version>1.10</version> <version>1.10</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency> <dependency>
<groupId>org.keycloak.testsuite</groupId> <groupId>org.keycloak.testsuite</groupId>
<artifactId>integration-arquillian-testsuite-providers</artifactId> <artifactId>integration-arquillian-testsuite-providers</artifactId>

View file

@ -43,8 +43,8 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.*;
import static org.keycloak.testsuite.auth.page.AuthRealm.EXAMPLE; import static org.keycloak.testsuite.auth.page.AuthRealm.EXAMPLE;
import static org.keycloak.testsuite.util.IOUtil.loadRealm; import static org.keycloak.testsuite.util.IOUtil.loadRealm;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlDoesntStartWith; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlDoesntStartWith;
@ -479,7 +479,7 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
private void assertResponseError(String errorDescription) { private void assertResponseError(String errorDescription) {
jsConsoleTestAppPage.showErrorResponse(); jsConsoleTestAppPage.showErrorResponse();
assertTrue(jsConsoleTestAppPage.getOutputElement().getText().contains(errorDescription)); assertThat(jsConsoleTestAppPage.getOutputElement().getText(), containsString(errorDescription));
} }
} }

View file

@ -50,7 +50,7 @@ import org.keycloak.testsuite.auth.page.account.Applications;
import org.keycloak.testsuite.auth.page.login.OAuthGrant; import org.keycloak.testsuite.auth.page.login.OAuthGrant;
import org.keycloak.testsuite.console.page.events.Config; import org.keycloak.testsuite.console.page.events.Config;
import org.keycloak.testsuite.console.page.events.LoginEvents; import org.keycloak.testsuite.console.page.events.LoginEvents;
import org.keycloak.testsuite.util.URLUtils; import org.keycloak.testsuite.util.*;
import org.keycloak.util.BasicAuthHelper; import org.keycloak.util.BasicAuthHelper;
import org.openqa.selenium.By; import org.openqa.selenium.By;
@ -74,16 +74,13 @@ import java.util.regex.Pattern;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.keycloak.testsuite.util.Matchers;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.keycloak.testsuite.auth.page.AuthRealm.DEMO; import static org.keycloak.testsuite.auth.page.AuthRealm.DEMO;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWithLoginUrlOf; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWithLoginUrlOf;
import static org.keycloak.testsuite.util.WaitUtils.pause; import static org.keycloak.testsuite.util.WaitUtils.*;
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
/** /**
* *
@ -199,7 +196,9 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage); assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
testRealmLoginPage.form().login("bburke@redhat.com", "password"); testRealmLoginPage.form().login("bburke@redhat.com", "password");
assertCurrentUrlEquals(driver, inputPortal + "/secured/post"); assertCurrentUrlEquals(driver, inputPortal + "/secured/post");
waitUntilElement(By.xpath("//body")).text().contains("parameter=hello"); waitForPageToLoad(driver);
String pageSource = driver.getPageSource();
assertThat(pageSource, containsString("parameter=hello"));
String logoutUri = OIDCLoginProtocolService.logoutUrl(authServerPage.createUriBuilder()) String logoutUri = OIDCLoginProtocolService.logoutUrl(authServerPage.createUriBuilder())
.queryParam(OAuth2Constants.REDIRECT_URI, customerPortal.toString()) .queryParam(OAuth2Constants.REDIRECT_URI, customerPortal.toString())
@ -621,8 +620,10 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd
oAuthGrantPage.accept(); oAuthGrantPage.accept();
waitUntilElement(By.xpath("//body")).text().contains("Bill Burke"); String pageSource = driver.getPageSource();
waitUntilElement(By.xpath("//body")).text().contains("Stian Thorgersen"); waitForPageToLoad(driver);
assertThat(pageSource, containsString("Bill Burke"));
assertThat(pageSource, containsString("Stian Thorgersen"));
String userId = ApiUtil.findUserByUsername(testRealmResource(), "bburke@redhat.com").getId(); String userId = ApiUtil.findUserByUsername(testRealmResource(), "bburke@redhat.com").getId();
@ -673,8 +674,10 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd
testRealmLoginPage.form().login("bburke@redhat.com", "password"); testRealmLoginPage.form().login("bburke@redhat.com", "password");
waitUntilElement(By.xpath("//body")).text().contains("Bill Burke"); waitForPageToLoad(driver);
waitUntilElement(By.xpath("//body")).text().contains("Stian Thorgersen"); String pageSource = driver.getPageSource();
assertThat(pageSource, containsString("Bill Burke"));
assertThat(pageSource, containsString("Stian Thorgersen"));
String userId = ApiUtil.findUserByUsername(testRealmResource(), "bburke@redhat.com").getId(); String userId = ApiUtil.findUserByUsername(testRealmResource(), "bburke@redhat.com").getId();

View file

@ -84,9 +84,7 @@ import org.keycloak.testsuite.admin.ApiUtil;
import org.keycloak.testsuite.auth.page.login.Login; import org.keycloak.testsuite.auth.page.login.Login;
import org.keycloak.testsuite.auth.page.login.SAMLIDPInitiatedLogin; import org.keycloak.testsuite.auth.page.login.SAMLIDPInitiatedLogin;
import org.keycloak.testsuite.page.AbstractPage; import org.keycloak.testsuite.page.AbstractPage;
import org.keycloak.testsuite.util.IOUtil; import org.keycloak.testsuite.util.*;
import org.keycloak.testsuite.util.SamlClient;
import org.keycloak.testsuite.util.UserBuilder;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -133,7 +131,7 @@ import static org.keycloak.testsuite.util.Matchers.statusCodeIsHC;
import static org.keycloak.testsuite.util.SamlClient.idpInitiatedLogin; import static org.keycloak.testsuite.util.SamlClient.idpInitiatedLogin;
import static org.keycloak.testsuite.util.SamlClient.login; import static org.keycloak.testsuite.util.SamlClient.login;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith;
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement; import static org.keycloak.testsuite.util.WaitUtils.*;
/** /**
* @author mhajas * @author mhajas
@ -384,7 +382,7 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
private void checkLoggedOut(AbstractPage page, Login loginPage) { private void checkLoggedOut(AbstractPage page, Login loginPage) {
page.navigateTo(); page.navigateTo();
waitUntilElement(By.xpath("//body")).is().present(); waitForPageToLoad(driver);
assertCurrentUrlStartsWith(loginPage); assertCurrentUrlStartsWith(loginPage);
} }
@ -862,8 +860,10 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
assertCurrentUrlStartsWith(testRealmSAMLPostLoginPage); assertCurrentUrlStartsWith(testRealmSAMLPostLoginPage);
testRealmSAMLPostLoginPage.form().login("bburke", "password"); testRealmSAMLPostLoginPage.form().login("bburke", "password");
assertCurrentUrlStartsWith(employeeServletPage); assertCurrentUrlStartsWith(employeeServletPage);
waitUntilElement(By.xpath("//body")).text().contains("Relay state: " + SamlSPFacade.RELAY_STATE); waitForPageToLoad(driver);
waitUntilElement(By.xpath("//body")).text().not().contains("SAML response: null"); String pageSource = driver.getPageSource();
assertThat(pageSource, containsString("Relay state: " + SamlSPFacade.RELAY_STATE));
assertThat(pageSource, not(containsString("SAML response: null")));
} }
@Test @Test