Search in sources :

Example 71 with ApacheRequest

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

the class RtMilestonesTest method deleteMilestone.

/**
 * RtMilestones can remove a milestone.
 * @throws Exception if some problem inside
 */
@Test
public void deleteMilestone() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
    try {
        final RtMilestones milestones = new RtMilestones(new ApacheRequest(container.home()), repo());
        milestones.remove(1);
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.DELETE));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 72 with ApacheRequest

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

the class RtLabelTest method sendHttpRequestAndWriteResponseAsJson.

/**
 * RtLabel can  can fetch HTTP request and describe response as a JSON.
 *
 * @throws Exception if there is any problem
 */
@Test
public void sendHttpRequestAndWriteResponseAsJson() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"msg\": \"hi\"}")).start();
    final RtLabel label = new RtLabel(new ApacheRequest(container.home()), RtLabelTest.repo(), "bug");
    MatcherAssert.assertThat(label.json().getString("msg"), Matchers.equalTo("hi"));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 73 with ApacheRequest

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

the class RtOrganizationTest method patchWithJson.

/**
 * RtOrganization should be able to perform a patch request.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void patchWithJson() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "response")).start();
    final RtOrganization org = new RtOrganization(new MkGithub(), new ApacheRequest(container.home()), "testPatch");
    org.patch(Json.createObjectBuilder().add("patch", "test").build());
    final MkQuery query = container.take();
    try {
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
        MatcherAssert.assertThat(query.body(), Matchers.equalTo("{\"patch\":\"test\"}"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 74 with ApacheRequest

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

the class RtOrganizationsTest method retrievesOrganizations.

/**
 * RtOrganizations should be able to iterate
 * the logged-in user's organizations.
 *
 * @throws Exception If a problem occurs
 * @checkstyle MagicNumberCheck (25 lines)
 */
@Test
public void retrievesOrganizations() throws Exception {
    final Github github = new MkGithub();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(org(1, "org1")).add(org(2, "org2")).add(org(3, "org3")).build().toString())).start(this.resource.port());
    try {
        final Organizations orgs = new RtOrganizations(github, new ApacheRequest(container.home()));
        MatcherAssert.assertThat(orgs.iterate(), Matchers.<Organization>iterableWithSize(Tv.THREE));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/user/orgs"));
    } finally {
        container.stop();
    }
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 75 with ApacheRequest

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

the class RtOrganizationsTest method fetchesSingleOrganization.

/**
 * RtOrganizations should be able to get a single organization.
 *
 * @throws Exception if a problem occurs
 */
@Test
public void fetchesSingleOrganization() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start(this.resource.port());
    try {
        final Organizations orgs = new RtOrganizations(new MkGithub(), new ApacheRequest(container.home()));
        MatcherAssert.assertThat(orgs.get("org"), Matchers.notNullValue());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

ApacheRequest (com.jcabi.http.request.ApacheRequest)106 MkContainer (com.jcabi.http.mock.MkContainer)105 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)105 Test (org.junit.Test)105 MkGithub (com.jcabi.github.mock.MkGithub)38 MkQuery (com.jcabi.http.mock.MkQuery)30 MkAnswer (com.jcabi.http.mock.MkAnswer)24 JsonObject (javax.json.JsonObject)19 Request (com.jcabi.http.Request)5 JsonArray (javax.json.JsonArray)3 FakeRequest (com.jcabi.http.request.FakeRequest)2 InputStream (java.io.InputStream)2 ArrayMap (com.jcabi.immutable.ArrayMap)1 StringReader (java.io.StringReader)1