Search in sources :

Example 1 with Content

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));
}
Also used : Contents(com.jcabi.github.Contents) Repo(com.jcabi.github.Repo) Content(com.jcabi.github.Content) Test(org.junit.Test)

Example 2 with Content

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));
}
Also used : Repo(com.jcabi.github.Repo) Content(com.jcabi.github.Content) Test(org.junit.Test)

Example 3 with Content

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;
}
Also used : XML(com.jcabi.xml.XML) Content(com.jcabi.github.Content) ArrayList(java.util.ArrayList) ToString(lombok.ToString)

Example 4 with Content

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));
}
Also used : Contents(com.jcabi.github.Contents) Content(com.jcabi.github.Content) Test(org.junit.Test)

Example 5 with Content

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));
}
Also used : Contents(com.jcabi.github.Contents) Content(com.jcabi.github.Content) Test(org.junit.Test)

Aggregations

Content (com.jcabi.github.Content)5 Test (org.junit.Test)4 Contents (com.jcabi.github.Contents)3 Repo (com.jcabi.github.Repo)2 XML (com.jcabi.xml.XML)1 ArrayList (java.util.ArrayList)1 ToString (lombok.ToString)1