Search in sources :

Example 66 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtCommentTest method removesComment.

/**
 * This tests that the remove() method is working fine.
 * @throws Exception - in case something goes wrong.
 */
@Test
public void removesComment() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("testing3", "issue3");
    final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
    try {
        comment.remove();
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    } 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 67 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtCommentTest method returnsItsJSon.

/**
 * RtComment can return its JSon description.
 * @throws Exception - if something goes wrong.
 */
@Test
public void returnsItsJSon() throws Exception {
    final String body = "{\"body\":\"test5\"}";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start(this.resource.port());
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("testing4", "issue4");
    final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
    try {
        final JsonObject json = comment.json();
        MatcherAssert.assertThat(json.getString("body"), Matchers.is("test5"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) JsonObject(javax.json.JsonObject) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 68 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtDeployKeysTest method canFetchNonEmptyListOfDeployKeys.

/**
 * RtDeployKeys can fetch non empty list of deploy keys.
 *
 * @throws IOException If some problem inside.
 */
@Test
public void canFetchNonEmptyListOfDeployKeys() throws IOException {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(key(1)).add(key(2)).build().toString()));
    container.start(this.resource.port());
    try {
        MatcherAssert.assertThat(new RtDeployKeys(new ApacheRequest(container.home()), RtDeployKeysTest.repo()).iterate(), Matchers.<DeployKey>iterableWithSize(2));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 69 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtGistCommentTest method patchAndCheckJsonGistComment.

/**
 * RtGistComment can patch comment and return new json.
 * @throws IOException if has some problems with json parsing.
 */
@Test
public final void patchAndCheckJsonGistComment() throws IOException {
    final int identifier = 1;
    final String idString = "id";
    final String bodyString = "body";
    final String body = "somebody";
    final String patchedBody = "some patchedbody";
    final MkAnswer first = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(bodyString, body).add(idString, identifier).build().toString());
    final MkAnswer second = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(bodyString, patchedBody).add(idString, identifier).build().toString());
    final MkAnswer third = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(bodyString, body).add(idString, identifier).build().toString());
    final MkContainer container = new MkGrizzlyContainer().next(first).next(second).next(third).start(this.resource.port());
    final MkContainer gistContainer = new MkGrizzlyContainer().start(this.resource.port());
    final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(gistContainer.home()), "someName");
    final RtGistComment comment = new RtGistComment(new ApacheRequest(container.home()), gist, identifier);
    comment.patch(Json.createObjectBuilder().add(bodyString, patchedBody).add(idString, identifier).build());
    MatcherAssert.assertThat(comment.json().getString(bodyString), Matchers.equalTo(patchedBody));
    container.stop();
    gistContainer.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 70 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtGistCommentTest method removeGistComment.

/**
 * RtGistComment can remove comment.
 * @throws IOException if has some problems with json parsing.
 */
@Test
public final void removeGistComment() throws IOException {
    final int identifier = 1;
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
    final RtGist gist = new RtGist(new MkGithub(), new FakeRequest().withStatus(HttpURLConnection.HTTP_NO_CONTENT), "gistName");
    final RtGistComment comment = new RtGistComment(new ApacheRequest(container.home()), gist, identifier);
    comment.remove();
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.DELETE));
    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) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Aggregations

MkContainer (com.jcabi.http.mock.MkContainer)136 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)136 Test (org.junit.Test)136 ApacheRequest (com.jcabi.http.request.ApacheRequest)105 MkGithub (com.jcabi.github.mock.MkGithub)40 MkQuery (com.jcabi.http.mock.MkQuery)34 MkAnswer (com.jcabi.http.mock.MkAnswer)32 JdkRequest (com.jcabi.http.request.JdkRequest)31 JsonObject (javax.json.JsonObject)19 Request (com.jcabi.http.Request)5 JsonArray (javax.json.JsonArray)3 FakeRequest (com.jcabi.http.request.FakeRequest)2 ArrayMap (com.jcabi.immutable.ArrayMap)2 InputStream (java.io.InputStream)2 RestResponse (com.jcabi.http.response.RestResponse)1 StringReader (java.io.StringReader)1 EnumMap (java.util.EnumMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1