Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mindula committed Apr 4, 2024
1 parent 50de57e commit 8a3614e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private static List<Node> getRecordFieldsForXMLElement(Element xmlElement, boole
if (xmlNode.getNodeType() == org.w3c.dom.Node.ATTRIBUTE_NODE) {
if ((xmlNode.getPrefix() == null &&
XMLNS_PREFIX.equals(xmlNode.getLocalName())) || (XMLNS_PREFIX.equals(xmlNode.getPrefix()) &&
xmlNode.getLocalName().equals(xmlElement.getPrefix()))) {
xmlNode.getLocalName().equals(xmlElement.getPrefix())) && withNameSpace) {
String prefix = null;
if (xmlElement.getPrefix() != null && xmlElement.getPrefix().equals(xmlNode.getLocalName())) {
prefix = xmlNode.getLocalName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public class XMLToRecordConverterTests {
private final Path sample23Bal = RES_DIR.resolve(BAL_DIR)
.resolve("sample_23.bal");

private final Path sample24XML = RES_DIR.resolve(XML_DIR)
.resolve("sample_24.xml");
private final Path sample24Bal = RES_DIR.resolve(BAL_DIR)
.resolve("sample_24.bal");

private static final String XMLToRecordServiceEP = "xmlToRecord/convert";


Expand Down Expand Up @@ -378,6 +383,15 @@ public void testXMLWithConflictingElementAndAttributeNames() throws IOException
Assert.assertEquals(generatedCodeBlock, expectedCodeBlock);
}

@Test(description = "testXMLWithoutNamespaces")
public void testXMLWithoutNamespaces() throws IOException {
String xmlFileContent = Files.readString(sample24XML);
String generatedCodeBlock = XMLToRecordConverter.convertXMLToRecord(xmlFileContent, false, false, false,
null, false).getCodeBlock().replaceAll("\\s+", "");
String expectedCodeBlock = Files.readString(sample24Bal).replaceAll("\\s+", "");
Assert.assertEquals(generatedCodeBlock, expectedCodeBlock);
}

@Test(description = "testXMLToRecordService")
public void testXMLToRecordService() throws IOException, ExecutionException, InterruptedException {
Endpoint serviceEndpoint = TestUtil.initializeLanguageSever();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type Book_BookItem record {
string[] authorName;
};

type Book_BookList record {
Book_BookItem bookItem;
};

@xmldata:Name {value: "library"}
type Example_Library record {
Book_BookList bookList;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<example:library xmlns:example="http://example.com/library" xmlns:book="http://example.com/book" xmlns:author="http://example.com/author">
<book:bookList>
<book:bookItem>
<author:authorName>Value 1</author:authorName>
<author:authorName>Value 2</author:authorName>
</book:bookItem>
</book:bookList>
</example:library>

0 comments on commit 8a3614e

Please sign in to comment.