/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Yegor Bugayenko
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.takes.rs;

import com.google.common.base.Joiner;
import com.jcabi.matchers.XhtmlMatchers;

import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.Charset;

import javax.xml.transform.Source;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource;

import org.apache.commons.io.IOUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

/**
 * Test case for {@link RsXSLT}.
 * @author Yegor Bugayenko (yegor@teamed.io)
 * @version $Id$
 * @since 0.1
 */
@Ignore
public final class RsXSLTTest {

    /**
     * Validate encoding.
     */
    @BeforeClass
    public static void before() {
        MatcherAssert.assertThat(
            "default charset during testing must be UTF-8",
            Charset.defaultCharset().name(),
            Matchers.equalTo("UTF-8")
        );
    }

    /**
     * RsXSLT can convert XML to HTML.
     * @throws IOException If some problem inside
     */
    @Test
    public void convertsXmlToHtml() throws IOException {
        final String xml = Joiner.on(' ').join(
            "<?xml-stylesheet href='/a.xsl' type='text/xsl'?>",
            "<page><data>ура</data></page>"
        );
        final String xsl = Joiner.on(' ').join(
            "<stylesheet xmlns='http://www.w3.org/1999/XSL/Transform'",
            " xmlns:x='http://www.w3.org/1999/xhtml' version='2.0'>",
            "<template match='/'>",
            "<x:html><x:div><value-of select='/page/data'/>",
            "</x:div><x:p>\u0443</x:p></x:html></template></stylesheet>"
        );
        MatcherAssert.assertThat(
            IOUtils.toString(
                new RsXSLT(
                    new RsText(xml),
                    new URIResolver() {
                        @Override
                        public Source resolve(final String href,
                            final String base) {
                            return new StreamSource(new StringReader(xsl));
                        }
                    }
                ).body()
            ),
            XhtmlMatchers.hasXPath("//xhtml:p[.='\u0443']")
        );
    }

    /**
     * RsXSLT can convert XML to plain text.
     * @throws IOException If some problem inside
     */
    @Test
    public void convertsXmlToPlainText() throws IOException {
        final String xml = Joiner.on(' ').join(
            "<?xml-stylesheet href='/x.xsl' type='text/xsl'?>",
            "<p><name>Jeffrey</name></p>"
        );
        final String xsl = Joiner.on(' ').join(
            "<stylesheet xmlns='http://www.w3.org/1999/XSL/Transform' ",
            " xmlns:x='http://www.w3.org/1999/xhtml' version='2.0' >",
            "<output method='text'/><template match='/'>",
            "Hey, <value-of select='/p/name'/>!</template></stylesheet>"
        );
        MatcherAssert.assertThat(
            new RsPrint(
                new RsXSLT(
                    new RsText(xml),
                    new URIResolver() {
                        @Override
                        public Source resolve(final String href,
                            final String base) {
                            return new StreamSource(new StringReader(xsl));
                        }
                    }
                )
            ).print(),
            Matchers.endsWith("Hey, Jeffrey!")
        );
    }

    /**
     * RsXSLT can resolve in classpath.
     * @throws IOException If some problem inside
     */
    @Test
    public void resolvesInClasspath() throws IOException {
        MatcherAssert.assertThat(
            new RsPrint(
                new RsXSLT(
                    new RsText(
                        Joiner.on(' ').join(
                            "<?xml-stylesheet",
                            " href='/org/takes/rs/simple.xsl?0'",
                            " type='text/xsl'?>",
                            "<p><name>Bobby</name></p>"
                        )
                    )
                )
            ).print(),
            Matchers.endsWith("Hello, Bobby!")
        );
        MatcherAssert.assertThat(
            new RsPrint(
                new RsXSLT(
                    new RsText(
                        Joiner.on(' ').join(
                            "<?xml-stylesheet ",
                            " href='/org/takes/rs/simple.xsl'",
                            " type='text/xsl' ?>",
                            "<p><name>Dan</name></p>"
                        )
                    )
                )
            ).print(),
            Matchers.endsWith("Hello, Dan!")
        );
    }

}

@@ -1241,25 +1241,24 @@
 mlMatchers;%0A
-%0A
 import java.
@@ -1335,17 +1335,16 @@
 harset;%0A
-%0A
 import j
@@ -1458,17 +1458,16 @@
 Source;%0A
-%0A
 import o
@@ -1595,33 +1595,8 @@
 ss;%0A
-import org.junit.Ignore;%0A
 impo
@@ -1732,20 +1732,12 @@
 0.1%0A
+
  */%0A
-@Ignore%0A
 publ

Fix unrelated file change commit