Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page Objects Sometimes Want to be Headless #11

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e646990
let Page objects choose to return a headless-type Reply object for cu…
Nov 16, 2011
978ecab
sitebricks 0.8.5 tar.gz from github
Dec 12, 2011
087cbf7
0.8.5 sitebricks from github
Dec 12, 2011
01a0d7b
velocity template acceptance test passes
Dec 12, 2011
4e9c2a0
a bit of cleanup, no velocity.properties in sitebricks
Dec 12, 2011
4b177b1
ignore this 'DS_Store' directory that popped in from somewhere
Dec 12, 2011
a006768
AERO-245 update the pom files to set their distributionManagement rep…
Dec 13, 2011
b3b0204
should now return this for a forward-after-redirect as it will be put…
Dec 30, 2011
0c5972a
AERO-488 update the pom.xml to use nightflight for 'mvn deploy' to ar…
Jan 30, 2012
fc79934
lost this edit when I pulled the pennyclickui over-rides into this pr…
Jan 30, 2012
a2d7a01
Merge remote-tracking branch 'dhanji/master'
Feb 7, 2012
68ca143
velocity template support, let decorated page objects be wrapped by m…
Feb 7, 2012
9a0a1d3
sometimes pages want to be HEADLESS (this solution may be causing a s…
Feb 8, 2012
858d3a3
velocity tools in the context
Feb 9, 2012
e44f229
velocity tools in the context
Feb 9, 2012
bcb37fb
property-ize snapshotRepository of distributionManagement for slf4j (…
Feb 9, 2012
dbf4653
When running Guice State.PRODUCTION it was discovered that the pagesT…
Feb 14, 2012
6b85ae4
memory sharing issue in how (1) There is only one EmbedWidget per Pag…
Feb 14, 2012
40c5b9b
add source jar for sitebricks (main project)
Feb 16, 2012
6a93b9b
dorked up the merge when I brought the headless support over to the f…
Feb 21, 2012
4921289
testing teh velocity stuff and updating some converter tests
Apr 6, 2012
d84ac68
this change to WidgetRoutingDispatcher so that the Page put in Flashc…
May 17, 2012
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@
<!-- This should be removed when the googlecode repositories are migrated to the standard Nexus OSS repository infrastructure -->
<distributionManagement>
<snapshotRepository>
<id>google-snapshots</id>
<name>Sonatype OSS Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/google-snapshots</url>
<id>${snapshots.id}</id>
<name>${snapshots.name}</name>
<url>${snapshots.url}</url>
</snapshotRepository>
<repository>
<id>google-with-staging</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.google.sitebricks.example;

public class Custom {

private String encap;

public Custom() {
encap = "encapsulated valuev";
}

public Custom(String value) {
encap = value;
}

@Override
public String toString() {
return encap.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.google.sitebricks.example;

import com.google.sitebricks.At;
import com.google.sitebricks.http.Get;
import com.google.sitebricks.http.Post;

@At("/customConvertion")
public class CustomConverter {

public static final String INITIAL_VALUE = "initial value";
private Custom custom;

public CustomConverter() {
custom = new Custom(INITIAL_VALUE);
}

@Get
public void get() {
System.out.println("custom converter sample. woot!");
}

@Post
public void post() {
System.out.println("posted custom value: " + custom);
}

public Custom getTestValue() {
return custom;
}

public void setTestValue(Custom value) {
System.out.println("*************************** " + value);
custom = value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.google.sitebricks.example;

import com.google.sitebricks.conversion.Converter;

public class CustomToStringConverter implements Converter<String, Custom> {

@Override
public Custom to(String source) {
return new Custom(source);
}

@Override
public String from(Custom target) {
return target.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.google.sitebricks.example;

import com.google.sitebricks.headless.Reply;
import com.google.sitebricks.http.Get;

public class PageWithReply {

@Get
public Object get() {
return Reply.saying().status(678);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.Locale;
import java.util.Map;

import org.apache.velocity.runtime.directive.VelocimacroProxy;

/**
* @author Dhanji R. Prasanna ([email protected])
*/
Expand Down Expand Up @@ -62,6 +64,7 @@ protected void configureSitebricks() {
install(new StatModule("/stats"));

converter(new DateConverters.DateStringConverter(DEFAULT_DATE_TIME_FORMAT));
converter(new CustomToStringConverter());

install(new AwareModule() {
@Override
Expand All @@ -82,6 +85,7 @@ private void bindExplicitly() {
at("/repeat").show(Repeat.class);
at("/showif").show(ShowIf.class);
at("/dynamic.js").show(DynamicJs.class);
at("/pageWithReply").show(PageWithReply.class);

at("/conversion").show(Conversion.class);

Expand Down Expand Up @@ -109,6 +113,8 @@ private void bindExplicitly() {

// templating by extension
at("/template").show(DecoratedPage.class);
at("/velocitySample").show(VelocitySample.class);
at("/customConvertion").show(CustomConverter.class);

embed(HelloWorld.class).as("Hello");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.google.sitebricks.example;

import com.google.sitebricks.http.Get;

public class VelocitySample {

public static final String MSG = "Yaba Daba Doo!";

@Get
public void get() {
System.out.println("velocity sample. woot!");
}

public String getName() {
return "fred flinstone";
}

public String getMessage() {
return MSG;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<title>custom conversion sample</title>
</head>
<body>
<h1>velocity sample</h1>

<form>
<input type="text" value="${testValue}" name="testValue" id="testValue"/>
<button type="submit" id="submit">submit</button>
</form>


</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<p>for this test, the template will never be displayed because the page get method will always return a non-200 status code Reply</p>
</body>
</html>
11 changes: 11 additions & 0 deletions sitebricks-acceptance-tests/src/main/resources/VelocitySample.vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<title>velocity sample</title>
</head>
<body>
<h1>velocity sample</h1>
<h2>$page.name</h2>
<h2>$page.message</h2>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resource.loader = class
class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.google.sitebricks.acceptance;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

import com.google.sitebricks.acceptance.page.CustomConversionPage;
import com.google.sitebricks.acceptance.util.AcceptanceTest;
import com.google.sitebricks.example.CustomConverter;

@Test(suiteName = AcceptanceTest.SUITE)
public class CustomConverterAcceptanceTest {

public void hasConvertedTypes() {
WebDriver driver = AcceptanceTest.createWebDriver();
CustomConversionPage page = CustomConversionPage.open(driver);

WebElement testValueInputField = page.getTestValue();
String testValue = testValueInputField.getAttribute("value");
assert testValue.equals(CustomConverter.INITIAL_VALUE) : "expected " + CustomConverter.INITIAL_VALUE + " but was " + testValue;


String expected = "new value from test";
testValueInputField.sendKeys(expected);
testValueInputField.submit();
System.out.println(driver.getPageSource());

assert testValueInputField.getAttribute("value").equals(CustomConverter.INITIAL_VALUE + expected) : "expected " + CustomConverter.INITIAL_VALUE + expected + " but was " + testValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.google.sitebricks.acceptance;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import org.testng.annotations.Test;

import com.google.sitebricks.acceptance.util.AcceptanceTest;

@Test(suiteName = AcceptanceTest.SUITE)
public class PageWithReplyAcceptanceTest {

public void shouldReturnCustomStatusCode() throws IOException {
URL url = new URL(AcceptanceTest.BASE_URL + "/pageWithReply");

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
int expected = 678;
int actual = connection.getResponseCode();

assert actual == expected : "expected custom response code '" + expected + "' but was '" + actual + "'";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.google.sitebricks.acceptance;

import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;

import com.google.sitebricks.acceptance.page.VelocitySamplePage;
import com.google.sitebricks.acceptance.util.AcceptanceTest;

@Test(suiteName = AcceptanceTest.SUITE)
public class VelocitySampleAcceptanceTest {

public void shouldRenderDynamicTextFromVelocitySample() {
WebDriver driver = AcceptanceTest.createWebDriver();
VelocitySamplePage page = VelocitySamplePage.open(driver, "/velocitySample");

assertVelocitySampleContent(page);
}

private void assertVelocitySampleContent(VelocitySamplePage page) {
String title = page.getTitle();
assert title.equals("velocity sample") : title + " != \"velocity sample\"\n" + page.getContent();
assert page.hasMessage() : "did not have dynamic text";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.google.sitebricks.acceptance.page;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;

import com.google.sitebricks.acceptance.util.AcceptanceTest;

public class CustomConversionPage {

private WebElement testValue;

public static CustomConversionPage open(WebDriver driver) {
driver.get(AcceptanceTest.BASE_URL + "/customConvertion");
return PageFactory.initElements(driver, CustomConversionPage.class);
}

public WebElement getTestValue() {
return testValue;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.google.sitebricks.acceptance.page;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;

import com.google.sitebricks.acceptance.util.AcceptanceTest;
import com.google.sitebricks.example.VelocitySample;

public class VelocitySamplePage {
private final WebDriver driver;

public VelocitySamplePage(WebDriver driver) {
this.driver = driver;
}

public static VelocitySamplePage open(WebDriver driver, String url) {
driver.get(AcceptanceTest.BASE_URL + url);
return PageFactory.initElements(driver, VelocitySamplePage.class);
}

public String getTitle() {
return driver.getTitle();
}

public boolean hasMessage() {
// System.out.println(driver.getPageSource());
return driver.getPageSource().contains(VelocitySample.MSG);
}

public String getContent() {
return driver.getPageSource();
}
}
6 changes: 3 additions & 3 deletions sitebricks-async/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
standard Nexus OSS repository infrastructure -->
<distributionManagement>
<snapshotRepository>
<id>google-snapshots</id>
<name>Sonatype OSS Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/google-snapshots</url>
<id>${snapshots.id}</id>
<name>${snapshots.name}</name>
<url>${snapshots.url}</url>
</snapshotRepository>
<repository>
<id>google-with-staging</id>
Expand Down
Loading