Search in sources :

Example 91 with MkGrizzlyContainer

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

the class RtCommitsTest method createsCommit.

/**
 * Tests creating a Commit.
 *
 * @throws Exception when an error occurs
 */
@Test
public final void createsCommit() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"sha\":\"0abcd89jcabitest\"}")).start(this.resource.port());
    final Commits commits = new RtCommits(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    final JsonObject author = Json.createObjectBuilder().add("name", "Scott").add("email", "scott@gmail.com").add("date", "2011-06-17T14:53:35-07:00").build();
    final JsonObject input = Json.createObjectBuilder().add("message", "initial version").add("author", author).build();
    try {
        final Commit newCommit = commits.create(input);
        MatcherAssert.assertThat(newCommit, Matchers.instanceOf(Commit.class));
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(newCommit.sha(), Matchers.equalTo("0abcd89jcabitest"));
    } 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 92 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer 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 93 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer 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 94 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer 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 95 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer 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)

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