Search in sources :

Example 81 with ApacheRequest

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

the class RtReferenceTest method returnsOwner.

/**
 * RtReference should be able to return its owner repo.
 * @throws Exception - If something goes wrong.
 */
@Test
public void returnsOwner() throws Exception {
    final Repo owner = new MkGithub().randomRepo();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"ref\":\"refs/heads/featureD\"}")).start();
    final Reference reference = new RtReference(new ApacheRequest(container.home()), owner, "refs/heads/featureD");
    try {
        MatcherAssert.assertThat(reference.repo(), Matchers.is(owner));
    } 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)

Example 82 with ApacheRequest

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

the class RtReferenceTest method patchesContent.

/**
 * RtReference should be able to execute patch.
 * @throws Exception - If something goes wrong.
 */
@Test
public void patchesContent() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"ref\":\"refs/heads/featureA\"}")).start();
    final Reference reference = new RtReference(new ApacheRequest(container.home()), new MkGithub().randomRepo(), "refs/heads/featureA");
    try {
        reference.patch(Json.createObjectBuilder().add("sha", "abcdef12345").add("force", "false").build());
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.PATCH));
    } 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)

Example 83 with ApacheRequest

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

the class RtReferencesTest method removesReference.

/**
 * RtReferences should be able to remove a Reference.
 * @throws Exception - If somethins goes wrong.
 */
@Test
public void removesReference() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final References refs = new RtReferences(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    refs.remove("heads/feature-a");
    try {
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.DELETE));
    } 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)

Example 84 with ApacheRequest

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

the class RtReferencesTest method createsReference.

/**
 * RtReferences should create and return a Reference.
 * @throws Exception - if something goes wrong.
 */
@Test
public void createsReference() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"ref\":\"refs/heads/feature-a\"}")).start();
    final References refs = new RtReferences(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    try {
        MatcherAssert.assertThat(refs.create("abceefgh3456", "refs/heads/feature-a"), Matchers.instanceOf(Reference.class));
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    } 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)

Example 85 with ApacheRequest

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

the class RtUserTest method executePatchRequest.

/**
 * RtUser can execute PATCH request.
 *
 * @throws Exception if there is any problem
 */
@Test
public void executePatchRequest() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"login\":\"octocate\"}")).start();
    final RtUser json = new RtUser(Mockito.mock(Github.class), new ApacheRequest(container.home()));
    json.patch(Json.createObjectBuilder().add("location", "San Francisco").build());
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.PATCH));
    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