Search in sources :

Example 1 with FkBase

use of io.wring.fake.FkBase in project wring by yegor256.

the class TkAppTest method rendersHomePageViaHttp.

/**
 * App can render front page.
 * @throws Exception If some problem inside
 */
@Test
public void rendersHomePageViaHttp() throws Exception {
    final Take app = new TkApp(new FkBase());
    new FtRemote(app).exec(home -> {
        new JdkRequest(home).fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK).as(XmlResponse.class).assertXPath("/xhtml:html");
        new JdkRequest(home).through(VerboseWire.class).header("Accept", "application/xml").fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK).as(XmlResponse.class).assertXPath("/page/version");
    });
}
Also used : Take(org.takes.Take) FkBase(io.wring.fake.FkBase) FtRemote(org.takes.http.FtRemote) JdkRequest(com.jcabi.http.request.JdkRequest) RestResponse(com.jcabi.http.response.RestResponse) XmlResponse(com.jcabi.http.response.XmlResponse) Test(org.junit.Test)

Example 2 with FkBase

use of io.wring.fake.FkBase in project wring by yegor256.

the class TkAppTest method rendersHomePage.

/**
 * App can render front page.
 * @throws Exception If some problem inside
 */
@Test
public void rendersHomePage() throws Exception {
    final Take take = new TkApp(new FkBase());
    MatcherAssert.assertThat(XhtmlMatchers.xhtml(new RsPrint(take.act(new RqWithHeaders(new RqFake("GET", "/"), "Accept: text/xml"))).printBody()), XhtmlMatchers.hasXPaths("/page/millis", "/page/links/link[@rel='takes:github']"));
}
Also used : Take(org.takes.Take) FkBase(io.wring.fake.FkBase) RqFake(org.takes.rq.RqFake) RsPrint(org.takes.rs.RsPrint) RqWithHeaders(org.takes.rq.RqWithHeaders) Test(org.junit.Test)

Example 3 with FkBase

use of io.wring.fake.FkBase in project wring by yegor256.

the class TkAppTest method rendersAllPossibleUrls.

/**
 * App can render all possible URLs.
 * @throws Exception If some problem inside
 */
@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void rendersAllPossibleUrls() throws Exception {
    final Take take = new TkApp(new FkBase());
    final String[] uris = { "/?x=y", "/robots.txt", "/xsl/layout.xsl", "/css/main.css", "/images/logo.svg", "/images/logo.png" };
    for (final String uri : uris) {
        MatcherAssert.assertThat(uri, take.act(new RqFake("INFO", uri)), Matchers.not(new HmRsStatus(HttpURLConnection.HTTP_NOT_FOUND)));
    }
}
Also used : Take(org.takes.Take) FkBase(io.wring.fake.FkBase) HmRsStatus(org.takes.facets.hamcrest.HmRsStatus) RqFake(org.takes.rq.RqFake) Test(org.junit.Test)

Example 4 with FkBase

use of io.wring.fake.FkBase in project wring by yegor256.

the class TkEventsTest method rendersListOfEvents.

/**
 * TkEvents can render list of events.
 * @throws Exception If some problem inside
 */
@Test
public void rendersListOfEvents() throws Exception {
    final Take take = new TkAppAuth(new TkEvents(new FkBase()));
    MatcherAssert.assertThat(XhtmlMatchers.xhtml(new RsPrint(take.act(new RqWithHeader(new RqFake("GET", "/"), "Accept", "text/xml"))).printBody()), XhtmlMatchers.hasXPaths("/page/millis", "/page/events/event", "/page/events/@total"));
}
Also used : Take(org.takes.Take) FkBase(io.wring.fake.FkBase) RqFake(org.takes.rq.RqFake) RsPrint(org.takes.rs.RsPrint) RqWithHeader(org.takes.rq.RqWithHeader) Test(org.junit.Test)

Example 5 with FkBase

use of io.wring.fake.FkBase in project wring by yegor256.

the class JsonAgentTest method makesAgent.

/**
 * JsonAgent can make an agent.
 * @throws Exception If some problem inside
 */
@Test
public void makesAgent() throws Exception {
    final Agent agent = new JsonAgent(new FkBase(), "{\"class\":\"io.wring.agents.FkAgent\"}");
    final Events events = Mockito.mock(Events.class);
    agent.push(events);
    Mockito.verify(events).post(Mockito.anyString(), Mockito.anyString());
}
Also used : FkBase(io.wring.fake.FkBase) Events(io.wring.model.Events) Test(org.junit.Test)

Aggregations

FkBase (io.wring.fake.FkBase)9 Test (org.junit.Test)9 Take (org.takes.Take)6 RqFake (org.takes.rq.RqFake)5 RsPrint (org.takes.rs.RsPrint)4 FkPipe (io.wring.fake.FkPipe)2 Base (io.wring.model.Base)2 Pipe (io.wring.model.Pipe)2 RqWithHeader (org.takes.rq.RqWithHeader)2 JdkRequest (com.jcabi.http.request.JdkRequest)1 RestResponse (com.jcabi.http.response.RestResponse)1 XmlResponse (com.jcabi.http.response.XmlResponse)1 Events (io.wring.model.Events)1 HmRsStatus (org.takes.facets.hamcrest.HmRsStatus)1 FtRemote (org.takes.http.FtRemote)1 RqWithHeaders (org.takes.rq.RqWithHeaders)1 Directives (org.xembly.Directives)1