Search in sources :

Example 46 with MkGithub

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

the class RtOrganizationsTest method retrievesOrganizations.

/**
 * RtOrganizations should be able to iterate
 * the logged-in user's organizations.
 *
 * @throws Exception If a problem occurs
 * @checkstyle MagicNumberCheck (25 lines)
 */
@Test
public void retrievesOrganizations() throws Exception {
    final Github github = new MkGithub();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(org(1, "org1")).add(org(2, "org2")).add(org(3, "org3")).build().toString())).start(this.resource.port());
    try {
        final Organizations orgs = new RtOrganizations(github, new ApacheRequest(container.home()));
        MatcherAssert.assertThat(orgs.iterate(), Matchers.<Organization>iterableWithSize(Tv.THREE));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/user/orgs"));
    } 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 47 with MkGithub

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

the class RtOrganizationsTest method fetchesSingleOrganization.

/**
 * RtOrganizations should be able to get a single organization.
 *
 * @throws Exception if a problem occurs
 */
@Test
public void fetchesSingleOrganization() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start(this.resource.port());
    try {
        final Organizations orgs = new RtOrganizations(new MkGithub(), new ApacheRequest(container.home()));
        MatcherAssert.assertThat(orgs.get("org"), Matchers.notNullValue());
    } 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 48 with MkGithub

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

the class RtPullCommentTest method canCompareInstances.

/**
 * RtPullComment should be able to compare different instances.
 * @throws Exception If a problem occurs.
 */
@Test
public void canCompareInstances() throws Exception {
    final Pull pull = Mockito.mock(Pull.class);
    Mockito.doReturn(new MkGithub().randomRepo()).when(pull).repo();
    final RtPullComment less = new RtPullComment(new FakeRequest(), pull, 1);
    final RtPullComment greater = new RtPullComment(new FakeRequest(), pull, 2);
    MatcherAssert.assertThat(less.compareTo(greater), Matchers.lessThan(0));
    MatcherAssert.assertThat(greater.compareTo(less), Matchers.greaterThan(0));
    MatcherAssert.assertThat(less.compareTo(less), Matchers.equalTo(0));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 49 with MkGithub

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

the class RtReferenceTest method fetchesContent.

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

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

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