Search in sources :

Example 31 with MkQuery

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

the class RtReleaseAssetTest method rawAsset.

/**
 * RtReleaseAsset can stream raw content.
 * @throws Exception If a problem occurs.
 */
@Test
public void rawAsset() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start();
    final RtReleaseAsset asset = new RtReleaseAsset(new ApacheRequest(container.home()), release(), 4);
    try {
        final InputStream stream = asset.raw();
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.GET));
        MatcherAssert.assertThat(IOUtils.toString(stream, StandardCharsets.UTF_8), Matchers.notNullValue());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) InputStream(java.io.InputStream) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 32 with MkQuery

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

the class RtReleaseTest method editRelease.

/**
 * RtRelease can edit a release.
 * @throws Exception If any problem during test execution occurs.
 */
@Test
public final void editRelease() throws Exception {
    this.container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, EMPTY_JSON)).start();
    final RtRelease release = RtReleaseTest.release(this.container.home());
    final JsonObject json = Json.createObjectBuilder().add("tag_name", "v1.0.0").build();
    release.patch(json);
    final MkQuery query = this.container.take();
    MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
    MatcherAssert.assertThat(query.body(), Matchers.equalTo(json.toString()));
}
Also used : MkQuery(com.jcabi.http.mock.MkQuery) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 33 with MkQuery

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

the class RtReleasesTest method canDeleteRelease.

/**
 * RtReleases can delete a release.
 * @throws Exception If some problem inside
 */
@Test
public void canDeleteRelease() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final Releases releases = new RtReleases(new ApacheRequest(container.home()), RtReleasesTest.repo());
    try {
        releases.remove(1);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/releases/1"));
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 34 with MkQuery

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

the class RtStarsTest method starRepository.

/**
 * RtStars can star repository.
 *
 * @throws Exception If something goes wrong.
 */
@Test
public void starRepository() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).start();
    final String user = "staruser";
    final String repo = "starrepo";
    final Stars stars = new RtStars(new ApacheRequest(container.home()), RtStarsTest.repo(user, repo));
    try {
        stars.star();
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PUT));
        MatcherAssert.assertThat(query.uri().getPath(), Matchers.containsString(UriBuilder.fromPath(user).path(repo).build().getPath()));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 35 with MkQuery

use of com.jcabi.http.mock.MkQuery 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)

Aggregations

MkQuery (com.jcabi.http.mock.MkQuery)35 Test (org.junit.Test)35 MkContainer (com.jcabi.http.mock.MkContainer)34 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)34 ApacheRequest (com.jcabi.http.request.ApacheRequest)30 JsonObject (javax.json.JsonObject)9 MkGithub (com.jcabi.github.mock.MkGithub)6 MkAnswer (com.jcabi.http.mock.MkAnswer)6 JdkRequest (com.jcabi.http.request.JdkRequest)4 Request (com.jcabi.http.Request)1 FakeRequest (com.jcabi.http.request.FakeRequest)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1