org.takes.rs.xe.RsXembly Java Examples

The following examples show how to use org.takes.rs.xe.RsXembly. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XeLogoutLinkTest.java    From takes with MIT License 6 votes vote down vote up
/**
 * XeLogoutLink can create a correct link.
 * @throws IOException If some problem inside
 */
@Test
public void generatesCorrectLink() throws IOException {
    MatcherAssert.assertThat(
        IOUtils.toString(
            new RsXembly(
                new XeAppend(
                    "root",
                    new XeLogoutLink(new RqFake())
                )
            ).body(),
            StandardCharsets.UTF_8
        ),
        XhtmlMatchers.hasXPaths(
            "/root/links/link[@rel='takes:logout']"
        )
    );
}
 
Example #2
Source File: XeIdentityTest.java    From takes with MIT License 6 votes vote down vote up
/**
 * XeIdentity can create a correct link.
 * @throws IOException If some problem inside
 */
@Test
public void generatesIdentityInXml() throws IOException {
    MatcherAssert.assertThat(
        IOUtils.toString(
            new RsXembly(
                new XeAppend(
                    "root",
                    new XeIdentity(
                        new RqWithHeader(
                            new RqFake(),
                            TkAuth.class.getSimpleName(),
                            "urn:test:1;name=Jeff"
                        )
                    )
                )
            ).body(),
            StandardCharsets.UTF_8
        ),
        XhtmlMatchers.hasXPaths(
            "/root/identity[urn='urn:test:1']",
            "/root/identity[name='Jeff']"
        )
    );
}
 
Example #3
Source File: XeGoogleLinkTest.java    From takes with MIT License 6 votes vote down vote up
/**
 * XeGoogleLink can create a correct link.
 * @throws IOException If some problem inside
 */
@Test
public void generatesCorrectLink() throws IOException {
    MatcherAssert.assertThat(
        IOUtils.toString(
            new RsXembly(
                new XeAppend(
                    "root",
                    new XeGoogleLink(new RqFake(), "abcdef")
                )
            ).body(),
            StandardCharsets.UTF_8
        ),
        XhtmlMatchers.hasXPaths(
            "/root/links/link[@rel='takes:google']"
        )
    );
}
 
Example #4
Source File: XeGithubLinkTest.java    From takes with MIT License 6 votes vote down vote up
/**
 * XeGithubLink can create a correct link.
 * @throws IOException If some problem inside
 */
@Test
public void generatesCorrectLink() throws IOException {
    MatcherAssert.assertThat(
        IOUtils.toString(
            new RsXembly(
                new XeAppend(
                    "root",
                    new XeGithubLink(new RqFake(), "abcdef")
                )
            ).body(),
            StandardCharsets.UTF_8
        ),
        XhtmlMatchers.hasXPaths(
            "/root/links/link[@rel='takes:github']"
        )
    );
}
 
Example #5
Source File: XeFacebookLinkTest.java    From takes with MIT License 6 votes vote down vote up
/**
 * XeFacebookLink can create a correct link.
 * @throws IOException If some problem inside
 */
@Test
public void generatesCorrectLink() throws IOException {
    MatcherAssert.assertThat(
        IOUtils.toString(
            new RsXembly(
                new XeAppend(
                    "root",
                    new XeFacebookLink(new RqFake(), "abcdef")
                )
            ).body(),
            StandardCharsets.UTF_8
        ),
        XhtmlMatchers.hasXPaths(
            "/root/links/link[@rel='takes:facebook']"
        )
    );
}
 
Example #6
Source File: RsPage.java    From jpeek with MIT License 5 votes vote down vote up
/**
 * Make it.
 * @param req Request
 * @param xsl XSL stylesheet
 * @param src Sources
 * @return Response
 */
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
private static Response make(final Request req, final String xsl,
    final Scalar<Iterable<XeSource>> src) {
    final Response raw = new RsXembly(
        new XeChain(
            new XeStylesheet(
                String.format("/org/jpeek/web/%s.xsl", xsl)
            ),
            new XeAppend(
                "page",
                new XeChain(
                    new XeMillis(),
                    new XeDirectives(new Header()),
                    new XeChain(src),
                    new XeMillis(true)
                )
            )
        )
    );
    return new RsFork(
        req,
        new FkTypes(
            "text/html",
            new RsXslt(new RsWithType(raw, "text/html"))
        ),
        new FkTypes(
            "application/vnd.jpeek+xml",
            new RsPrettyXml(new RsWithType(raw, "text/xml"))
        ),
        new FkTypes("*/*", raw)
    );
}
 
Example #7
Source File: RsPage.java    From takes with MIT License 5 votes vote down vote up
/**
 * Ctor.
 * @param xsl XSL stylesheet name
 * @param source Xembly source
 */
RsPage(final String xsl, final XeSource source) {
    this.origin = new RsXslt(
        new RsXembly(
            new XeStylesheet(xsl),
            new XeAppend(
                "page",
                new XeMillis(false),
                source,
                new XeMillis(true)
            )
        )
    );
}
 
Example #8
Source File: XeFlashTest.java    From takes with MIT License 5 votes vote down vote up
/**
 * XeFlash can accept RsFlash cookie.
 * @throws IOException If some problem inside
 */
