Search in sources :

Example 51 with MkGithub

use of com.jcabi.github.mock.MkGithub 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 52 with MkGithub

use of com.jcabi.github.mock.MkGithub 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 53 with MkGithub

use of com.jcabi.github.mock.MkGithub 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 54 with MkGithub

use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.

the class RtUserOrganizationsTest method canIterateOrganizationsForUnauthUser.

/**
 * RtUserOrganizations can iterate organizations for
 * an unauthenticated user.
 *
 * @throws Exception If a problem occurs
 */
@Test
public void canIterateOrganizationsForUnauthUser() throws Exception {
    final String username = "octopus";
    final Github github = new MkGithub();
    final User user = github.users().get(username);
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(org(Tv.THREE, "org11")).add(org(Tv.FOUR, "org12")).add(org(Tv.FIVE, "org13")).build().toString())).start();
    try {
        final UserOrganizations orgs = new RtUserOrganizations(github, new ApacheRequest(container.home()), user);
        MatcherAssert.assertThat(orgs.iterate(), Matchers.<Organization>iterableWithSize(Tv.THREE));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith(String.format("/users/%s/orgs", username)));
    } finally {
        container.stop();
    }
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) 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 55 with MkGithub

use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.

the class RtReleaseAssetsTest method release.

/**
 * This method returns a Release for testing.
 * @return Release to be used for test.
 * @throws Exception - if anything goes wrong.
 */
private static Release release() throws Exception {
    final Release release = Mockito.mock(Release.class);
    final Repo repo = new MkGithub("john").randomRepo();
    Mockito.doReturn(repo).when(release).repo();
    Mockito.doReturn(1).when(release).number();
    return release;
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub)

Aggregations

MkGithub (com.jcabi.github.mock.MkGithub)57 Test (org.junit.Test)55 MkContainer (com.jcabi.http.mock.MkContainer)40 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)40 ApacheRequest (com.jcabi.http.request.ApacheRequest)38 FakeRequest (com.jcabi.http.request.FakeRequest)10 MkAnswer (com.jcabi.http.mock.MkAnswer)7 MkQuery (com.jcabi.http.mock.MkQuery)6 JsonObject (javax.json.JsonObject)5 JdkRequest (com.jcabi.http.request.JdkRequest)2 Request (com.jcabi.http.Request)1 StringReader (java.io.StringReader)1