Search in sources :

Example 66 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest 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 67 with ApacheRequest

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

the class RtEventTest method retrieveEventAsJson.

/**
 * RtEvent can be retrieved in JSON form.
 *
 * @throws Exception If a problem occurs.
 */
@Test
public void retrieveEventAsJson() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"test\":\"events\"}")).start(this.resource.port());
    final RtEvent event = new RtEvent(new ApacheRequest(container.home()), this.repo(), 3);
    try {
        MatcherAssert.assertThat(event.json().getString("test"), Matchers.equalTo("events"));
    } 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 68 with ApacheRequest

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

the class RtDeployKeysTest method canCreateDeployKey.

/**
 * RtDeployKeys can create a key.
 * @throws IOException If some problem inside.
 */
@Test
public void canCreateDeployKey() throws IOException {
    final int number = 2;
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, String.format("{\"id\":%d}", number)));
    container.start(this.resource.port());
    try {
        final DeployKeys keys = new RtDeployKeys(new ApacheRequest(container.home()), RtDeployKeysTest.repo());
        MatcherAssert.assertThat(keys.create("Title", "Key").number(), Matchers.equalTo(number));
    } 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 ApacheRequest

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

the class RtForkTest method patchAndCheckJsonFork.

/**
 * RtFork can patch comment and return new json.
 * @throws IOException if has some problems with json parsing.
 */
@Test
public void patchAndCheckJsonFork() throws IOException {
    final String original = "some organization";
    final String patched = "some patched organization";
    final MkContainer container = new MkGrizzlyContainer().next(this.answer(original)).next(this.answer(patched)).next(this.answer(original)).start(this.resource.port());
    final MkContainer forksContainer = new MkGrizzlyContainer().start(this.resource.port());
    final RtRepo repo = new RtRepo(new MkGithub(), new ApacheRequest(forksContainer.home()), new Coordinates.Simple("test_user", "test_repo"));
    final RtFork fork = new RtFork(new ApacheRequest(container.home()), repo, 1);
    fork.patch(RtForkTest.fork(patched));
    MatcherAssert.assertThat(new Fork.Smart(fork).organization(), Matchers.equalTo(patched));
    MatcherAssert.assertThat(new Fork.Smart(fork).name(), Matchers.notNullValue());
    container.stop();
    forksContainer.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)

Example 70 with ApacheRequest

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

the class RtJsonTest method executePatchRequest.

/**
 * RtJson can execute PATCH request.
 *
 * @throws Exception if there is any problem
 */
@Test
public void executePatchRequest() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"body\":\"hj\"}")).start();
    final RtJson json = new RtJson(new ApacheRequest(container.home()));
    json.patch(Json.createObjectBuilder().add("content", "hi you!").build());
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo("PATCH"));
    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)

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