Search in sources :

Example 1 with ApacheRequest

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

the class RtUsersTest method iterateUsers.

/**
 * RtUsers can iterate users.
 * @throws Exception if there is any error
 */
@Test
public void iterateUsers() throws Exception {
    final String identifier = "1";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(RtUsersTest.json("octocat", identifier)).add(RtUsersTest.json("dummy", "2")).build().toString())).start();
    final Users users = new RtUsers(Mockito.mock(Github.class), new ApacheRequest(container.home()));
    MatcherAssert.assertThat(users.iterate(identifier), Matchers.<User>iterableWithSize(2));
    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 2 with ApacheRequest

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

the class RtUsersTest method getCurrentUser.

/**
 * RtUsers can get a current  user.
 *
 * @throws Exception  if there is any error
 */
@Test
public void getCurrentUser() throws Exception {
    final String login = "kendy";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, RtUsersTest.json(login, "4").toString())).start();
    final Users users = new RtUsers(Mockito.mock(Github.class), new ApacheRequest(container.home()));
    MatcherAssert.assertThat(users.self().login(), Matchers.equalTo(login));
    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 3 with ApacheRequest

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

the class RtPublicKeysTest method canRemoveKey.

/**
 * RtPublicKeys should be able to remove a key.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canRemoveKey() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final RtPublicKeys keys = new RtPublicKeys(new ApacheRequest(container.home()), Mockito.mock(User.class));
    try {
        keys.remove(1);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/user/keys/1"));
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    } 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 4 with ApacheRequest

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

the class RtPublicKeysTest method canCreatePublicKey.

/**
 * RtPublicKeys can create a key.
 * @throws IOException If some problem inside.
 */
@Test
public void canCreatePublicKey() throws IOException {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, key(1).toString())).start();
    try {
        final RtPublicKeys keys = new RtPublicKeys(new ApacheRequest(container.home()), Mockito.mock(User.class));
        MatcherAssert.assertThat(keys.create("theTitle", "theKey").number(), Matchers.is(1));
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/user/keys"));
        MatcherAssert.assertThat(query.body(), Matchers.equalTo("{\"title\":\"theTitle\",\"key\":\"theKey\"}"));
    } 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 5 with ApacheRequest

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

the class RtPublicKeysTest method retrievesKeys.

/**
 * RtPublicKeys should be able to iterate its keys.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void retrievesKeys() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(key(1)).add(key(2)).build().toString())).start();
    final RtPublicKeys keys = new RtPublicKeys(new ApacheRequest(container.home()), Mockito.mock(User.class));
    MatcherAssert.assertThat(keys.iterate(), Matchers.<PublicKey>iterableWithSize(2));
    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