Search in sources :

Example 21 with MkQuery

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

the class RtContentTest method patchWithJson.

/**
 * RtContent 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(this.resource.port());
    final RtContent content = new RtContent(new ApacheRequest(container.home()), this.repo(), "path");
    content.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) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 22 with MkQuery

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

the class RtContentsTest method canDeleteFilesFromRepository.

/**
 * RtContents can delete files from the repository.
 *
 * @throws Exception if a problem occurs.
 * @checkstyle MultipleStringLiteralsCheck (50 lines)
 */
@Test
public void canDeleteFilesFromRepository() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("commit", Json.createObjectBuilder().add("sha", "commitSha").build()).build().toString())).start(this.resource.port());
    final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
    try {
        final RepoCommit commit = contents.remove(Json.createObjectBuilder().add("path", "to/remove").add("message", "Delete me").add("sha", "fileSha").build());
        MatcherAssert.assertThat(commit.sha(), Matchers.is("commitSha"));
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.body(), Matchers.allOf(Matchers.containsString("\"message\":\"Delete me\""), Matchers.containsString("\"sha\":\"fileSha\"")));
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/contents/to/remove"));
    } 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 23 with MkQuery

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

the class RtContentsTest method canFetchReadmeFile.

/**
 * RtContents can fetch the default branch readme file.
 *
 * @throws Exception if some problem inside.
 */
@Test
public void canFetchReadmeFile() throws Exception {
    final String path = "README.md";
    final JsonObject body = Json.createObjectBuilder().add("path", path).build();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())).start(this.resource.port());
    final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
    try {
        MatcherAssert.assertThat(contents.readme().path(), Matchers.is(path));
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/readme"));
        MatcherAssert.assertThat(query.body().length(), Matchers.is(0));
    } 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 24 with MkQuery

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

the class RtDeployKeyTest method canDeleteDeployKey.

/**
 * RtDeployKey can delete a deploy key.
 *
 * @throws Exception If some problem inside.
 */
@Test
public void canDeleteDeployKey() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
    final DeployKey key = new RtDeployKey(new ApacheRequest(container.home()), 3, RtDeployKeyTest.repo());
    key.remove();
    final MkQuery query = container.take();
    MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    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 25 with MkQuery

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

the class RtLabelsTest method deleteLabel.

/**
 * RtLabels can delete a label.
 * @throws Exception if some problem inside
 */
@Test
public void deleteLabel() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final RtLabels issues = new RtLabels(new JdkRequest(container.home()), repo());
    issues.delete("issue");
    final MkQuery query = container.take();
    MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    MatcherAssert.assertThat(query.body(), Matchers.isEmptyOrNullString());
    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