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();
}
}
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()));
}
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();
}
}
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();
}
}
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();
}
}
Aggregations