Search in sources :

Example 61 with MkContainer

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

the class RtHooksTest method canFetchEmptyListOfHooks.

/**
 * RtHooks can fetch empty list of hooks.
 * @throws Exception if some problem inside
 */
@Test
public void canFetchEmptyListOfHooks() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[]")).start();
    final Hooks hooks = new RtHooks(new JdkRequest(container.home()), RtHooksTest.repo());
    try {
        MatcherAssert.assertThat(hooks.iterate(), Matchers.emptyIterable());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 62 with MkContainer

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

the class RtIssuesTest method iterateIssues.

/**
 * RtIssues can iterate issues.
 * @throws Exception if there is any error
 */
@Test
public void iterateIssues() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(issue("new issue")).add(issue("code issue")).build().toString())).start(this.resource.port());
    final RtIssues issues = new RtIssues(new JdkRequest(container.home()), repo());
    MatcherAssert.assertThat(issues.iterate(new ArrayMap<String, String>()), Matchers.<Issue>iterableWithSize(2));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) ArrayMap(com.jcabi.immutable.ArrayMap) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 63 with MkContainer

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

the class RtBlobsTest method canCreateBlob.

/**
 * RtBlobs can create a blob.
 *
 * @throws Exception if some problem inside
 */
@Test
public void canCreateBlob() throws Exception {
    final String content = "Content of the blob";
    final String body = blob().toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
    final RtBlobs blobs = new RtBlobs(new ApacheRequest(container.home()), repo());
    try {
        final Blob blob = blobs.create(content, "utf-8");
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(new Blob.Smart(blob).url(), Matchers.equalTo("http://localhost/1"));
    } 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 64 with MkContainer

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

the class RtBranchesTest method iteratesOverBranches.

/**
 * RtBranches can iterate over all branches.
 * @throws Exception if there is any error
 */
@Test
public void iteratesOverBranches() throws Exception {
    final String firstname = "first";
    final String firstsha = "a971b1aca044105897297b87b0b0983a54dd5817";
    final String secondname = "second";
    final String secondsha = "5d8dc2acf9c95d0d4e8881eebe04c2f0cbb249ff";
    final MkAnswer answer = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(branch(firstname, firstsha)).add(branch(secondname, secondsha)).build().toString());
    final MkContainer container = new MkGrizzlyContainer().next(answer).next(answer).start(this.resource.port());
    final RtBranches branches = new RtBranches(new JdkRequest(container.home()), new MkGithub().randomRepo());
    MatcherAssert.assertThat(branches.iterate(), Matchers.<Branch>iterableWithSize(2));
    final Iterator<Branch> iter = branches.iterate().iterator();
    final Branch first = iter.next();
    MatcherAssert.assertThat(first.name(), Matchers.equalTo(firstname));
    MatcherAssert.assertThat(first.commit().sha(), Matchers.equalTo(firstsha));
    final Branch second = iter.next();
    MatcherAssert.assertThat(second.name(), Matchers.equalTo(secondname));
    MatcherAssert.assertThat(second.commit().sha(), Matchers.equalTo(secondsha));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 65 with MkContainer

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

the class RtCommentTest method patchesComment.

/**
 * RtComment can patch a comment.
 * @throws Exception - if anything goes wrong.
 */
@Test
public void patchesComment() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start(this.resource.port());
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("testing5", "issue5");
    final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
    final JsonObject jsonPatch = Json.createObjectBuilder().add("title", "test comment").build();
    try {
        comment.patch(jsonPatch);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
    } 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) 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