Search in sources :

Example 56 with MkGithub

use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.

the class RtStatusesTest method createsStatus.

/**
 * Tests creating a Status.
 *
 * @throws Exception when an Error occurs
 */
@Test
public void createsStatus() throws Exception {
    final String stateprop = "state";
    final String urlprop = "target_url";
    final String descriptionprop = "description";
    final String contextprop = "context";
    final String url = "https://ci.example.com/1000/output";
    final String description = "Build has completed successfully";
    final String context = "continuous-integration/jenkins";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, Json.createObjectBuilder().add(stateprop, "failure").add(urlprop, url).add(descriptionprop, description).add(contextprop, context).build().toString())).start();
    final Request entry = new ApacheRequest(container.home());
    final Statuses statuses = new RtStatuses(entry, new RtCommit(entry, new MkGithub().randomRepo(), "0abcd89jcabitest"));
    try {
        statuses.create(new Statuses.StatusCreate(Status.State.FAILURE).withTargetUrl(Optional.of(url)).withDescription(description).withContext(Optional.of(context)));
        final MkQuery request = container.take();
        MatcherAssert.assertThat(request.method(), Matchers.equalTo(Request.POST));
        final JsonObject obj = Json.createReader(new StringReader(request.body())).readObject();
        MatcherAssert.assertThat(obj.getString(stateprop), Matchers.equalTo(Status.State.FAILURE.identifier()));
        MatcherAssert.assertThat(obj.getString(contextprop), Matchers.equalTo(context));
        MatcherAssert.assertThat(obj.getString(descriptionprop), Matchers.equalTo(description));
        MatcherAssert.assertThat(obj.getString(urlprop), Matchers.equalTo(url));
    } finally {
        container.stop();
    }
}
Also used : Request(com.jcabi.http.Request) ApacheRequest(com.jcabi.http.request.ApacheRequest) FakeRequest(com.jcabi.http.request.FakeRequest) MkQuery(com.jcabi.http.mock.MkQuery) JsonObject(javax.json.JsonObject) MkContainer(com.jcabi.http.mock.MkContainer) MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) StringReader(java.io.StringReader) MkGithub(com.jcabi.github.mock.MkGithub) Test(org.junit.Test)

Example 57 with MkGithub

use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.

the class RtTagTest method fetchesContent.

/**
 * RtTag can fetch its json.
 * @throws Exception - If something goes wrong.
 */
@Test
public void fetchesContent() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"sha\":\"abdes00test\",\"tag\":\"v.0.1\"}")).start();
    final Tag tag = new RtTag(new ApacheRequest(container.home()), new MkGithub().randomRepo(), "abdes00test");
    try {
        MatcherAssert.assertThat(tag.json().getString("tag"), Matchers.is("v.0.1"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

MkGithub (com.jcabi.github.mock.MkGithub)57 Test (org.junit.Test)55 MkContainer (com.jcabi.http.mock.MkContainer)40 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)40 ApacheRequest (com.jcabi.http.request.ApacheRequest)38 FakeRequest (com.jcabi.http.request.FakeRequest)10 MkAnswer (com.jcabi.http.mock.MkAnswer)7 MkQuery (com.jcabi.http.mock.MkQuery)6 JsonObject (javax.json.JsonObject)5 JdkRequest (com.jcabi.http.request.JdkRequest)2 Request (com.jcabi.http.Request)1 StringReader (java.io.StringReader)1