use of com.jcabi.http.mock.MkContainer 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.mock.MkContainer 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();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtJsonTest method sendHttpRequest.
/**
* RtJson can fetch HTTP request.
*
* @throws Exception if there is any problem
*/
@Test
public void sendHttpRequest() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"body\":\"hi\"}")).start();
final RtJson json = new RtJson(new ApacheRequest(container.home()));
MatcherAssert.assertThat(json.fetch().getString("body"), Matchers.equalTo("hi"));
container.stop();
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtLabelsTest method createLabel.
/**
* RtLabels can create a label.
* @throws Exception if some problem inside
*/
@Test
public void createLabel() throws Exception {
final String name = "API";
final String color = "FFFFFF";
final String body = label(name, color).toString();
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
final RtLabels labels = new RtLabels(new JdkRequest(container.home()), repo());
final Label label = labels.create(name, color);
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
MatcherAssert.assertThat(new Label.Smart(label).name(), Matchers.equalTo(name));
MatcherAssert.assertThat(new Label.Smart(label).color(), Matchers.equalTo(color));
container.stop();
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtLabelsTest method iterateLabels.
/**
* RtLabels can iterate labels.
* @throws Exception if there is any error
*/
@Test
public void iterateLabels() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(label("new issue", "f29512")).add(label("new bug", "f29522")).build().toString())).start();
final RtLabels labels = new RtLabels(new JdkRequest(container.home()), repo());
MatcherAssert.assertThat(labels.iterate(), Matchers.<Label>iterableWithSize(2));
container.stop();
}
Aggregations