PageRenderTime 31ms CodeModel.GetById 18ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/sitebricks-acceptance-tests/src/test/java/com/google/sitebricks/acceptance/page/I18nPage.java

http://github.com/dhanji/sitebricks
Java | 45 lines | 37 code | 8 blank | 0 comment | 0 complexity | 4b8534e0d5e8ff839631bfabef421d31 MD5 | raw file
 1package com.google.sitebricks.acceptance.page;
 2
 3import com.google.inject.Guice;
 4import com.google.sitebricks.acceptance.util.AcceptanceTest;
 5import com.google.sitebricks.client.Web;
 6import com.google.sitebricks.client.transport.Text;
 7import org.dom4j.DocumentException;
 8import org.dom4j.DocumentHelper;
 9
10import java.util.Map;
11
12public class I18nPage {
13  private final String content;
14  public static final String NAME = "Dhanji";
15
16  public I18nPage(String content) {
17    try {
18      this.content = DocumentHelper.parseText(content)
19          .selectSingleNode("//span['localizedMessage'][1]")
20          .getText();
21    } catch (DocumentException e) {
22      throw new RuntimeException(e);
23    }
24  }
25
26  public boolean hasHelloTo(String name) {
27    return content.trim().equals("Hello there " + name + "!");
28  }
29
30  public boolean hasBonjourTo(String name) {
31    return content.trim().equals("Bonjour misieu " + name + "!");
32  }
33
34  public static I18nPage openWithHeaders(Map<String, String> headers) {
35    String content = Guice.createInjector()
36        .getInstance(Web.class)
37        .clientOf(AcceptanceTest.baseUrl() + "/i18n?name=" + NAME, headers)
38        .transports(String.class)
39        .over(Text.class)
40        .get()
41        .toString();
42
43    return new I18nPage(content);
44  }
45}