Search in sources :

Example 1 with Contents

use of com.jcabi.github.Contents 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 Contents

use of com.jcabi.github.Contents in project jcabi-github by jcabi.

the class MkContentTest method fetchesRawRepresentation.

/**
 * MkContent should be able to fetch its raw representation.
 *
 * @throws Exception if some problem inside
 */
@Test
public void fetchesRawRepresentation() throws Exception {
    final Contents contents = new MkGithub().randomRepo().contents();
    final String raw = "raw test \u20ac\u0000";
    final InputStream stream = contents.create(jsonContent("raw.txt", "for raw", raw)).raw();
    try {
        MatcherAssert.assertThat(IOUtils.toString(stream, CharEncoding.UTF_8), Matchers.is(raw));
    } finally {
        stream.close();
    }
}
Also used : Contents(com.jcabi.github.Contents) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 3 with Contents

use of com.jcabi.github.Contents in project jcabi-github by jcabi.

the class MkContentsTest method updateContent.

/**
 * MkContents can update an content.
 * @throws Exception if any problem inside
 */
@Test
public void updateContent() throws Exception {
    final String path = "content-to-update.txt";
    final String message = "commit message";
    final String initial = "Hello World!";
    final String updated = "update content";
    final String branch = "master";
    final Contents contents = new MkGithub().randomRepo().contents();
    final JsonObject content = MkContentsTest.content(path, message, initial).add("ref", branch).build();
    MatcherAssert.assertThat(new Content.Smart(contents.create(content)).content(), Matchers.is(initial));
    contents.update(path, MkContentsTest.content(path, message, updated).add("ref", branch).build());
    MatcherAssert.assertThat(new Content.Smart(contents.get(path, branch)).content(), Matchers.is(updated));
}
Also used : Contents(com.jcabi.github.Contents) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 4 with Contents

use of com.jcabi.github.Contents in project jcabi-github by jcabi.

the class MkContentsTest method getContentFromDefaultBranch.

/**
 * MkContents can get content from default branch.
 * @throws Exception if any problem inside
 */
@Test
public void getContentFromDefaultBranch() throws Exception {
    final String path = "content-default-branch.txt";
    final String message = "content default branch created";
    final String text = "I'm content of default branch";
    final Contents contents = new MkGithub().randomRepo().contents();
    final JsonObject content = MkContentsTest.content(path, message, text).build();
    MatcherAssert.assertThat(new Content.Smart(contents.create(content)).content(), Matchers.is(text));
    MatcherAssert.assertThat(new Content.Smart(contents.get(path)).content(), Matchers.is(text));
}
Also used : Contents(com.jcabi.github.Contents) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 5 with Contents

use of com.jcabi.github.Contents in project jcabi-github by jcabi.

the class MkContentsTest method canFetchReadmeFile.

/**
 * MkContents can fetch the default branch readme file.
 * @throws Exception if some problem inside
 */
@Test
public void canFetchReadmeFile() throws Exception {
    final Contents contents = new MkGithub().randomRepo().contents();
    final String body = "Readme On Master";
    // @checkstyle MultipleStringLiterals (6 lines)
    contents.create(content("README.md", "readme on master", body).build());
    MatcherAssert.assertThat(contents.readme().json().getString("content"), Matchers.is(body));
}
Also used : Contents(com.jcabi.github.Contents) Test(org.junit.Test)

Aggregations

Contents (com.jcabi.github.Contents)12 Test (org.junit.Test)11 JsonObject (javax.json.JsonObject)4 Content (com.jcabi.github.Content)3 Repo (com.jcabi.github.Repo)1 InputStream (java.io.InputStream)1