org.takes.facets.hamcrest.HmRsStatus Java Examples

The following examples show how to use org.takes.facets.hamcrest.HmRsStatus. 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: TkAppTest.java    From jpeek with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void pingsSimplePages(@TempDir final Path temp) throws Exception {
    final String[] pages = {
        "/org/jpeek/web/layout.xsl",
        "/org/jpeek/web/index.xsl",
        "/jpeek.css",
        "/",
        "/mistakes",
        "/robots.txt",
    };
    final Take app = new TkApp(temp);
    for (final String page : pages) {
        final Response response = app.act(new RqFake("GET", page));
        new Assertion<>(
            new RsPrint(response).print(),
            response,
            new HmRsStatus(HttpURLConnection.HTTP_OK)
        ).affirm();
    }
}
 
Example #2
Source File: TkCorsTest.java    From takes with MIT License 6 votes vote down vote up
/**
 * TkCORS can handle connections with correct domain on origin.
 * @throws Exception If some problem inside
 */
@Test
public void handleConnectionsWithCorrectDomainOnOrigin() throws Exception {
    MatcherAssert.assertThat(
        "Invalid HTTP status for a request with correct domain.",
        new TkCors(
            new TkFixed(new RsText()),
            "http://teamed.io",
            "http://example.com"
        ).act(
            new RqWithHeaders(
                new RqFake(),
                "Origin: http://teamed.io"
            )
        ),
        new HmRsStatus(HttpURLConnection.HTTP_OK)
    );
}
 
Example #3
Source File: ReportsTest.java    From jpeek with MIT License 5 votes vote down vote up
@Test
public void rendersOneReport(@TempDir final File folder) throws Exception {
    final BiFunc<String, String, Func<String, Response>> reports = new Reports(folder.toPath());
    new Assertion<>(
        "Must return HTTP 200 OK status",
        reports.apply("com.jcabi", "jcabi-urn").apply("index.html"),
        new HmRsStatus(HttpURLConnection.HTTP_OK)
    ).affirm();
    new Assertion<>(
        "Must return HTTP 200 OK status",
        reports.apply("com.jcabi", "jcabi-urn").apply("index.html"),
        new HmRsStatus(HttpURLConnection.HTTP_OK)
    ).affirm();
}
 
Example #4
Source File: AsyncReportsTest.java    From jpeek with MIT License 5 votes vote down vote up
@Test
public void rendersOneReport() throws Exception {
    final ExecutorService service = Executors.newSingleThreadExecutor();
    final BiFunc<String, String, Func<String, Response>> bifunc = new AsyncReports(
        new SolidBiFunc<>(
            (first, second) -> service.submit(
                () -> input -> {
                    TimeUnit.DAYS.sleep(1L);
                    return new RsText("done!");
                }
            )
        )
    );
    final Response response = bifunc.apply("org.jpeek", "jpeek").apply(
        "index.html"
    );
    new Assertion<>(
        "Must return HTTP NOT FOUND status",
        response,
        new HmRsStatus(HttpURLConnection.HTTP_NOT_FOUND)
    ).affirm();
    new Assertion<>(
        "Must have body in response",
        XhtmlMatchers.xhtml(new RsPrint(response).printBody()),
        XhtmlMatchers.hasXPath("//xhtml:body")
    ).affirm();
    service.shutdownNow();
}
 
Example #5
Source File: PingingTest.java    From jare with MIT License 5 votes vote down vote up
/**
 * App can render the URL.
 * @throws Exception If some problem inside
 */
@Test
public void rendersAllPossibleUrls() throws Exception {
    final Take take = new TkApp(new FkBase());
    MatcherAssert.assertThat(
        this.url,
        take.act(new RqFake("INFO", this.url)),
        Matchers.not(
            new HmRsStatus(
                HttpURLConnection.HTTP_NOT_FOUND
            )
        )
    );
}
 
Example #6
Source File: TkCorsTest.java    From takes with MIT License 5 votes vote down vote up
/**
 * TkCORS can handle connections without origin in the request.
 * @throws Exception If some problem inside
 */
@Test
public void handleConnectionsWithoutOriginInTheRequest() throws Exception {
    MatcherAssert.assertThat(
        "It was expected to receive a 403 error.",
        new TkCors(
            new TkFixed(new RsText()),
            "http://www.netbout.io",
            "http://www.example.com"
        ).act(new RqFake()),
        new HmRsStatus(HttpURLConnection.HTTP_FORBIDDEN)
    );
}