Search in sources :

Example 1 with JdkRequest

use of com.jcabi.http.request.JdkRequest in project jcabi-github by jcabi.

the class RetryCarefulWireTest method makesMultipleRequestsAndWaitUntilReset.

/**
 * RetryCarefulWire can make a few requests before giving up and
 * can wait until the rate limit resets.
 * @throws Exception If something goes wrong inside
 */
@Test
public void makesMultipleRequestsAndWaitUntilReset() throws Exception {
    final int threshold = 10;
    // @checkstyle MagicNumber (2 lines)
    final long reset = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + 5L;
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK).withHeader(REMAINING_HEADER, "9").withHeader("X-RateLimit-Reset", String.valueOf(reset))).start();
    new JdkRequest(container.home()).through(RetryCarefulWire.class, threshold).fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK);
    final long now = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    MatcherAssert.assertThat(now, Matchers.greaterThanOrEqualTo(reset));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) RestResponse(com.jcabi.http.response.RestResponse) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 2 with JdkRequest

use of com.jcabi.http.request.JdkRequest 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 3 with JdkRequest

use of com.jcabi.http.request.JdkRequest in project jcabi-github by jcabi.

the class RtReleasesTest method canCreateRelease.

/**
 * RtReleases can create a release.
 * @throws Exception If some problem inside
 */
@Test
public void canCreateRelease() throws Exception {
    final String tag = "v1.0.0";
    final String rel = release(tag).toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, rel)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, rel)).start();
    final RtReleases releases = new RtReleases(new JdkRequest(container.home()), repo());
    final Release release = releases.create(tag);
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    MatcherAssert.assertThat(release.json().getString("tag_name"), Matchers.equalTo(tag));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 4 with JdkRequest

use of com.jcabi.http.request.JdkRequest in project jcabi-github by jcabi.

the class RtLabelsTest method createLabel.

/**
 * RtLabels can create a label.
 * @throws Exception if some problem inside
 */
@Test
public void createLabel() throws Exception {
    final String name = "API";
    final String color = "FFFFFF";
    final String body = label(name, color).toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
    final RtLabels labels = new RtLabels(new JdkRequest(container.home()), repo());
    final Label label = labels.create(name, color);
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    MatcherAssert.assertThat(new Label.Smart(label).name(), Matchers.equalTo(name));
    MatcherAssert.assertThat(new Label.Smart(label).color(), Matchers.equalTo(color));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 5 with JdkRequest

use of com.jcabi.http.request.JdkRequest in project jcabi-github by jcabi.

the class RtLabelsTest method iterateLabels.

/**
 * RtLabels can iterate labels.
 * @throws Exception if there is any error
 */
@Test
public void iterateLabels() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(label("new issue", "f29512")).add(label("new bug", "f29522")).build().toString())).start();
    final RtLabels labels = new RtLabels(new JdkRequest(container.home()), repo());
    MatcherAssert.assertThat(labels.iterate(), Matchers.<Label>iterableWithSize(2));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

JdkRequest (com.jcabi.http.request.JdkRequest)32 Test (org.junit.Test)32 MkContainer (com.jcabi.http.mock.MkContainer)31 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)31 MkAnswer (com.jcabi.http.mock.MkAnswer)8 MkQuery (com.jcabi.http.mock.MkQuery)4 MkGithub (com.jcabi.github.mock.MkGithub)2 RestResponse (com.jcabi.http.response.RestResponse)2 XmlResponse (com.jcabi.http.response.XmlResponse)1 ArrayMap (com.jcabi.immutable.ArrayMap)1 FkBase (io.wring.fake.FkBase)1 EnumMap (java.util.EnumMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Take (org.takes.Take)1 FtRemote (org.takes.http.FtRemote)1