Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit 83fb96d

Browse files
author
pacafuentes
committed
Refactor xml validation test.
1 parent 5910aec commit 83fb96d

File tree

3 files changed

+19
-121
lines changed

3 files changed

+19
-121
lines changed

raml-parser-2/src/test/java/org/raml/v2/unit/ApiModelUnitTestCase.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import java.net.URL;
2626
import java.util.List;
2727

28+
import static org.hamcrest.CoreMatchers.containsString;
2829
import static org.hamcrest.CoreMatchers.is;
30+
import static org.junit.Assert.assertEquals;
2931
import static org.junit.Assert.assertThat;
3032

3133
public class ApiModelUnitTestCase
@@ -106,4 +108,21 @@ public void shouldGenerateXsdSchemaOnRecursiveTypes()
106108
"</schema>"));
107109

108110
}
111+
112+
@Test
113+
public void testXMLValidation()
114+
{
115+
URL savedRamlLocation = getClass().getClassLoader().getResource("org/raml/v2/unit/xml-validation.raml");
116+
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(savedRamlLocation.toString());
117+
TypeDeclaration typeDeclaration = ramlModelResult.getApiV10().resources().get(0).methods().get(0).body().get(0);
118+
List<ValidationResult> validationResults = typeDeclaration.validate("<root>\n" +
119+
" <name>robert</name>\n" +
120+
" <my-custom-xml>with-custom-value</my-custom-xml>\n" +
121+
" </root>");
122+
assertEquals(1, validationResults.size());
123+
String message = validationResults.get(0).getMessage();
124+
assertThat(message, containsString("Error validating XML. Error: cvc-complex-type.2.4.a: Invalid content was found starting with element"));
125+
assertThat(message, containsString("my-custom-xml"));
126+
assertThat(message, containsString("One of '{\"http://validationnamespace.raml.org\":friends}' is expected."));
127+
}
109128
}

raml-parser-2/src/test/resources/org/raml/v2/parser/xml-to-raml-type-validations/array-error/output.txt

Lines changed: 0 additions & 116 deletions
This file was deleted.
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,3 @@ types:
1515
body:
1616
application/xml:
1717
type: root
18-
example: |
19-
<root>
20-
<name>robert</name>
21-
<my-custom-xml>with-custom-value</my-custom-xml>
22-
</root>

0 commit comments

Comments
 (0)