Search in sources :

Example 6 with MkQuery

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

the class RtReleaseAssetTest method removesAsset.

/**
 * RtReleaseAsset can remove itself.
 * @throws Exception If a problem occurs.
 */
@Test
public void removesAsset() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final RtReleaseAsset asset = new RtReleaseAsset(new ApacheRequest(container.home()), release(), 3);
    try {
        asset.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) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 7 with MkQuery

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

the class RtReposTest method removeRepo.

/**
 * RtRepos can remove a repo.
 * @throws Exception if some problem inside
 */
@Test
public void removeRepo() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final Repos repos = new RtRepos(Mockito.mock(Github.class), new ApacheRequest(container.home()));
    repos.remove(new Coordinates.Simple("", ""));
    try {
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
        MatcherAssert.assertThat(query.body(), Matchers.isEmptyString());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 8 with MkQuery

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

the class RtPullCommentTest method patchesComment.

/**
 * RtPullComment can create a patch request.
 * @throws Exception If a problem occurs.
 */
@Test
public void patchesComment() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start();
    final Pull pull = Mockito.mock(Pull.class);
    Mockito.doReturn(repo()).when(pull).repo();
    final RtPullComment comment = new RtPullComment(new ApacheRequest(container.home()), pull, 2);
    try {
        final JsonObject json = Json.createObjectBuilder().add("body", "test comment").build();
        comment.patch(json);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
        MatcherAssert.assertThat(query.body(), Matchers.containsString("{\"body\":\"test comment\"}"));
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/joe/blueharvest/pulls/comments/2"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) JsonObject(javax.json.JsonObject) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 9 with MkQuery

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

the class RtStarsTest method unstarRepository.

/**
 * RtStars can unstar repository.
 *
 * @throws Exception If something goes wrong.
 */
@Test
public void unstarRepository() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).start();
    final String user = "unstaruser";
    final String repo = "unstarrepo";
    final Stars stars = new RtStars(new ApacheRequest(container.home()), RtStarsTest.repo(user, repo));
    try {
        stars.unstar();
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
        MatcherAssert.assertThat(query.uri().getPath(), Matchers.containsString(UriBuilder.fromPath(user).path(repo).build().getPath()));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 10 with MkQuery

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

the class RtCollaboratorsTest method userCanBeAddedAsCollaborator.

/**
 * User can be added to a repo as a collaborator.
 * @throws Exception if any error occurs.
 */
@Test
public void userCanBeAddedAsCollaborator() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, Json.createArrayBuilder().add(RtCollaboratorsTest.json("octocat2")).add(RtCollaboratorsTest.json("dummy")).build().toString())).start(this.resource.port());
    final Collaborators users = new RtCollaborators(new JdkRequest(container.home()), this.repo());
    try {
        users.add("dummy1");
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PUT));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

MkQuery (com.jcabi.http.mock.MkQuery)35 Test (org.junit.Test)35 MkContainer (com.jcabi.http.mock.MkContainer)34 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)34 ApacheRequest (com.jcabi.http.request.ApacheRequest)30 JsonObject (javax.json.JsonObject)9 MkGithub (com.jcabi.github.mock.MkGithub)6 MkAnswer (com.jcabi.http.mock.MkAnswer)6 JdkRequest (com.jcabi.http.request.JdkRequest)4 Request (com.jcabi.http.Request)1 FakeRequest (com.jcabi.http.request.FakeRequest)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1