diff --git a/docs/csv_to_csv.md b/docs/csv_to_csv.md
index 24f08a1..db3deaf 100644
--- a/docs/csv_to_csv.md
+++ b/docs/csv_to_csv.md
@@ -42,6 +42,7 @@ Specify columns to skip from the CSV payload. You can specify the columns as com
* If `headerPresent` is `Present` and `skipHeader` is set as `false`, output CSV would have the header of the input
CSV.
* customValueSeparator (Separator): Values separator to use in the output CSV. Default is `,` (comma)
+* suppressEscaping (Suppress Escaping): Specify whether to suppress all escaping in the output Csv payload. Default is false. (ie. Escape characters will be present)
### Sample configuration
diff --git a/docs/json_to_csv.md b/docs/json_to_csv.md
index a48e307..5889fd4 100644
--- a/docs/json_to_csv.md
+++ b/docs/json_to_csv.md
@@ -12,6 +12,7 @@ You can use the jsonToCsv operation to transform a JSON payload in to an CSV pay
* customHeader (CSV Header):
Set a custom header to the output CSV payload. If this property is not specified, Key values of the input would be
used as the output CSV headers.
+* suppressEscaping (Suppress Escaping): Specify whether to suppress all escaping in the output Csv payload. Default is false. (ie. Escape characters will be present)
### Sample configuration
diff --git a/docs/xml_to_csv.md b/docs/xml_to_csv.md
index 521b7ae..6890823 100644
--- a/docs/xml_to_csv.md
+++ b/docs/xml_to_csv.md
@@ -11,7 +11,7 @@ You can use the xmlToCsv operation to transform an XML payload in to an CSV payl
**Properties**
* customHeader (CSV Header):
Set a custom header to the output CSV payload. If this property is not specified, Key values of the input would be used as the output CSV headers.
-
+* suppressEscaping (Suppress Escaping): Specify whether to suppress all escaping in the output Csv payload. Default is false. (ie. Escape characters will be present)
### Sample configuration
diff --git a/pom.xml b/pom.xml
index c204899..c656ef4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
4.0.0
org.wso2.carbon.module
mediation-csv-module
- 1.0.5-SNAPSHOT
+ 1.0.5
jar
WSO2 Carbon - Connector For csvConnector
http://wso2.org
@@ -43,7 +43,7 @@
1.55
1.6.1-wso2v18
1.6.1.wso2v18
- 1.0.1
+ 1.0.2
5.6.2
2.21.0
2.23.0
diff --git a/src/main/java/org/wso2/carbon/module/csv/CsvToCsvTransformer.java b/src/main/java/org/wso2/carbon/module/csv/CsvToCsvTransformer.java
index aa6704b..33bb2c6 100644
--- a/src/main/java/org/wso2/carbon/module/csv/CsvToCsvTransformer.java
+++ b/src/main/java/org/wso2/carbon/module/csv/CsvToCsvTransformer.java
@@ -58,6 +58,7 @@ public void mediate(SimpleMessageContext mc) {
getEnumParam(mc, ParameterKey.SORT_COLUMNS_BY_ORDERING, OrderingType.class, OrderingType.ASCENDING);
final Optional customHeader = getStringParam(mc, ParameterKey.CUSTOM_HEADER);
final Optional customValueSeparator = getCharParam(mc, ParameterKey.CUSTOM_VALUE_SEPARATOR);
+ final boolean suppressEscapeCharacters = getBooleanParam(mc, ParameterKey.SUPPRESS_ESCAPE_CHARACTERS);
CsvPayloadInfo payloadInfo = new CsvPayloadInfo();
if (headerAvailability == HeaderAvailability.PRESENT || customHeader.isPresent()) {
@@ -89,10 +90,8 @@ public void mediate(SimpleMessageContext mc) {
resultHeader = skipColumnsSingleRow(payloadInfo.getNumberOfColumns(), columnsToSkipQuery.get(),
payloadInfo.getFirstRow(), resultHeader);
}
-
csvArrayStream
- .collect(mc.collectToCsv(resultHeader, customValueSeparator.orElse(Constants.DEFAULT_CSV_SEPARATOR)));
-
+ .collect(mc.collectToCsv(resultHeader, customValueSeparator.orElse(Constants.DEFAULT_CSV_SEPARATOR), suppressEscapeCharacters));
}
/**
diff --git a/src/main/java/org/wso2/carbon/module/csv/JsonToCsvTransformer.java b/src/main/java/org/wso2/carbon/module/csv/JsonToCsvTransformer.java
index ea49ccd..16b7d67 100644
--- a/src/main/java/org/wso2/carbon/module/csv/JsonToCsvTransformer.java
+++ b/src/main/java/org/wso2/carbon/module/csv/JsonToCsvTransformer.java
@@ -33,6 +33,7 @@
import java.util.Set;
import static org.wso2.carbon.module.csv.constant.Constants.DEFAULT_EXPRESSION_SPLITTER;
+import static org.wso2.carbon.module.csv.util.PropertyReader.getBooleanParam;
/**
* Transformer to transform JSON content to a CSV content.
@@ -41,6 +42,7 @@ public class JsonToCsvTransformer extends SimpleMediator {
@Override
public void mediate(SimpleMessageContext mc) {
+ final boolean suppressEscapeCharacters = getBooleanParam(mc, ParameterKey.SUPPRESS_ESCAPE_CHARACTERS);
String[] header = getHeader(mc);
mc.getJsonArrayStream()
@@ -58,7 +60,7 @@ public void mediate(SimpleMessageContext mc) {
return csvEntry.toArray(new String[]{});
})
- .collect(mc.collectToCsv(header));
+ .collect(mc.collectToCsv(header, suppressEscapeCharacters));
}
/**
diff --git a/src/main/java/org/wso2/carbon/module/csv/XmlToCsvTransformer.java b/src/main/java/org/wso2/carbon/module/csv/XmlToCsvTransformer.java
index 9c9a92d..bbb768d 100644
--- a/src/main/java/org/wso2/carbon/module/csv/XmlToCsvTransformer.java
+++ b/src/main/java/org/wso2/carbon/module/csv/XmlToCsvTransformer.java
@@ -29,6 +29,7 @@
import java.util.List;
import static org.wso2.carbon.module.csv.constant.Constants.DEFAULT_EXPRESSION_SPLITTER;
+import static org.wso2.carbon.module.csv.util.PropertyReader.getBooleanParam;
/**
* Transformer to transform an XML content to a CSV content.
@@ -37,7 +38,7 @@ public class XmlToCsvTransformer extends SimpleMediator {
@Override
public void mediate(SimpleMessageContext mc) {
-
+ final boolean suppressEscapeCharacter = getBooleanParam(mc, ParameterKey.SUPPRESS_ESCAPE_CHARACTERS);
String[] header = getHeader(mc);
mc.getXmlChildElementsStream()
.map(omElement -> {
@@ -49,7 +50,7 @@ public void mediate(SimpleMessageContext mc) {
csvEntry.add(childText);
}
return csvEntry.toArray(new String[0]);
- }).collect(mc.collectToCsv(header));
+ }).collect(mc.collectToCsv(header, suppressEscapeCharacter));
}
/**
diff --git a/src/main/java/org/wso2/carbon/module/csv/constant/ParameterKey.java b/src/main/java/org/wso2/carbon/module/csv/constant/ParameterKey.java
index 82eaf0f..1e77568 100644
--- a/src/main/java/org/wso2/carbon/module/csv/constant/ParameterKey.java
+++ b/src/main/java/org/wso2/carbon/module/csv/constant/ParameterKey.java
@@ -45,6 +45,8 @@ public class ParameterKey {
public static final String GROUP_ELEMENT_NAMESPACE = "groupElementNamespace";
public static final String GROUP_ELEMENT_NAMESPACE_URI = "groupElementNamespaceURI";
+ public static final String SUPPRESS_ESCAPE_CHARACTERS = "suppressEscaping";
+
private ParameterKey() {
}
diff --git a/src/main/resources/csvToCsv/csv_to_csv_template.xml b/src/main/resources/csvToCsv/csv_to_csv_template.xml
index 83a3833..07b4ff1 100644
--- a/src/main/resources/csvToCsv/csv_to_csv_template.xml
+++ b/src/main/resources/csvToCsv/csv_to_csv_template.xml
@@ -27,6 +27,7 @@
+
@@ -38,6 +39,7 @@
+
diff --git a/src/main/resources/jsonToCsv/json_to_csv_template.xml b/src/main/resources/jsonToCsv/json_to_csv_template.xml
index 9395a7c..81ba858 100644
--- a/src/main/resources/jsonToCsv/json_to_csv_template.xml
+++ b/src/main/resources/jsonToCsv/json_to_csv_template.xml
@@ -17,8 +17,10 @@
-->
+
+
diff --git a/src/main/resources/uischema/csvToCsv.json b/src/main/resources/uischema/csvToCsv.json
index 03b68b3..26142f9 100644
--- a/src/main/resources/uischema/csvToCsv.json
+++ b/src/main/resources/uischema/csvToCsv.json
@@ -150,6 +150,17 @@
"required": "false",
"helpTip": "Specify a value separator for CSV output. Default is comma ( , )"
}
+ },
+ {
+ "type": "attribute",
+ "value": {
+ "name": "suppressEscaping",
+ "displayName": "Suppress Escaping",
+ "inputType": "booleanOrExpression",
+ "defaultValue": "false",
+ "required": "false",
+ "helpTip": "Specify whether to suppress all escaping in the output Csv payload. Default is false. (ie. Escape characters will be present)"
+ }
}
]
}
diff --git a/src/main/resources/uischema/jsonToCsv.json b/src/main/resources/uischema/jsonToCsv.json
index 5c0914c..ac72c71 100644
--- a/src/main/resources/uischema/jsonToCsv.json
+++ b/src/main/resources/uischema/jsonToCsv.json
@@ -35,6 +35,17 @@
"required": "false",
"helpTip": "Comma separated strings to set as the CSV header"
}
+ },
+ {
+ "type": "attribute",
+ "value": {
+ "name": "suppressEscaping",
+ "displayName": "Suppress Escaping",
+ "inputType": "booleanOrExpression",
+ "defaultValue": "false",
+ "required": "false",
+ "helpTip": "Specify whether to suppress all escaping in the output Csv payload. Default is false. (ie. Escape characters will be present)"
+ }
}
]
}
diff --git a/src/main/resources/uischema/xmlToCsv.json b/src/main/resources/uischema/xmlToCsv.json
index 4824050..713f7b9 100644
--- a/src/main/resources/uischema/xmlToCsv.json
+++ b/src/main/resources/uischema/xmlToCsv.json
@@ -35,6 +35,17 @@
"required": "false",
"helpTip": "Comma separated strings to set as the CSV header"
}
+ },
+ {
+ "type": "attribute",
+ "value": {
+ "name": "suppressEscaping",
+ "displayName": "Suppress Escaping",
+ "inputType": "booleanOrExpression",
+ "defaultValue": "false",
+ "required": "false",
+ "helpTip": "Specify whether to suppress all escaping in the output Csv payload. Default is false. (ie. Escape characters will be present)"
+ }
}
]
}
diff --git a/src/main/resources/xmlToCsv/xml_to_csv_template.xml b/src/main/resources/xmlToCsv/xml_to_csv_template.xml
index c6c2278..978bc8b 100644
--- a/src/main/resources/xmlToCsv/xml_to_csv_template.xml
+++ b/src/main/resources/xmlToCsv/xml_to_csv_template.xml
@@ -17,8 +17,10 @@
-->
+
+
diff --git a/src/test/java/org/wso2/carbon/module/csv/CsvToCsvTransformerTest.java b/src/test/java/org/wso2/carbon/module/csv/CsvToCsvTransformerTest.java
index 91a96de..4485f95 100644
--- a/src/test/java/org/wso2/carbon/module/csv/CsvToCsvTransformerTest.java
+++ b/src/test/java/org/wso2/carbon/module/csv/CsvToCsvTransformerTest.java
@@ -53,7 +53,7 @@ void testMediate_noConfigurations_sameCsvShouldSet() {
final CsvCollector csvCollector = new CsvCollector(mc, null, Constants.DEFAULT_CSV_SEPARATOR);
when(mc.getCsvArrayStream(0, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.stream());
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -82,7 +82,7 @@ void testMediate_headerPresent_sameCsvShouldSet() {
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -113,7 +113,7 @@ void testMediate_headerPresentGivenCustomHeader_correctCsvShouldSet() {
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(new String[]{"p", "q", "r"}, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(new String[]{"p", "q", "r"}, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -143,7 +143,7 @@ void testMediate_headerPresentSkipHeader_correctCsvShouldSet() {
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -174,7 +174,7 @@ void testMediate_headerPresentSkipHeaderCustomHeaderGiven_correctCsvShouldSet()
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(new String[]{"p", "q", "r"}, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(new String[]{"p", "q", "r"}, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -202,7 +202,7 @@ void testMediate_headerAbsentCustomHeaderGiven_correctCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.IS_HEADER_PRESENT)).thenReturn("Absent");
lenient().when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_HEADER)).thenReturn("p,q,r");
when(mc.getCsvArrayStream(0, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.stream());
- when(mc.collectToCsv(new String[]{"p", "q", "r"}, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(new String[]{"p", "q", "r"}, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -228,7 +228,7 @@ void testMediate_headerAbsentCustomHeaderNotGiven_correctCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.IS_HEADER_PRESENT)).thenReturn("Absent");
when(mc.getCsvArrayStream(0, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.stream());
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -253,7 +253,7 @@ void testMediate_OrderByColumn_correctCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.ORDER_BY_COLUMN)).thenReturn("2");
when(mc.getCsvArrayStream(0, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.stream());
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -279,7 +279,7 @@ void testMediate_OrderByColumnOrderAscending_correctCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.ORDER_BY_COLUMN)).thenReturn("2");
lenient().when(mc.lookupTemplateParameter(ParameterKey.SORT_COLUMNS_BY_ORDERING)).thenReturn("Ascending");
when(mc.getCsvArrayStream(0, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.stream());
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -305,7 +305,7 @@ void testMediate_OrderByColumnOrderDescending_correctCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.ORDER_BY_COLUMN)).thenReturn("2");
lenient().when(mc.lookupTemplateParameter(ParameterKey.SORT_COLUMNS_BY_ORDERING)).thenReturn("Descending");
when(mc.getCsvArrayStream(0, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.stream());
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -334,7 +334,7 @@ void testMediate_OrderByColumnWithHeader_correctCsvShouldSet() {
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -365,7 +365,7 @@ void testMediate_OrderByColumnWithHeaderWithSkipHeader_correctCsvShouldSet() {
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -394,7 +394,7 @@ void testMediate_OrderByColumnNameWithHeader_correctCsvShouldSet() {
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -424,7 +424,7 @@ void testMediate_OrderByInvalidColumnNameWithHeader_sameCsvShouldSet() {
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -455,7 +455,7 @@ void testMediate_OrderByColumnNameIntegerNameWithHeader_correctCsvShouldSet() {
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -480,7 +480,7 @@ void testMediate_skipDataRows_correctCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.DATA_ROWS_TO_SKIP)).thenReturn("1");
when(mc.getCsvArrayStream(1, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(1, 2).stream());
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -508,7 +508,7 @@ void testMediate_skipDataRowsHeaderPresent_correctCsvShouldSet() {
when(mc.getCsvArrayStream(2, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(2, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -538,7 +538,7 @@ void testMediate_skipDataRowsHeaderPresentSkipHeader_correctCsvShouldSet() {
when(mc.getCsvArrayStream(2, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(2, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -569,7 +569,7 @@ void testMediate_skipDataRowsHeaderPresentSkipHeaderCustomHeader_correctCsvShoul
when(mc.getCsvArrayStream(2, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.subList(2, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(new String[]{"p", "q", "r"}, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(new String[]{"p", "q", "r"}, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -595,7 +595,7 @@ void testMediate_SeparatorDefined_sameCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.VALUE_SEPARATOR)).thenReturn("#");
when(mc.getCsvArrayStream(0, '#')).thenReturn(csvPayload.stream());
- when(mc.collectToCsv(null, ',')).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, ',', false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -624,7 +624,7 @@ void testMediate_SeparatorDefinedWithHeader_sameCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.IS_HEADER_PRESENT)).thenReturn("Present");
when(mc.getCsvArrayStream(1, '#')).thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo('#')).thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(csvPayload.get(0), ',')).thenReturn(csvCollector);
+ when(mc.collectToCsv(csvPayload.get(0), ',', false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -650,7 +650,7 @@ void testMediate_skipColumns_correctCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.COLUMNS_TO_SKIP)).thenReturn("2");
when(mc.getCsvArrayStream(0, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.stream());
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -680,7 +680,7 @@ void testMediate_skipColumnsWithHeader_correctCsvShouldSet() {
.thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(new String[]{"a", "c"}, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(new String[]{"a", "c"}, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -712,7 +712,7 @@ void testMediate_skipColumnsWithHeaderWithSkipHeader_correctCsvShouldSet() {
.thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -742,7 +742,7 @@ void testMediate_skipColumnsWithHeaderWithHeaderNames_correctCsvShouldSet() {
.thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(new String[]{"a", "c"}, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(new String[]{"a", "c"}, Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -774,7 +774,7 @@ void testMediate_skipColumnsWithHeaderComplexQuery_correctCsvShouldSet() {
.thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 8, csvPayload));
- when(mc.collectToCsv(new String[]{"b", "e", "f", "h"}, Constants.DEFAULT_CSV_SEPARATOR))
+ when(mc.collectToCsv(new String[]{"b", "e", "f", "h"}, Constants.DEFAULT_CSV_SEPARATOR, false))
.thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
@@ -806,7 +806,7 @@ void testMediate_skipColumnsWithHeaderInvalidHeaderName_sameCsvShouldSet() {
.thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -837,7 +837,7 @@ void testMediate_skipColumnsWithHeaderComplexQueryInvalidColumnName_sameCsvShoul
.thenReturn(csvPayload.subList(1, 3).stream());
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 8, csvPayload));
- when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvCollector);
+ when(mc.collectToCsv(csvPayload.get(0), Constants.DEFAULT_CSV_SEPARATOR, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -864,7 +864,7 @@ void testMediate_customSeparator_correctCsvShouldSet() {
lenient().when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_VALUE_SEPARATOR)).thenReturn("#");
when(mc.getCsvArrayStream(0, Constants.DEFAULT_CSV_SEPARATOR)).thenReturn(csvPayload.stream());
- when(mc.collectToCsv(null, '#')).thenReturn(csvCollector);
+ when(mc.collectToCsv(null, '#', false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
@@ -896,7 +896,7 @@ void testMediate_customSeparatorWithHeader_correctCsvShouldSet() {
when(mc.getCsvPayloadInfo(Constants.DEFAULT_CSV_SEPARATOR))
.thenReturn(new CsvPayloadInfo(csvPayload.get(0), 3, csvPayload));
- when(mc.collectToCsv(csvPayload.get(0), '#')).thenReturn(csvCollector);
+ when(mc.collectToCsv(csvPayload.get(0), '#', false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
CsvToCsvTransformer csvToCsvTransformer = new CsvToCsvTransformer();
diff --git a/src/test/java/org/wso2/carbon/module/csv/JsonToCsvTransformerTest.java b/src/test/java/org/wso2/carbon/module/csv/JsonToCsvTransformerTest.java
index bb2d6b0..7580fda 100644
--- a/src/test/java/org/wso2/carbon/module/csv/JsonToCsvTransformerTest.java
+++ b/src/test/java/org/wso2/carbon/module/csv/JsonToCsvTransformerTest.java
@@ -33,9 +33,10 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+
@ExtendWith(MockitoExtension.class)
class JsonToCsvTransformerTest {
@@ -70,10 +71,11 @@ public void testMediate_validJsonInput_correctCsvOutputShouldSet() {
StreamSupport.stream(payloadJsonElement.getAsJsonArray().spliterator(), false);
final CsvCollector csvCollector = new CsvCollector(mc, null);
- when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_HEADER)).thenReturn("");
+ lenient().when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_HEADER)).thenReturn("");
+ lenient().when(mc.lookupTemplateParameter(ParameterKey.SUPPRESS_ESCAPE_CHARACTERS)).thenReturn("false");
when(mc.getJsonElement()).thenReturn(payloadJsonElement);
when(mc.getJsonArrayStream()).thenReturn(payloadJsonStream);
- when(mc.collectToCsv(any())).thenReturn(csvCollector);
+ when(mc.collectToCsv(new String[]{"id", "firstName", "lastName"}, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
@@ -121,9 +123,10 @@ public void testMediate_validJsonInputWithHeaderSet_correctCsvShouldReturnWithHe
StreamSupport.stream(payloadJsonElement.getAsJsonArray().spliterator(), false);
final CsvCollector csvCollector = new CsvCollector(mc, headerArray);
- when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_HEADER)).thenReturn(header);
+ lenient().when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_HEADER)).thenReturn(header);
+ lenient().when(mc.lookupTemplateParameter(ParameterKey.SUPPRESS_ESCAPE_CHARACTERS)).thenReturn("false");
when(mc.getJsonArrayStream()).thenReturn(payloadJsonStream);
- when(mc.collectToCsv(headerArray)).thenReturn(csvCollector);
+ when(mc.collectToCsv(headerArray, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
diff --git a/src/test/java/org/wso2/carbon/module/csv/XmlToCsvTransformerTest.java b/src/test/java/org/wso2/carbon/module/csv/XmlToCsvTransformerTest.java
index 01b6e7c..536ffb2 100644
--- a/src/test/java/org/wso2/carbon/module/csv/XmlToCsvTransformerTest.java
+++ b/src/test/java/org/wso2/carbon/module/csv/XmlToCsvTransformerTest.java
@@ -35,9 +35,9 @@
import javax.xml.stream.XMLStreamException;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
class XmlToCsvTransformerTest {
@@ -71,10 +71,11 @@ public void testMediate_validXmlInput_correctCsvOutputShouldSet() throws XMLStre
Stream childElementStream = StreamSupport.stream(iterable.spliterator(), false);
final CsvCollector csvCollector = new CsvCollector(mc, null);
- when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_HEADER)).thenReturn("");
+ lenient().when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_HEADER)).thenReturn("");
+ lenient().when(mc.lookupTemplateParameter(ParameterKey.SUPPRESS_ESCAPE_CHARACTERS)).thenReturn("false");
when(mc.getRootXmlElement()).thenReturn(xmlPayload.cloneOMElement());
when(mc.getXmlChildElementsStream()).thenReturn(childElementStream);
- when(mc.collectToCsv(any())).thenReturn(csvCollector);
+ when(mc.collectToCsv(new String[]{"id", "firstName", "lastName"}, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);
@@ -122,9 +123,10 @@ public void testMediate_validXmlInputWithHeaderProperty_correctCsvOutputWithHead
Stream childElementStream = StreamSupport.stream(iterable.spliterator(), false);
final CsvCollector csvCollector = new CsvCollector(mc, headerArray);
- when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_HEADER)).thenReturn(header);
+ lenient().when(mc.lookupTemplateParameter(ParameterKey.CUSTOM_HEADER)).thenReturn(header);
+ lenient().when(mc.lookupTemplateParameter(ParameterKey.SUPPRESS_ESCAPE_CHARACTERS)).thenReturn("false");
when(mc.getXmlChildElementsStream()).thenReturn(childElementStream);
- when(mc.collectToCsv(any())).thenReturn(csvCollector);
+ when(mc.collectToCsv(headerArray, false)).thenReturn(csvCollector);
ArgumentCaptor payloadSetArgumentCaptor = ArgumentCaptor.forClass(String.class);