use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtHooksTest method canFetchEmptyListOfHooks.
/**
* RtHooks can fetch empty list of hooks.
* @throws Exception if some problem inside
*/
@Test
public void canFetchEmptyListOfHooks() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[]")).start();
final Hooks hooks = new RtHooks(new JdkRequest(container.home()), RtHooksTest.repo());
try {
MatcherAssert.assertThat(hooks.iterate(), Matchers.emptyIterable());
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtIssuesTest method iterateIssues.
/**
* RtIssues can iterate issues.
* @throws Exception if there is any error
*/
@Test
public void iterateIssues() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(issue("new issue")).add(issue("code issue")).build().toString())).start(this.resource.port());
final RtIssues issues = new RtIssues(new JdkRequest(container.home()), repo());
MatcherAssert.assertThat(issues.iterate(new ArrayMap<String, String>()), Matchers.<Issue>iterableWithSize(2));
container.stop();
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtBlobsTest method canCreateBlob.
/**
* RtBlobs can create a blob.
*
* @throws Exception if some problem inside
*/
@Test
public void canCreateBlob() throws Exception {
final String content = "Content of the blob";
final String body = blob().toString();
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
final RtBlobs blobs = new RtBlobs(new ApacheRequest(container.home()), repo());
try {
final Blob blob = blobs.create(content, "utf-8");
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
MatcherAssert.assertThat(new Blob.Smart(blob).url(), Matchers.equalTo("http://localhost/1"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtBranchesTest method iteratesOverBranches.
/**
* RtBranches can iterate over all branches.
* @throws Exception if there is any error
*/
@Test
public void iteratesOverBranches() throws Exception {
final String firstname = "first";
final String firstsha = "a971b1aca044105897297b87b0b0983a54dd5817";
final String secondname = "second";
final String secondsha = "5d8dc2acf9c95d0d4e8881eebe04c2f0cbb249ff";
final MkAnswer answer = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(branch(firstname, firstsha)).add(branch(secondname, secondsha)).build().toString());
final MkContainer container = new MkGrizzlyContainer().next(answer).next(answer).start(this.resource.port());
final RtBranches branches = new RtBranches(new JdkRequest(container.home()), new MkGithub().randomRepo());
MatcherAssert.assertThat(branches.iterate(), Matchers.<Branch>iterableWithSize(2));
final Iterator<Branch> iter = branches.iterate().iterator();
final Branch first = iter.next();
MatcherAssert.assertThat(first.name(), Matchers.equalTo(firstname));
MatcherAssert.assertThat(first.commit().sha(), Matchers.equalTo(firstsha));
final Branch second = iter.next();
MatcherAssert.assertThat(second.name(), Matchers.equalTo(secondname));
MatcherAssert.assertThat(second.commit().sha(), Matchers.equalTo(secondsha));
container.stop();
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtCommentTest method patchesComment.
/**
* RtComment can patch a comment.
* @throws Exception - if anything goes wrong.
*/
@Test
public void patchesComment() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start(this.resource.port());
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("testing5", "issue5");
final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
final JsonObject jsonPatch = Json.createObjectBuilder().add("title", "test comment").build();
try {
comment.patch(jsonPatch);
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
} finally {
container.stop();
}
}
Aggregations