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();
}
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();
}
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();
}
}
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();
}
}
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();
}
Aggregations