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();
}
}
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();
}
}
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();
}
}
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();
}
}
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;
}
Aggregations