Skip to content

Commit

Permalink
Remove unreachable setters and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshanWeerasinghe committed Apr 8, 2024
1 parent b76dd62 commit bc0c5f8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,39 @@
*/
public class XMLToRecordRequest {

private String xmlValue;
private boolean isRecordTypeDesc;
private boolean isClosed;
private boolean forceFormatRecordFields;
private String textFieldName;
private boolean withNameSpace;
private final String xmlValue;
private final boolean isRecordTypeDesc;
private final boolean isClosed;
private final boolean forceFormatRecordFields;
private final String textFieldName;
private final boolean withNameSpace;

public XMLToRecordRequest(String xmlValue, boolean isRecordTypeDesc, boolean isClosed,
boolean forceFormatRecordFields) {
boolean forceFormatRecordFields, String textFieldName, boolean withNameSpace) {
this.xmlValue = xmlValue;
this.isRecordTypeDesc = isRecordTypeDesc;
this.isClosed = isClosed;
this.forceFormatRecordFields = forceFormatRecordFields;
this.textFieldName = textFieldName;
this.withNameSpace = withNameSpace;
}

public String getXmlValue() {
return xmlValue;
}

public void setXmlValue(String xmlValue) {
this.xmlValue = xmlValue;
}

public boolean getIsRecordTypeDesc() {
return isRecordTypeDesc;
}

public void setIsRecordTypeDesc(boolean isRecordTypeDesc) {
this.isRecordTypeDesc = isRecordTypeDesc;
}

public boolean getIsClosed() {
return isClosed;
}

public void setIsClosed(boolean isClosed) {
this.isClosed = isClosed;
}

public boolean getForceFormatRecordFields() {
return forceFormatRecordFields;
}

public void setForceFormatRecordFields(boolean forceFormatRecordFields) {
this.forceFormatRecordFields = forceFormatRecordFields;
}

public String getTextFieldName() {
return textFieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ public class XMLToRecordConverterTests {
private final Path sample24Bal = RES_DIR.resolve(BAL_DIR)
.resolve("sample_24.bal");

private final Path sample25XML = RES_DIR.resolve(XML_DIR)
.resolve("sample_25.xml");
private final Path sample25Bal = RES_DIR.resolve(BAL_DIR)
.resolve("sample_25.bal");

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


Expand Down Expand Up @@ -397,11 +402,25 @@ public void testXMLToRecordService() throws IOException, ExecutionException, Int
Endpoint serviceEndpoint = TestUtil.initializeLanguageSever();
String xmlValue = Files.readString(sample0XML);

XMLToRecordRequest request = new XMLToRecordRequest(xmlValue, false, false, false);
XMLToRecordRequest request = new XMLToRecordRequest(xmlValue, false, false, false, null, true);
CompletableFuture<?> result = serviceEndpoint.request(XMLToRecordServiceEP, request);
XMLToRecordResponse response = (XMLToRecordResponse) result.get();
String generatedCodeBlock = response.getCodeBlock().replaceAll("\\s+", "");
String expectedCodeBlock = Files.readString(sample0Bal).replaceAll("\\s+", "");
Assert.assertEquals(generatedCodeBlock, expectedCodeBlock);
}

@Test(description = "Test xml record request with text field name and without namespace")
public void testXMLToRecordServiceWithFieldNameAndWithoutNamespace()
throws IOException, ExecutionException, InterruptedException {
Endpoint serviceEndpoint = TestUtil.initializeLanguageSever();
String xmlValue = Files.readString(sample25XML);

XMLToRecordRequest request = new XMLToRecordRequest(xmlValue, false, false, false, "__text", false);
CompletableFuture<?> result = serviceEndpoint.request(XMLToRecordServiceEP, request);
XMLToRecordResponse response = (XMLToRecordResponse) result.get();
String generatedCodeBlock = response.getCodeBlock().replaceAll("\\s+", "");
String expectedCodeBlock = Files.readString(sample25Bal).replaceAll("\\s+", "");
Assert.assertEquals(generatedCodeBlock, expectedCodeBlock);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
type Book_Title record {
string __text;
@xmldata:Attribute
string edition;
@xmldata:Attribute
string lang;
};

type Book_Author record {
string __text;
@xmldata:Attribute
string gender;
@xmldata:Attribute
string nationality;
};

type Book_Book record {
Book_Title title;
Book_Author author;
string publish_date;
string description;
};

type Books record {
string genre;
Book_Book book;
};

@xmldata:Name {value: "library"}
type Library record {
Books books;
@xmldata:Attribute
string genre;
};
11 changes: 11 additions & 0 deletions misc/xml-to-record-converter/src/test/resources/xml/sample_25.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library xmlns:book="http://example.com/books" genre="genre">
<books>
<genre>Programming</genre>
<book:book>
<book:title lang="en" edition="1st">XML Developer's Guide</book:title>
<book:author gender="male" nationality="American">Gambardella, Matthew</book:author>
<book:publish_date>2000-10-01</book:publish_date>
<book:description>An in-depth look at creating applications with XML.</book:description>
</book:book>
</books>
</library>

0 comments on commit bc0c5f8

Please sign in to comment.