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