Search in sources :

Example 26 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkGist method fork.

@Override
public Gist fork() throws IOException {
    this.storage.lock();
    final String number;
    try {
        final XML xml = this.storage.xml();
        number = Integer.toString(1 + xml.xpath("/github/gists/gist/id/text()").size());
        final Directives dirs = new Directives().xpath("/github/gists").add("gist").add("id").set(number).up().add("files");
        final List<XML> files = xml.nodes(String.format("%s/files/file", this.xpath()));
        for (final XML file : files) {
            final String filename = file.xpath("filename/text()").get(0);
            // @checkstyle MultipleStringLiterals (3 lines)
            dirs.add("file").add("filename").set(filename).up().add("raw_content").set(this.read(filename)).up().up();
        }
        this.storage.apply(dirs);
    } finally {
        this.storage.unlock();
    }
    return new MkGist(this.storage, this.self, number);
}
Also used : XML(com.jcabi.xml.XML) Directives(org.xembly.Directives) ToString(lombok.ToString)

Example 27 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkRepoCommitTest method canGetJson.

/**
 * MkRepoCommit can get a JSON.
 * @throws Exception if some problem inside
 */
@Test
public void canGetJson() throws Exception {
    final MkStorage storage = new MkStorage.InFile();
    storage.apply(new Directives().xpath("/github").add("repos").add("repo").attr("coords", "test_login/test_repo").add("commits").add("commit").add("sha").set(SHA1));
    final MkRepoCommit repoCommit = new MkRepoCommit(storage, this.repo(storage), SHA1);
    MatcherAssert.assertThat(repoCommit.json(), Matchers.notNullValue());
}
Also used : Directives(org.xembly.Directives) Test(org.junit.Test)

Example 28 with Directives

use of org.xembly.Directives in project wring by yegor256.

the class CycleTest method processesSinglePipeWithBrokenJson.

/**
 * Cycle can process a single pipe with broken JSOn.
 * @throws Exception If some problem inside
 */
@Test
public void processesSinglePipeWithBrokenJson() throws Exception {
    final Base base = new FkBase();
    final Pipe pipe = new FkPipe(new Directives().add("pipe").add("urn").set("urn:test:1").up().add("json").set("{\"a\":\"/@[a-z0-9\\\\-]\\\\s+\"}").up().up());
    new Cycle(base).exec(pipe);
}
Also used : FkBase(io.wring.fake.FkBase) Directives(org.xembly.Directives) Pipe(io.wring.model.Pipe) FkPipe(io.wring.fake.FkPipe) Base(io.wring.model.Base) FkBase(io.wring.fake.FkBase) FkPipe(io.wring.fake.FkPipe) Test(org.junit.Test)

Aggregations

Directives (org.xembly.Directives)28 ToString (lombok.ToString)12 Github (com.jcabi.github.Github)4 Map (java.util.Map)3 JsonValue (javax.json.JsonValue)3 JsonObject (javax.json.JsonObject)2 Test (org.junit.Test)2 Coordinates (com.jcabi.github.Coordinates)1 Issue (com.jcabi.github.Issue)1 Repo (com.jcabi.github.Repo)1 XML (com.jcabi.xml.XML)1 FkBase (io.wring.fake.FkBase)1 FkPipe (io.wring.fake.FkPipe)1 Base (io.wring.model.Base)1 Pipe (io.wring.model.Pipe)1 XePrint (io.wring.model.XePrint)1 HashSet (java.util.HashSet)1 JsonArray (javax.json.JsonArray)1 Href (org.takes.misc.Href)1 XeDirectives (org.takes.rs.xe.XeDirectives)1