Skip to content

Commit

Permalink
(cqfn#226) Index.xsd: add a reference to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakharlamov committed Apr 11, 2019
1 parent 801ef70 commit c3d214e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
16 changes: 14 additions & 2 deletions src/main/java/org/jpeek/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,22 @@ public Iterator<Directive> iterator() {
.attr("artifact", "unknown")
.append(new Header())
.append(
new Joined<Directive>(
() -> 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<Path>(
new Filtered<>(
path -> path.getFileName().toString().matches(
"^[A-Z].+\\.xml$"
),
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/org/jpeek/xsd/index.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
-->
<!--
@todo #135:30min Index.xsd: add a reference to this schema from the generated
index.xml. Schemas from src/resources/org/jpeek/xsd must be referenced in
generated XMLs.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="index">
<xs:complexType>
Expand Down
29 changes: 26 additions & 3 deletions src/test/java/org/jpeek/IndexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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']"
)
);
}

}
1 change: 1 addition & 0 deletions src/test/java/org/jpeek/MatrixTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void createsMatrixXml() {
@Test
public void xmlHasSchema() {
MatcherAssert.assertThat(
"The XML Schema is invalid",
XhtmlMatchers.xhtml(
this.xml
),
Expand Down

0 comments on commit c3d214e

Please sign in to comment.