use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtStarsTest method checkIfRepoStarred.
/**
* RtStars can check if repo is starred.
*
* @throws Exception If something goes wrong.
*/
@Test
public void checkIfRepoStarred() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_NOT_FOUND)).start();
try {
final Stars starred = new RtStars(new ApacheRequest(container.home()), RtStarsTest.repo("someuser", "starredrepo"));
MatcherAssert.assertThat(starred.starred(), Matchers.is(true));
final Stars unstarred = new RtStars(new ApacheRequest(container.home()), RtStarsTest.repo("otheruser", "notstarredrepo"));
MatcherAssert.assertThat(unstarred.starred(), Matchers.is(false));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtStarsTest method unstarRepository.
/**
* RtStars can unstar repository.
*
* @throws Exception If something goes wrong.
*/
@Test
public void unstarRepository() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).start();
final String user = "unstaruser";
final String repo = "unstarrepo";
final Stars stars = new RtStars(new ApacheRequest(container.home()), RtStarsTest.repo(user, repo));
try {
stars.unstar();
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
MatcherAssert.assertThat(query.uri().getPath(), Matchers.containsString(UriBuilder.fromPath(user).path(repo).build().getPath()));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtTagsTest method createsTag.
/**
* RtTags can create a tag.
* @throws Exception - If something goes wrong.
* @checkstyle IndentationCheck (20 lines)
*/
@Test
public void createsTag() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"sha\":\"0abcd89jcabitest\",\"tag\":\"v.0.1\"}")).next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"ref\":\"refs/heads/feature-a\"}")).start();
final Tags tags = new RtTags(new ApacheRequest(container.home()), new MkGithub().randomRepo());
final JsonObject tagger = Json.createObjectBuilder().add("name", "Scott").add("email", "scott@gmail.com").add("date", "2011-06-17T14:53:35-07:00").build();
final JsonObject input = Json.createObjectBuilder().add("tag", "v.0.1").add("message", "initial version").add("object", "07cd4r45Test444").add("type", "commit").add("tagger", tagger).build();
try {
MatcherAssert.assertThat(tags.create(input), Matchers.instanceOf(Tag.class));
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtTreesTest method createsTree.
/**
* RtTrees can create a tree.
* @throws Exception - If something goes wrong.
*/
@Test
public void createsTree() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"sha\":\"0abcd89jcabitest\",\"url\":\"http://localhost/1\"}")).start();
final Trees trees = new RtTrees(new ApacheRequest(container.home()), repo());
final JsonObject tree = Json.createObjectBuilder().add("path", "/path").add("mode", "100644 ").add("type", "blob").add("sha", "sha1").add("content", "content1").build();
final JsonObject input = Json.createObjectBuilder().add("tree", tree).add("base_tree", "SHA1").build();
try {
final Tree tri = trees.create(input);
MatcherAssert.assertThat(tri, Matchers.instanceOf(Tree.class));
MatcherAssert.assertThat(trees.get(tri.sha()), Matchers.equalTo(tri));
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtUserEmailsTest method addsEmails.
/**
* RtUserEmails can add emails.
* @throws Exception If some problem inside
*/
@Test
public void addsEmails() throws Exception {
final String email = "test1@email.com";
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, String.format("[{\"email\":\"%s\"}]", email)));
container.start();
try {
final UserEmails emails = new RtUserEmails(new ApacheRequest(container.home()));
MatcherAssert.assertThat(emails.add(Collections.singletonList(email)).iterator().next(), Matchers.equalTo(email));
} finally {
container.stop();
}
}
Aggregations