/**
 * 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 java.io.IOException;
import java.util.Collections;
import javax.json.Json;
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 RtHooks}.
 * @author Paul Polishchuk (ppol@ua.fm)
 * @version $Id$
 * @since 0.8
 * @todo #551 RtHooksITCase methods are disabled since they don't work
 *  with real Github account. Let's fix them all and remove their
 *  Ignore annotations.
 */
public final class RtHooksITCase {

    /**
     * RtHooks can iterate hooks.
     * @throws Exception If some problem inside
     */
    @Test
    @Ignore
    public void canFetchAllHooks() throws Exception {
        final Repos repos = RtHooksITCase.repos();
        final Repo repo = RtHooksITCase.repo(repos);
        try {
            RtHooksITCase.createHook(repo);
            MatcherAssert.assertThat(
                repo.hooks().iterate(), Matchers.<Hook>iterableWithSize(1)
            );
        } finally {
            repos.remove(repo.coordinates());
        }
    }

    /**
     * RtHooks can create a hook.
     * @throws Exception If some problem inside
     */
    @Test
    @Ignore
    public void canCreateAHook() throws Exception {
        final Repos repos = RtHooksITCase.repos();
        final Repo repo = RtHooksITCase.repo(repos);
        try {
            MatcherAssert.assertThat(
                RtHooksITCase.createHook(repo), Matchers.notNullValue()
            );
        } finally {
            repos.remove(repo.coordinates());
        }
    }

    /**
     * RtHooks can fetch a single hook.
     *
     * @throws Exception If some problem inside.
     */
    @Test
    @Ignore
    public void canFetchSingleHook() throws Exception {
        final Repos repos = RtHooksITCase.repos();
        final Repo repo = RtHooksITCase.repo(repos);
        try {
            final int number = RtHooksITCase.createHook(repo).number();
            MatcherAssert.assertThat(
                repo.hooks().get(number).json().getInt("id"),
                Matchers.equalTo(number)
            );
        } finally {
            repos.remove(repo.coordinates());
        }
    }

    /**
     * RtHooks can remove a hook by ID.
     *
     * @throws Exception If something goes wrong.
     */
    @Test
    @Ignore
    public void canRemoveHook() throws Exception {
        final Repos repos = RtHooksITCase.repos();
        final Repo repo = RtHooksITCase.repo(repos);
        try {
            final Hook hook = RtHooksITCase.createHook(repo);
            repo.hooks().remove(hook.number());
            MatcherAssert.assertThat(
                repo.hooks().iterate(), Matchers.not(Matchers.hasItem(hook))
            );
        } finally {
            repos.remove(repo.coordinates());
        }
    }

    /**
     * Return repos for tests.
     * @return Repos
     */
    private static Repos repos() {
        final String key = System.getProperty("failsafe.github.key");
        Assume.assumeThat(key, Matchers.notNullValue());
        return new RtGithub(key).repos();
    }

    /**
     * Create a new repo with random name.
     * @param repos Repos
     * @return Repository
     * @throws IOException If there is any I/O problem
     */
    private static Repo repo(final Repos repos) throws IOException {
        return repos.create(
            Json.createObjectBuilder().add(
                // @checkstyle MagicNumber (1 line)
                "name", RandomStringUtils.randomNumeric(5)
            ).build()
        );
    }

    /**
     * Create a new hook in a repository.
     * @param repo Repository
     * @return Hook
     * @throws IOException If there is any I/O problem
     */
    private static Hook createHook(final Repo repo) throws IOException {
        return repo.hooks().create(
            "geocommit", Collections.<String, String>emptyMap()
        );
    }

}

@@ -1809,33 +1809,8 @@
 me;%0A
-import org.junit.Ignore;%0A
 impo
@@ -1828,16 +1828,16 @@
 t.Test;%0A
+
 %0A/**%0A * 
@@ -1942,169 +1942,8 @@
 0.8%0A
- * @todo #551 RtHooksITCase methods are disabled since they don't work%0A *  with real Github account. Let's fix them all and remove their%0A *  Ignore annotations.%0A
  */%0A
@@ -2082,36 +2082,24 @@
 /%0A    @Test%0A
-    @Ignore%0A
     public v
@@ -2617,36 +2617,24 @@
 /%0A    @Test%0A
-    @Ignore%0A
     public v
@@ -3117,36 +3117,24 @@
 /%0A    @Test%0A
-    @Ignore%0A
     public v
@@ -3711,32 +3711,32 @@
  wrong.%0A     */%0A
+
     @Test%0A    @I
@@ -3733,20 +3733,8 @@
 est%0A
-    @Ignore%0A
     

remove ignore from RT hooks test, now that test is working. Tests performed with my github repository