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();
}
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");
});
}
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();
}
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();
}
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();
}
Aggregations