@Test
public void acceptsRsFlashCookie() throws IOException {
    final Pattern pattern = Pattern.compile(
        "^Set-Cookie: RsFlash=(.*?);Path.*"
    );
    final Iterator<String> itr = new RsFlash("hello").head().iterator();
    final List<String> cookies = new ArrayList<>(0);
    while (itr.hasNext()) {
        final Matcher matcher = pattern.matcher(itr.next());
        if (matcher.find()) {
            cookies.add(matcher.group(1));
        }
    }
    MatcherAssert.assertThat(cookies, Matchers.hasSize(1));
    MatcherAssert.assertThat(
        IOUtils.toString(
            new RsXembly(
                new XeAppend(
                    "root",
                    new XeFlash(
                        new RqWithHeader(
                            new RqFake(),
                            "Cookie",
                            "RsFlash=".concat(cookies.get(0))
                        )
                    )
                )
            ).body(),
            StandardCharsets.UTF_8
        ),
        XhtmlMatchers.hasXPaths(
            "/root/flash[message='hello']",
            "/root/flash[level='INFO']"
        )
    );
}
 
Example #9
Source File: XeFlashTest.java    From takes with MIT License 5 votes vote down vote up
/**
 * XeFlash can accept RsFlash cookie.
 * @throws IOException If some problem inside
 */
@Test
public void rendersViaStandardXsltTemplate() throws IOException {
    MatcherAssert.assertThat(
        IOUtils.toString(
            new RsXslt(
                new RsXembly(
                    new XeStylesheet(
                        "/org/takes/facets/flash/test_flash.xsl"
                    ),
                    new XeAppend(
                        "page",
                        new XeFlash(
                            new RqWithHeaders(
                                new RqFake(),
                                "Cookie: RsFlash=how are you?/INFO"
                            )
                        )
                    )
                )
            ).body(),
            StandardCharsets.UTF_8
        ),
        XhtmlMatchers.hasXPaths(
            "/xhtml:html/xhtml:p[.='how are you?']",
            "/xhtml:html/xhtml:p[@class='flash flash-INFO']"
        )
    );
}
 
Example #10
Source File: RsPage.java    From jare with MIT License 4 votes vote down vote up
/**
 * Make it.
 * @param xsl XSL
 * @param req Request
 * @param src Source
 * @return Response
 * @throws IOException If fails
 */
private static Response make(final String xsl, final Request req,
    final Iterable<XeSource> src) throws IOException {
    final Response raw = new RsXembly(
        new XeStylesheet(xsl),
        new XeAppend(
            "page",
            new XeMillis(false),
            new XeChain(src),
            new XeLinkHome(req),
            new XeLinkSelf(req),
            new XeMillis(true),
            new XeDate(),
            new XeSla(),
            new XeLocalhost(),
            new XeFlash(req),
            new XeWhen(
                new RqAuth(req).identity().equals(Identity.ANONYMOUS),
                new XeChain(
                    new XeGithubLink(req, Manifests.read("Jare-GithubId"))
                )
            ),
            new XeWhen(
                !new RqAuth(req).identity().equals(Identity.ANONYMOUS),
                new XeChain(
                    new XeIdentity(req),
                    new XeLogoutLink(req),
                    new XeLink("domains", "/domains")
                )
            ),
            new XeAppend(
                "version",
                new XeAppend("name", Manifests.read("Jare-Version")),
                new XeAppend("revision", Manifests.read("Jare-Revision")),
                new XeAppend("date", Manifests.read("Jare-Date")),
                new XeAppend("heroku", RsPage.heroku())
            )
        )
    );
    return new RsFork(
        req,
        new FkTypes(
            "application/xml,text/xml",
            new RsPrettyXml(new RsWithType(raw, "text/xml"))
        ),
        new FkTypes(
            "*/*",
            new RsXslt(new RsWithType(raw, "text/html"))
        )
    );
}
 
Example #11
Source File: PsGithubTest.java    From takes with MIT License 4 votes vote down vote up
/**
 * Performs the basic login.
 * @param directive The directive object.
 * @throws Exception If some problem inside.
 */
private void performLogin(final Directives directive) throws Exception {
    final String app = "app";
    final String key = "key";
    final Take take = new TkFork(
        new FkRegex(
            "/login/oauth/access_token",
            new Take() {
                @Override
                public Response act(final Request req) throws IOException {
                    final Request greq = new RqGreedy(req);
                    final String code = "code";
                    PsGithubTest.assertParam(greq, code, code);
                    PsGithubTest.assertParam(greq, "client_id", app);
                    PsGithubTest.assertParam(greq, "client_secret", key);
                    return new RsXembly(
                        new XeDirectives(directive.toString())
                    );
                }
            }
        ),
        new FkRegex(
            "/user",
            new TkFakeLogin()
        )
    );
    new FtRemote(take).exec(
        // @checkstyle AnonInnerLengthCheck (100 lines)
        new FtRemote.Script() {
            @Override
            public void exec(final URI home) throws IOException {
                final Identity identity = new PsGithub(
                    app,
                    key,
                    home.toString(),
                    home.toString()
                ).enter(new RqFake("GET", "?code=code")).get();
                MatcherAssert.assertThat(
                    identity.urn(),
                    Matchers.equalTo("urn:github:1")
                );
                MatcherAssert.assertThat(
                    identity.properties().get(PsGithubTest.LOGIN),
                    Matchers.equalTo(PsGithubTest.OCTOCAT)
                );
                MatcherAssert.assertThat(
                    identity.properties().get("avatar"),
                    Matchers.equalTo(PsGithubTest.OCTOCAT_GIF_URL)
                );
            }
        }
    );
}