use of com.jcabi.github.Content in project jcabi-github by jcabi.
the class MkContentTest method canGetOwnRepo.
/**
* MkContent should be able to fetch its own repo.
*
* @throws Exception if some problem inside
*/
@Test
public void canGetOwnRepo() throws Exception {
final Repo repo = new MkGithub().randomRepo();
final Contents contents = repo.contents();
final Content content = contents.create(jsonContent("repo.txt", "for repo", "json repo"));
MatcherAssert.assertThat(content.repo(), Matchers.is(repo));
}
use of com.jcabi.github.Content in project jcabi-github by jcabi.
the class MkContentsTest method canIterate.
/**
* Tests if MkContents is iterable by path.
* @throws IOException if any error occurs.
*/
@Test
public void canIterate() throws IOException {
final MkStorage storage = new MkStorage.InFile();
final Repo repo = repo(storage);
final Content[] correct = this.addContent(repo, "foo/bar/1", "foo/bar/2");
this.addContent(repo, "foo/baz", "foo/boo");
MatcherAssert.assertThat(repo.contents().iterate("foo/bar", "ref-1"), Matchers.contains(correct));
}
use of com.jcabi.github.Content in project jcabi-github by jcabi.
the class MkContents method iterate.
@Override
public Iterable<Content> iterate(final String pattern, final String ref) throws IOException {
final Collection<XML> nodes = this.storage.xml().nodes(String.format("%s/content[@ref='%s']", this.xpath(), ref));
final Collection<Content> result = new ArrayList<Content>(nodes.size());
for (final XML node : nodes) {
final String path = node.xpath("path/text()").get(0);
if (path.startsWith(pattern)) {
result.add(this.mkContent(ref, path));
}
}
return result;
}
use of com.jcabi.github.Content in project jcabi-github by jcabi.
the class MkContentTest method fetchesJsonRepresentation.
/**
* MkContent should be able to fetch its JSON representation.
*
* @throws Exception if some problem inside
*/
@Test
public void fetchesJsonRepresentation() throws Exception {
final Contents contents = new MkGithub().randomRepo().contents();
final String path = "fake.txt";
final Content content = contents.create(jsonContent(path, "for json", "json test"));
MatcherAssert.assertThat(// @checkstyle MultipleStringLiterals (1 line)
content.json().getString("name"), Matchers.is(path));
}
use of com.jcabi.github.Content in project jcabi-github by jcabi.
the class MkContentTest method canGetOwnPath.
/**
* MkContent should be able to fetch its own path.
*
* @throws Exception if some problem inside
*/
@Test
public void canGetOwnPath() throws Exception {
final Contents contents = new MkGithub().randomRepo().contents();
final String path = "dummy.txt";
final Content content = contents.create(jsonContent(path, "for path", "path test"));
MatcherAssert.assertThat(content.path(), Matchers.is(path));
}