<commit_before>/**
 * Copyright (c) 2013-2014, JCabi.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met: 1) Redistributions of source code must retain the above
 * copyright notice, this list of conditions and the following
 * disclaimer. 2) Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution. 3) Neither the name of the jcabi.com nor
 * the names of its contributors may be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.jcabi.github;

import com.jcabi.aspects.Tv;
import javax.json.Json;
import javax.json.JsonObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.RandomStringUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;

/**
 * Test case for {@link RtContents}.
 * @author <NAME> (<EMAIL>)
 * @version $Id$
 * @since 0.8
 * @todo #119 RtContents should be able to get the readme file
 *  from a real Github repository, fetch files, create, update and remove
 *  files.
 *  When done, remove this puzzle and Ignore annotation from the method.
 */
public final class RtContentsITCase {

    /**
     * RtContents can fetch readme file.
     * @throws Exception If some problem inside
     */
    @Test
    @Ignore
    public void canFetchReadmeFiles() throws Exception {
        // to be implemented
    }

    /**
     * RtContents can create file content.
     * @throws Exception If some problem inside
     */
    @Test
    public void canCreateFileContent() throws Exception {
        final String path = RandomStringUtils.randomAlphabetic(Tv.TEN);
        MatcherAssert.assertThat(
            RtContentsITCase.repo().contents().create(
                jsonObject(
                    path, new String(
                        Base64.encodeBase64("some content".getBytes())
                    ), "theMessage"
                )
            ).path(),
            Matchers.equalTo(path)
        );
    }

    /**
     * RtContents can get content.
     * @throws Exception If some problem inside
     */
    @Test
    public void getContent() throws Exception {
        final String path = String.valueOf(System.currentTimeMillis());
        final String message = String.format("testMessage");
        final String cont = new String(
            Base64.encodeBase64(
                String.format("content%d", System.currentTimeMillis())
                    .getBytes()
            )
        );
        RtContentsITCase.repo().contents().create(
            jsonObject(path, cont, message)
        );
        final Content content = RtContentsITCase.repo().contents()
            .get(path, "master");
        MatcherAssert.assertThat(
            content.path(),
            Matchers.equalTo(path)
        );
        MatcherAssert.assertThat(
            new Content.Smart(content).content(),
            Matchers.equalTo(String.format("%s\n", cont))
        );
    }

    /**
     * Create and return JsonObject of content.
     * @param path Content's path
     * @param cont Content's Base64 string
     * @param message Message
     * @return JsonObject
     */
    private JsonObject jsonObject(
        final String path, final String cont, final String message
    ) {
        return Json.createObjectBuilder()
            .add("path", path)
            .add("message", message)
            .add("content", cont)
            .build();
    }

    /**
     * Create and return repo to test.
     * @return Repo
     * @throws Exception If some problem inside
     */
    private static Repo repo() throws Exception {
        final String key = System.getProperty("failsafe.github.key");
        Assume.assumeThat(key, Matchers.notNullValue());
        return new RtGithub(key).repos().get(RtContentsITCase.coordinates());
    }

    /**
     * Create and return repo coordinates to test on.
     * @return Coordinates
     */
    private static Coordinates coordinates() {
        return new Coordinates.Simple(
            System.getProperty("failsafe.github.repo")
        );
    }
}
<commit_msg>Issue #665 RtContentsITCase works under new random repo<commit_after>/**
 * Copyright (c) 2013-2014, JCabi.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met: 1) Redistributions of source code must retain the above
 * copyright notice, this list of conditions and the following
 * disclaimer. 2) Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution. 3) Neither the name of the jcabi.com nor
 * the names of its contributors may be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.jcabi.github;

import com.jcabi.aspects.Tv;
import javax.json.Json;
import javax.json.JsonObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.RandomStringUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;

/**
 * Test case for {@link RtContents}.
 * @author <NAME> (<EMAIL>)
 * @version $Id$
 * @since 0.8
 * @todo #119 RtContents should be able to get the readme file
 *  from a real Github repository, fetch files, create, update and remove
 *  files.
 *  When done, remove this puzzle and Ignore annotation from the method.
 * @checkstyle MultipleStringLiterals (300 lines)
 */
public final class RtContentsITCase {

    /**
     * RtContents can fetch readme file.
     * @throws Exception If some problem inside
     */
    @Test
    @Ignore
    public void canFetchReadmeFiles() throws Exception {
        // to be implemented
    }

    /**
     * RtContents can create file content.
     * @throws Exception If some problem inside
     */
    @Test
    public void canCreateFileContent() throws Exception {
        final Repos repos = github().repos();
        final Repo repo = repos.create(
            Json.createObjectBuilder().add(
                "name", RandomStringUtils.randomAlphanumeric(Tv.TEN)
            ).build()
        );
        try {
            final String path = RandomStringUtils.randomAlphabetic(Tv.TEN);
            MatcherAssert.assertThat(
                repos.get(repo.coordinates()).contents().create(
                    this.jsonObject(
                        path, new String(
                            Base64.encodeBase64("some content".getBytes())
                        ), "theMessage"
                    )
                ).path(),
                Matchers.equalTo(path)
            );
        } finally {
            repos.remove(repo.coordinates());
        }
    }

    /**
     * RtContents can get content.
     * @throws Exception If some problem inside
     */
    @Test
    public void getContent() throws Exception {
        final Repos repos = github().repos();
        final Repo repo = repos.create(
            Json.createObjectBuilder().add(
                "name", RandomStringUtils.randomAlphanumeric(Tv.TEN)
            ).build()
        );
        try {
            final String path = RandomStringUtils.randomAlphanumeric(Tv.TEN);
            final String message = String.format("testMessage");
            final String cont = new String(
                Base64.encodeBase64(
                    String.format("content%d", System.currentTimeMillis())
                        .getBytes()
                )
            );
            final Contents contents = repos.get(repo.coordinates()).contents();
            contents.create(this.jsonObject(path, cont, message));
            final Content content = contents.get(path, "master");
            MatcherAssert.assertThat(
                content.path(),
                Matchers.equalTo(path)
            );
            MatcherAssert.assertThat(
                new Content.Smart(content).content(),
                Matchers.equalTo(String.format("%s\n", cont))
            );
        } finally {
            repos.remove(repo.coordinates());
        }
    }

    /**
     * Create and return JsonObject of content.
     * @param path Content's path
     * @param cont Content's Base64 string
     * @param message Message
     * @return JsonObject
     */
    private JsonObject jsonObject(
        final String path, final String cont, final String message
    ) {
        return Json.createObjectBuilder()
            .add("path", path)
            .add("message", message)
            .add("content", cont)
            .build();
    }

    /**
     * Create and return repo to test.
     *
     * @return Repo
     * @throws Exception If some problem inside
     */
    private static Github github() throws Exception {
        final String key = System.getProperty("failsafe.github.key");
        Assume.assumeThat(key, Matchers.notNullValue());
        return new RtGithub(key);
    }
}

{'fraction_non_alphanumeric': 0.08795706749135893, 'fraction_numerical': 0.005821357103874841, 'mean_word_length': 2.4477892756349955, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2647185', 'n_tokens_mistral': 2971, 'n_tokens_neox': 2761, 'n_words': 999}