Search in sources :

Example 86 with MkContainer

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

the class RtContentsTest method canIterateDirectoryContents.

/**
 * RtContents can iterate through a directory's contents.
 * @throws Exception If something goes wrong.
 */
@Test
public void canIterateDirectoryContents() throws Exception {
    final JsonArray body = Json.createArrayBuilder().add(Json.createObjectBuilder().add("path", "README.md").build()).add(Json.createObjectBuilder().add("path", ".gitignore").build()).build();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())).next(new MkAnswer.Simple("{\"path\":\"README.md\"}")).next(new MkAnswer.Simple("{\"path\":\".gitignore\"}")).start(this.resource.port());
    final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
    try {
        MatcherAssert.assertThat(contents.iterate("dir", "branch2"), Matchers.<Content>iterableWithSize(2));
    } finally {
        container.stop();
    }
}
Also used : JsonArray(javax.json.JsonArray) 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 87 with MkContainer

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

the class RtAssigneesTest method checkUserIsAssigneeForRepo.

/**
 * RtAssignees can check if user is assignee for this repo.
 * @throws Exception Exception If some problem inside
 */
@Test
public void checkUserIsAssigneeForRepo() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, Json.createArrayBuilder().add(RtAssigneesTest.json("octocat2")).add(RtAssigneesTest.json("dummy")).build().toString())).start(this.resource.port());
    final Assignees users = new RtAssignees(new JdkRequest(container.home()), this.repo());
    MatcherAssert.assertThat(users.check("octocat2"), Matchers.equalTo(true));
    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 88 with MkContainer

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

the class RtAssigneesTest method checkUserIsNotAssigneeForRepo.

/**
 * RtAssignees can check if user is NOT assignee for this repo.
 * @throws Exception Exception If some problem inside
 */
@Test
public void checkUserIsNotAssigneeForRepo() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NOT_FOUND, Json.createArrayBuilder().add(RtAssigneesTest.json("octocat3")).add(RtAssigneesTest.json("dummy")).build().toString())).start(this.resource.port());
    final Assignees users = new RtAssignees(new JdkRequest(container.home()), this.repo());
    MatcherAssert.assertThat(users.check("octocat33"), Matchers.equalTo(false));
    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 89 with MkContainer

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

the class RtAssigneesTest method iteratesAssignees.

/**
 * RtAssignees can iterate over assignees.
 * @throws Exception Exception If some problem inside
 */
@Test
public void iteratesAssignees() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(RtAssigneesTest.json("octocat")).add(RtAssigneesTest.json("dummy")).build().toString())).start(this.resource.port());
    final Assignees users = new RtAssignees(new JdkRequest(container.home()), this.repo());
    MatcherAssert.assertThat(users.iterate(), Matchers.<User>iterableWithSize(2));
    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 90 with MkContainer

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

the class RtCommentTest method givesToString.

/**
 * This tests that the toString() method is working fine.
 * @throws Exception - if anything goes wrong.
 */
@Test
public void givesToString() 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("testing6", "issue6");
    final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
    try {
        final String stringComment = comment.toString();
        MatcherAssert.assertThat(stringComment, Matchers.not(Matchers.isEmptyOrNullString()));
        MatcherAssert.assertThat(stringComment, Matchers.endsWith("10"));
    } finally {
        container.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