20 package net.sf.gridarta.model.archetypetype;
22 import java.io.ByteArrayOutputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.net.URISyntaxException;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.List;
31 import java.util.regex.Pattern;
36 import nu.xom.ParsingException;
37 import nu.xom.xinclude.XIncludeException;
38 import org.jetbrains.annotations.NotNull;
39 import org.junit.Assert;
40 import org.junit.Test;
41 import org.xml.sax.SAXException;
53 private static final Pattern
CR = Pattern.compile(
"\r");
76 public void test1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
89 public void testImport1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
102 public void testImport2() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
116 check(
"ignoreDefaultAttribute1");
129 check(
"ignoreImportAttribute1");
142 check(
"ignoreDefinedAttribute1");
154 public void testMsgDefault1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
155 check(
"msgDefault1");
167 public void testMsgDefault2() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
168 check(
"msgDefault2");
180 public void testMsgDefault3() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
181 check(
"msgDefault3");
194 public void testArchetypeOrder1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
196 Assert.assertFalse(errorView.
hasErrors());
197 final List<String> keys =
new ArrayList<>(Arrays.asList(
"a",
"b",
"c",
"d"));
199 Assert.assertEquals(
"[a, b, c, d]", keys.toString());
211 public void testArchetypeOrder2() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
213 Assert.assertFalse(errorView.
hasErrors());
214 final List<String> keys =
new ArrayList<>(Arrays.asList(
"a",
"b",
"c",
"d"));
216 Assert.assertEquals(
"[a, b, c, d]", keys.toString());
229 public void testArchetypeOrder3() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
231 Assert.assertFalse(errorView.
hasErrors());
232 final List<String> keys =
new ArrayList<>(Arrays.asList(
"a",
"b",
"c",
"d"));
234 Assert.assertEquals(
"[c, d, a, b]", keys.toString());
247 public void testArchetypeOrder4() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
249 Assert.assertFalse(errorView.
hasErrors());
250 final List<String> keys =
new ArrayList<>(Arrays.asList(
"a",
"b",
"c",
"d"));
252 Assert.assertEquals(
"[c, a, b, d]", keys.toString());
264 private void check(@NotNull
final String name)
throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
266 final InputStream is = getClass().getResourceAsStream(
"ArchetypeTypeSetParserTest-" + name +
"-result.txt");
267 Assert.assertNotNull(is);
268 final ByteArrayOutputStream baos =
new ByteArrayOutputStream();
269 final byte[] tmp =
new byte[1024];
271 final int len = is.read(tmp);
275 baos.write(tmp, 0, len);
277 final String expectedResult = CR.matcher(baos.toString(
"UTF-8")).replaceAll(
"");
278 Assert.assertEquals(expectedResult,
"errors=" + errorView.
hasErrors() +
"\n" + archetypeTypeSet);
295 final URL typesXml = getClass().getResource(
"ArchetypeTypeSetParserTest-" + name +
"-types.xml");
296 Assert.assertNotNull(typesXml);
void testImport2()
Checks that multi-imports do work.
static final Pattern CR
A Pattern that matches characters.
An ArchetypeAttributeFactory suitable for unit tests.
void testImport1()
Checks that imports do work.
Comparator< String > getAttributeOrderComparator()
Returns a Comparator that sorts attributes keys by the order defined by addAttributeOrder(String).
Utility class for parsing ArchetypeAttributes.
Convenience class for adding messages to a ErrorView instance using a fixed category name...
void testIgnoreDefaultAttribute1()
Checks that ignoring default attributes do work.
Interface for classes implementing ArchetypeAttribute factories.
Manages ArchetypeType instances, list, and bitmask definitions.
Utility class for parsing XML files.
static ArchetypeTypeSetParser createArchetypeTypeSetParser()
Creates a new ArchetypeTypeSetParser instance.
Utility class for parsing ArchetypeType instances.
ArchetypeTypeSet loadTypesFromXML(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final Document document)
Loads a types.xml file.
Interface for classes displaying error messages.
Base package of all Gridarta classes.
ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final String name)
Loads a types.xml file from resources.
final ErrorView errorView
The ErrorView used for parsing.
Regression tests for ArchetypeTypeSetParser.
static Document readXmlUrl(@NotNull final URL url, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler)
Reads an XML file from an URL.
void testMsgDefault2()
Checks that a "msg" field in default_type does work.
boolean hasErrors()
Whether at least one error message has been added.
void check(@NotNull final String name)
Checks that a types.xml file can be read.
void testIgnoreImportAttribute1()
Checks that ignoring import attributes do work.
void testArchetypeOrder4()
Checks that a "archetype_order" is parsed correctly: some attributes missing.
void testMsgDefault1()
Checks that a "msg" field in default_type does work.
Parser for ArchetypeTypeSets ("types.xml" files).
void testArchetypeOrder1()
Checks that a "archetype_order" is parsed correctly: missing attribute_order element.
void testArchetypeOrder3()
Checks that a "archetype_order" is parsed correctly: all attributes specified.
void testMsgDefault3()
Checks that a "msg" field in default_type CAN BE "ignored".
final ErrorViewCollector errorViewCollector
The ErrorViewCollector used for parsing.
void testIgnoreDefinedAttribute1()
Checks that ignoring defined attributes do work.
void testArchetypeOrder2()
Checks that a "archetype_order" is parsed correctly: empty element.
An ErrorView suitable for unit tests.
void test1()
Read a simple types.xml file.