Search in sources :

Example 96 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtForksTest method createsFork.

/**
 * RtForks should be able to create a new fork.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void createsFork() throws Exception {
    final String organization = RandomStringUtils.randomAlphanumeric(10);
    final MkAnswer answer = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fork(organization).toString());
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_ACCEPTED, fork(organization).toString())).next(answer).start(this.resource.port());
    final Repo owner = Mockito.mock(Repo.class);
    final Coordinates coordinates = new Coordinates.Simple("test_user", "test_repo");
    Mockito.doReturn(coordinates).when(owner).coordinates();
    final RtForks forks = new RtForks(new JdkRequest(container.home()), owner);
    final Fork fork = forks.create(organization);
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    MatcherAssert.assertThat(fork.json().getString(ORGANIZATION), Matchers.equalTo(organization));
    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 97 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtJsonTest method executePatchRequest.

/**
 * RtJson can execute PATCH request.
 *
 * @throws Exception if there is any problem
 */
@Test
public void executePatchRequest() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"body\":\"hj\"}")).start();
    final RtJson json = new RtJson(new ApacheRequest(container.home()));
    json.patch(Json.createObjectBuilder().add("content", "hi you!").build());
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo("PATCH"));
    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 98 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtLabelsTest method deleteLabel.

/**
 * RtLabels can delete a label.
 * @throws Exception if some problem inside
 */
@Test
public void deleteLabel() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final RtLabels issues = new RtLabels(new JdkRequest(container.home()), repo());
    issues.delete("issue");
    final MkQuery query = container.take();
    MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    MatcherAssert.assertThat(query.body(), Matchers.isEmptyOrNullString());
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 99 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtLabelsTest method getSingleLabel.

/**
 * RtLabels can get a single label.
 *
 * @throws Exception if some problem inside
 */
@Test
public void getSingleLabel() throws Exception {
    final String name = "bug";
    final String color = "f29513";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, label(name, color).toString())).start();
    final RtLabels issues = new RtLabels(new JdkRequest(container.home()), repo());
    final Label label = issues.get(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) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 100 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtMilestonesTest method deleteMilestone.

/**
 * RtMilestones can remove a milestone.
 * @throws Exception if some problem inside
 */
@Test
public void deleteMilestone() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
    try {
        final RtMilestones milestones = new RtMilestones(new ApacheRequest(container.home()), repo());
        milestones.remove(1);
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.DELETE));
    } finally {
        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)

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