use of com.jcabi.github.Contents in project jcabi-github by jcabi.
the class MkContentsTest method updatesFile.
/**
* MkContents should be able to update a file.
* @throws Exception - if anything goes wrong.
*/
@Test
public void updatesFile() throws Exception {
final String path = "file.txt";
final String message = "content message";
final String initial = "initial text";
final String updated = "updated text";
final String cont = "content";
final Contents contents = new MkGithub().randomRepo().contents();
MatcherAssert.assertThat(contents.create(MkContentsTest.content(path, message, initial).build()).json().getString(cont), Matchers.is(initial));
contents.update(path, MkContentsTest.content(path, message, updated).build());
MatcherAssert.assertThat(contents.get(path, "master").json().getString(cont), Matchers.is(updated));
}
use of com.jcabi.github.Contents in project jcabi-github by jcabi.
the class MkContentsTest method updatesFileCreateCommit.
/**
* MkContents is able to update the file content.
* During update new commit is created
* @throws Exception Exception if some problem inside
*/
@Test
public void updatesFileCreateCommit() throws Exception {
final MkStorage storage = new MkStorage.InFile();
final Contents contents = MkContentsTest.repo(storage).contents();
final String path = "file.txt";
final JsonObject json = MkContentsTest.content(path, "theCreateMessage", "newContent").add("committer", MkContentsTest.committer()).build();
contents.create(json);
final String xpath = "/github/repos/repo/commits/commit";
MatcherAssert.assertThat(storage.xml().nodes(xpath), Matchers.<XML>iterableWithSize(1));
final JsonObject update = MkContentsTest.content(path, "theMessage", "blah").build();
MatcherAssert.assertThat(new RepoCommit.Smart(contents.update(path, update)).sha(), Matchers.not(Matchers.isEmptyOrNullString()));
MatcherAssert.assertThat(new Content.Smart(contents.get(path, "master")).path(), Matchers.is(path));
MatcherAssert.assertThat(storage.xml().nodes(xpath), Matchers.<XML>iterableWithSize(2));
}
use of com.jcabi.github.Contents in project jcabi-github by jcabi.
the class MkContentsTest method checkExists.
/**
* MkContents can check whether content exists or not.
* @throws Exception if any problem inside.
*/
@Test
public void checkExists() throws Exception {
final String path = "content-exist.txt";
final String branch = "rel.08";
final Contents contents = new MkGithub().randomRepo().contents();
contents.create(MkContentsTest.content(path, "commit", "content exists").add("ref", branch).build());
MatcherAssert.assertThat(contents.exists(path, branch), Matchers.is(true));
MatcherAssert.assertThat(contents.exists("content-not-exist.txt", branch), Matchers.is(false));
}
use of com.jcabi.github.Contents in project jcabi-github by jcabi.
the class MkContentsTest method createFile.
/**
* Creates a new file.
* @param repo The repository
* @param path Content path
* @return Created content
* @throws Exception if some problem inside
*/
private Content createFile(final Repo repo, final String path) throws Exception {
final Contents contents = repo.contents();
final JsonObject json = MkContentsTest.content(path, "theCreateMessage", "newContent").add("committer", MkContentsTest.committer()).build();
return contents.create(json);
}
use of com.jcabi.github.Contents in project jcabi-github by jcabi.
the class MkContentsTest method canFetchReadmeFromBranch.
/**
* MkContents should be able to fetch readme from a branch.
*
* @throws Exception if some problem inside
*/
@Test
public void canFetchReadmeFromBranch() throws Exception {
final String branch = "branch-1";
final Contents contents = new MkGithub().randomRepo().contents();
final String body = "Readme On Branch";
contents.create(content("README.md", "readme on branch", body).add("ref", branch).build());
MatcherAssert.assertThat(contents.readme(branch).json().getString("content"), Matchers.is(body));
}
Aggregations