Search in sources :

Example 1 with MkQuery

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();
    }
}
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 2 with MkQuery

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();
    }
}
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 3 with MkQuery

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 4 with MkQuery

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 5 with MkQuery

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) JsonObject(javax.json.JsonObject) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

MkQuery (com.jcabi.http.mock.MkQuery)35 Test (org.junit.Test)35 MkContainer (com.jcabi.http.mock.MkContainer)34 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)34 ApacheRequest (com.jcabi.http.request.ApacheRequest)30 JsonObject (javax.json.JsonObject)9 MkGithub (com.jcabi.github.mock.MkGithub)6 MkAnswer (com.jcabi.http.mock.MkAnswer)6 JdkRequest (com.jcabi.http.request.JdkRequest)4 Request (com.jcabi.http.Request)1 FakeRequest (com.jcabi.http.request.FakeRequest)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1