use of com.jcabi.http.mock.MkQuery 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.mock.MkQuery 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.mock.MkQuery in project jcabi-github by jcabi.
the class RtPublicMembersTest method iteratesPublicMembers.
/**
* RtPublicMembers can list the public members of the organization.
* @throws IOException If there is an I/O problem
*/
@Test
public void iteratesPublicMembers() throws IOException {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"login\":\"octobat\"}]")).next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR)).start();
try {
final RtPublicMembers members = new RtPublicMembers(new ApacheRequest(container.home()), organization());
members.iterate().iterator().next();
final MkQuery req = container.take();
MatcherAssert.assertThat(req.method(), Matchers.equalTo(Request.GET));
MatcherAssert.assertThat(req.uri().toString(), Matchers.endsWith(MEMBERS_URL));
this.thrown.expect(AssertionError.class);
members.iterate().iterator().next();
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkQuery in project jcabi-github by jcabi.
the class RtPublicMembersTest method concealsMembers.
/**
* RtPublicMembers can conceal a user's membership in the organization.
* @throws IOException If there is an I/O problem
*/
@Test
public void concealsMembers() throws IOException {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR)).start();
try {
final RtPublicMembers members = new RtPublicMembers(new ApacheRequest(container.home()), organization());
members.conceal(user());
final MkQuery req = container.take();
MatcherAssert.assertThat(req.method(), Matchers.equalTo(Request.DELETE));
MatcherAssert.assertThat(req.body(), Matchers.isEmptyOrNullString());
MatcherAssert.assertThat(req.uri().toString(), Matchers.endsWith(MEMBER_URL));
this.thrown.expect(AssertionError.class);
members.conceal(user());
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkQuery in project jcabi-github by jcabi.
the class RtReleaseAssetTest method patchesAsset.
/**
* RtReleaseAsset can create a patch request.
* @throws Exception If a problem occurs.
*/
@Test
public void patchesAsset() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start();
final RtReleaseAsset asset = new RtReleaseAsset(new ApacheRequest(container.home()), release(), 2);
try {
final JsonObject json = Json.createObjectBuilder().add("name", "hello").build();
asset.patch(json);
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
MatcherAssert.assertThat(query.body(), Matchers.containsString("{\"name\":\"hello\"}"));
MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/john/blueharvest/releases/assets/2"));
} finally {
container.stop();
}
}
Aggregations