Search in sources :

Example 31 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer 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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) JsonObject(javax.json.JsonObject) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 32 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer 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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 33 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer 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();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 34 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer 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();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 35 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer 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();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

MkContainer (com.jcabi.http.mock.MkContainer)136 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)136 Test (org.junit.Test)136 ApacheRequest (com.jcabi.http.request.ApacheRequest)105 MkGithub (com.jcabi.github.mock.MkGithub)40 MkQuery (com.jcabi.http.mock.MkQuery)34 MkAnswer (com.jcabi.http.mock.MkAnswer)32 JdkRequest (com.jcabi.http.request.JdkRequest)31 JsonObject (javax.json.JsonObject)19 Request (com.jcabi.http.Request)5 JsonArray (javax.json.JsonArray)3 FakeRequest (com.jcabi.http.request.FakeRequest)2 ArrayMap (com.jcabi.immutable.ArrayMap)2 InputStream (java.io.InputStream)2 RestResponse (com.jcabi.http.response.RestResponse)1 StringReader (java.io.StringReader)1 EnumMap (java.util.EnumMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1