use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtOrganizationTest method canRepresentAsString.
/**
* RtOrganization can return a String representation correctly reflecting
* its URI.
*
* @throws Exception if something goes wrong.
*/
@Test
public void canRepresentAsString() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "blah")).start();
final RtOrganization org = new RtOrganization(new MkGithub(), new ApacheRequest(container.home()), "testToString");
try {
MatcherAssert.assertThat(org.toString(), Matchers.endsWith("/orgs/testToString"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtPullCommentTest method canDescribeAsJson.
/**
* RtPullComment can return its JSON description.
* @throws Exception If a problem occurs.
*/
@Test
public void canDescribeAsJson() throws Exception {
final String body = "{\"body\":\"test\"}";
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
final Pull pull = Mockito.mock(Pull.class);
Mockito.doReturn(repo()).when(pull).repo();
final RtPullComment comment = new RtPullComment(new ApacheRequest(container.home()), pull, 1);
try {
final JsonObject json = comment.json();
MatcherAssert.assertThat(json.getString("body"), Matchers.is("test"));
MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/joe/blueharvest/pulls/comments/1"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtPullCommentTest method patchesComment.
/**
* RtPullComment can create a patch request.
* @throws Exception If a problem occurs.
*/
@Test
public void patchesComment() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start();
final Pull pull = Mockito.mock(Pull.class);
Mockito.doReturn(repo()).when(pull).repo();
final RtPullComment comment = new RtPullComment(new ApacheRequest(container.home()), pull, 2);
try {
final JsonObject json = Json.createObjectBuilder().add("body", "test comment").build();
comment.patch(json);
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
MatcherAssert.assertThat(query.body(), Matchers.containsString("{\"body\":\"test comment\"}"));
MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/joe/blueharvest/pulls/comments/2"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtPullTest method fetchesFiles.
/**
* RtPull should be able to retrieve files.
*
* @throws Exception when a problem occurs.
*/
@Test
public void fetchesFiles() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"file1\":\"testFile\"}]")).start();
final RtPull pull = new RtPull(new ApacheRequest(container.home()), this.repo(), 2);
try {
MatcherAssert.assertThat(pull.files().iterator().next().getString("file1"), Matchers.equalTo("testFile"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtReferenceTest method returnsRef.
/**
* RtReference should be able to return its ref.
* @throws Exception - If something goes wrong.
*/
@Test
public void returnsRef() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"ref\":\"refs/heads/featureC\"}")).start();
final Reference reference = new RtReference(new ApacheRequest(container.home()), new MkGithub().randomRepo(), "refs/heads/featureC");
try {
MatcherAssert.assertThat(reference.ref(), Matchers.is("refs/heads/featureC"));
} finally {
container.stop();
}
}
Aggregations