use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtGitignoresTest method iterateTemplateNames.
/**
* RtGitignores can iterate template names.
* @throws Exception if there is any error
*/
@Test
public void iterateTemplateNames() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add("C").add("Java").build().toString())).start();
final RtGitignores gitignores = new RtGitignores(new RtGithub(new JdkRequest(container.home())));
MatcherAssert.assertThat(gitignores.iterate(), Matchers.<String>iterableWithSize(2));
container.stop();
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtCollaboratorsTest method userCanBeAddedAsCollaborator.
/**
* User can be added to a repo as a collaborator.
* @throws Exception if any error occurs.
*/
@Test
public void userCanBeAddedAsCollaborator() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, Json.createArrayBuilder().add(RtCollaboratorsTest.json("octocat2")).add(RtCollaboratorsTest.json("dummy")).build().toString())).start(this.resource.port());
final Collaborators users = new RtCollaborators(new JdkRequest(container.home()), this.repo());
try {
users.add("dummy1");
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PUT));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtCommitTest method readsMessage.
/**
* Commit.Smart can read message.
* @throws Exception when an error occurs
*/
@Test
public final void readsMessage() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"sha\":\"a0b1c3\",\"commit\":{\"message\":\"hello\"}}")).start(this.resource.port());
try {
final Commit.Smart commit = new Commit.Smart(new RtCommit(new JdkRequest(container.home()), new MkGithub().randomRepo(), "sha"));
MatcherAssert.assertThat(commit.message(), Matchers.equalTo("hello"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtContentTest method fetchesRawContent.
/**
* RtContent should be able to fetch raw content.
*
* @throws Exception if a problem occurs.
*/
@Test
public void fetchesRawContent() throws Exception {
final String raw = "the raw \u20ac";
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, raw)).start(this.resource.port());
final InputStream stream = new RtContent(new ApacheRequest(container.home()), this.repo(), "raw").raw();
try {
MatcherAssert.assertThat(IOUtils.toString(stream, StandardCharsets.UTF_8), Matchers.is(raw));
MatcherAssert.assertThat(container.take().headers().get(HttpHeaders.ACCEPT).get(0), Matchers.is("application/vnd.github.v3.raw"));
} finally {
stream.close();
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtContentsTest method canCreateFileInRepository.
/**
* RtContents can create a file in the repository.
* @throws Exception If a problem occurs.
*/
@Test
public void canCreateFileInRepository() throws Exception {
final String path = "test/thefile";
final String name = "thefile";
final JsonObject body = Json.createObjectBuilder().add("path", path).add("name", name).build();
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, Json.createObjectBuilder().add("content", body).build().toString())).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())).start(this.resource.port());
final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
final JsonObject content = Json.createObjectBuilder().add("path", path).add("message", "theMessage").add("content", "blah").build();
try {
final Content.Smart smart = new Content.Smart(contents.create(content));
MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith(path));
MatcherAssert.assertThat(smart.path(), Matchers.is(path));
MatcherAssert.assertThat(smart.name(), Matchers.is(name));
MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/test/contents/contents/test/thefile"));
} finally {
container.stop();
}
}
Aggregations