From c3d214e4bbb35a37b370fa5574f0d04b41c582f6 Mon Sep 17 00:00:00 2001 From: Ilya Kharlamov <502372+ilyakharlamov@users.noreply.github.com> Date: Thu, 4 Apr 2019 15:06:57 -0400 Subject: [PATCH] (#226) Index.xsd: add a reference to schema --- src/main/java/org/jpeek/Index.java | 16 ++++++++++-- src/main/resources/org/jpeek/xsd/index.xsd | 5 ---- src/test/java/org/jpeek/IndexTest.java | 29 +++++++++++++++++++--- src/test/java/org/jpeek/MatrixTest.java | 1 + 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jpeek/Index.java b/src/main/java/org/jpeek/Index.java index 99ef4f7a..31869798 100644 --- a/src/main/java/org/jpeek/Index.java +++ b/src/main/java/org/jpeek/Index.java @@ -69,10 +69,22 @@ public Iterator iterator() { .attr("artifact", "unknown") .append(new Header()) .append( - new Joined( + () -> new Directives() + .attr( + "xmlns:xsi", + "http://www.w3.org/2001/XMLSchema-instance" + ) + .attr( + "xsi:noNamespaceSchemaLocation", + "xsd/index.xsd" + ) + .iterator() + ) + .append( + new Joined<>( new Mapped<>( Index::metric, - new Filtered( + new Filtered<>( path -> path.getFileName().toString().matches( "^[A-Z].+\\.xml$" ), diff --git a/src/main/resources/org/jpeek/xsd/index.xsd b/src/main/resources/org/jpeek/xsd/index.xsd index d7e5a28c..8b5d16e2 100644 --- a/src/main/resources/org/jpeek/xsd/index.xsd +++ b/src/main/resources/org/jpeek/xsd/index.xsd @@ -22,11 +22,6 @@ 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. --> - diff --git a/src/test/java/org/jpeek/IndexTest.java b/src/test/java/org/jpeek/IndexTest.java index b85d2d85..3e8ee2a4 100644 --- a/src/test/java/org/jpeek/IndexTest.java +++ b/src/test/java/org/jpeek/IndexTest.java @@ -30,6 +30,7 @@ import java.nio.file.Paths; import org.cactoos.text.TextOf; import org.hamcrest.MatcherAssert; +import org.junit.Before; import org.junit.Test; /** @@ -40,18 +41,40 @@ * @checkstyle JavadocMethodCheck (500 lines) */ public final class IndexTest { + /** + * Xml file content as a string. + */ + private String xml; - @Test - public void createsIndexXml() throws IOException { + @Before + public void setUp() throws IOException { final Path output = Files.createTempDirectory("").resolve("x2"); final Path input = Paths.get("."); new App(input, output).analyze(); + this.xml = new TextOf(output.resolve("index.xml")).asString(); + } + + @Test + public void createsIndexXml() { MatcherAssert.assertThat( XhtmlMatchers.xhtml( - new TextOf(output.resolve("index.xml")).asString() + this.xml ), XhtmlMatchers.hasXPaths("/index/metric") ); } + @Test + public void xmlHasSchema() { + MatcherAssert.assertThat( + "The XML Schema is invalid", + XhtmlMatchers.xhtml( + this.xml + ), + XhtmlMatchers.hasXPaths( + "/index[@xsi:noNamespaceSchemaLocation='xsd/index.xsd']" + ) + ); + } + } diff --git a/src/test/java/org/jpeek/MatrixTest.java b/src/test/java/org/jpeek/MatrixTest.java index 95e943c0..e799d8c6 100644 --- a/src/test/java/org/jpeek/MatrixTest.java +++ b/src/test/java/org/jpeek/MatrixTest.java @@ -67,6 +67,7 @@ public void createsMatrixXml() { @Test public void xmlHasSchema() { MatcherAssert.assertThat( + "The XML Schema is invalid", XhtmlMatchers.xhtml( this.xml ),