Skip to content

Commit

Permalink
Merge pull request #30 from virtualansoftware/excel-support
Browse files Browse the repository at this point in the history
Excel support
  • Loading branch information
elans3 committed Mar 24, 2021
2 parents 034ffa9 + 6154200 commit b78be96
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 47 deletions.
4 changes: 2 additions & 2 deletions modules/idaithalam/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<artifactId>idaithalam</artifactId>
<packaging>jar</packaging>
<name>idaithalam-platform-testing</name>
<version>1.1.7-SNAPSHOT</version>
<version>1.1.10-SNAPSHOT</version>
<properties>
<cucumblan.version>1.1.3</cucumblan.version>
<cucumblan.version>1.1.4</cucumblan.version>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ public class Item {
*/
boolean hasInputJsonMap;

/**
* The Has output file by path.
*/
boolean hasOutputFileByPath;

/**
* The Output file by path.
*/
List<String> outputFileByPath;
/**
* The Response by field.
*/
Expand Down Expand Up @@ -305,6 +314,42 @@ public void setHasResponseByField(boolean hasResponseByField) {
}


/**
* Is has output file by path boolean.
*
* @return the boolean
*/
public boolean isHasOutputFileByPath() {
return hasOutputFileByPath;
}

/**
* Sets has output file by path.
*
* @param hasOutputFileByPath the has output file by path
*/
public void setHasOutputFileByPath(boolean hasOutputFileByPath) {
this.hasOutputFileByPath = hasOutputFileByPath;
}

/**
* Gets output file by path.
*
* @return the output file by path
*/
public List<String> getOutputFileByPath() {
return outputFileByPath;
}

/**
* Sets output file by path.
*
* @param outputFileByPath the output file by path
*/
public void setOutputFileByPath(List<String> outputFileByPath) {
this.outputFileByPath = outputFileByPath;
}

/**
* Gets has output inline.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.virtualan.idaithalam.core.generator;

import io.virtualan.idaithalam.config.IdaithalamConfiguration;
import io.virtualan.idaithalam.core.domain.ContentType;
import io.virtualan.idaithalam.core.domain.CreateFileInfo;
import io.virtualan.idaithalam.core.domain.SheetObject;
import java.io.BufferedReader;
Expand All @@ -22,6 +21,7 @@
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
Expand Down Expand Up @@ -85,7 +85,8 @@ private static Map<Integer, String> getHeader(Row nextRow) {
Map<Integer, String> headers = new HashMap<>();
int headerIndex = 0;
for (Cell cell : nextRow) {
headers.put(headerIndex++, cell.getStringCellValue());
headers.put(headerIndex++, getCellValue(cell));

}
return headers;
}
Expand All @@ -94,16 +95,11 @@ private static Map<String, String> getRow(Row nextRow, Map<Integer, String> head
Map<String, String> dataMap = new HashMap<>();
for (Cell cell : nextRow) {
String key = headers.get(cell.getColumnIndex());
if ("HttpStatusCode".equalsIgnoreCase(key)) {
dataMap.put(key, String.valueOf((int) cell.getNumericCellValue()));
} else {
dataMap.put(key, cell.getStringCellValue());
}
dataMap.put(key, getCellValue(cell));
}
return dataMap;
}


/**
* Create collection.
*
Expand Down Expand Up @@ -146,9 +142,9 @@ public static void createCollection(String basePath, List<String> generatedTestC

}

private static void getAsSingleFile(List<String> generatedTestCaseList, String generatedPath,
private static void getAsSingleFile(int sheet, List<String> generatedTestCaseList, String generatedPath,
Map<String, String> cucumblanMap, JSONArray virtualanArray) {
for (int rowIndex =0 ; rowIndex < virtualanArray.length(); rowIndex++){
for (int rowIndex = 0; rowIndex < virtualanArray.length(); rowIndex++) {
JSONObject object = virtualanArray.getJSONObject(rowIndex);
if (byEachTestCase(generatedTestCaseList, object)) {
JSONArray virtualanSingle = new JSONArray();
Expand All @@ -157,7 +153,8 @@ private static void getAsSingleFile(List<String> generatedTestCaseList, String g
createFileInfo.setGeneratedPath(generatedPath);
createFileInfo.setCucumblanMap(cucumblanMap);
createFileInfo.setVirtualanArray(virtualanSingle);
createFileInfo.setTestcaseName( "Virtualan_" + object.optString("TestCaseName") + "_" + rowIndex);
createFileInfo
.setTestcaseName("Virtualan_" +sheet+"_"+ object.optString("scenarioId") + "_" + rowIndex);
createFileInfo.setScenario(object.optString("scenario"));
createIdaithalamProcessingFile(createFileInfo);
}
Expand Down Expand Up @@ -279,7 +276,6 @@ private static InputStream getInputStream(String fileNameWithSubCategory,
return stream;
}


private static Map<String, String> getCucumblan() {
Map<String, String> cucumblanMap = new HashMap<>();
cucumblanMap.put("virtualan.data.load", "");
Expand Down Expand Up @@ -324,6 +320,9 @@ private static JSONObject buildVirtualanCollection(String basePath,
if (dataMap.get("ResponseByField") != null) {
virtualanObj.put("outputFields", dataMap.get("ResponseByField"));
} else {
if (dataMap.get("IncludesbyPath") != null) {
virtualanObj.put("outputPaths", dataMap.get("IncludesbyPath"));
}
virtualanObj.put("output", buildObject(basePath, dataMap.get("ResponseFile")));
}
builHttpStausCode(dataMap, virtualanObj);
Expand Down Expand Up @@ -480,7 +479,6 @@ private static void createQueryParam(String queryString, JSONArray paramsArray)
}
}


private static void populateConfigMaps(
Map<String, String> dataMap, Map<String, String> cucumblanMap,
Map<String, String> excludeResponseMap) throws MalformedURLException {
Expand All @@ -497,14 +495,29 @@ private static void populateConfigMaps(
}
}

private static String getCellValue(Cell cell) {
if (cell.getCellTypeEnum() != CellType.FORMULA) {
switch (cell.getCellTypeEnum()) {
case STRING:
return cell.getStringCellValue().trim();
case BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case NUMERIC:
return String.valueOf((int)cell.getNumericCellValue());
default:
return null;
}
}
return null;
}
private static class BuildCollections {

private final String basePath;
private final List<String> generatedTestCaseList;
private final String generatedPath;
private final InputStream stream;
private Map<String, String> excludeResponseMap;
private Map<String, String> cucumblanMap;
private Map<String, String> excludeResponseMap;
private Map<String, String> cucumblanMap;

BuildCollections(String basePath, List<String> generatedTestCaseList,
String generatedPath,
Expand Down Expand Up @@ -550,11 +563,12 @@ private void createCollections(int sheet, Sheet firstSheet, SheetObject sheetObj
createFileInfo.setGeneratedPath(generatedPath);
createFileInfo.setCucumblanMap(cucumblanMap);
createFileInfo.setVirtualanArray(virtualanArray);
createFileInfo.setTestcaseName(firstSheet.getSheetName() + "_WORKFLOW_" + sheet);
createFileInfo.setTestcaseName("Virtualan_"+sheet+"_"+firstSheet.getSheetName().replaceAll(" ","_")
+ "_WORKFLOW_" + sheet);
createFileInfo.setScenario("WORKFLOW:" + firstSheet.getSheetName());
createIdaithalamProcessingFile(createFileInfo);
} else {
getAsSingleFile(generatedTestCaseList, generatedPath, cucumblanMap, virtualanArray);
getAsSingleFile(sheet, generatedTestCaseList, generatedPath, cucumblanMap, virtualanArray);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -134,26 +135,24 @@ private static void buildVirtualanFromPostMan(JSONArray virtualanArry, JSONArray
}


private static ContentType getContentType(JSONObject jsonObject) {
private static String getContentType(JSONObject jsonObject) {
JSONArray arrayObject = jsonObject.optJSONArray("header");
if (arrayObject != null) {
for (int i = 0; i < arrayObject.length(); i++) {
JSONObject object = arrayObject.optJSONObject(i);
if ("Content-Type".equalsIgnoreCase(object.optString("name")) &&
"text/xml".equalsIgnoreCase(object.optString("value"))
|| (object.optString("value").contains("xml"))) {
return ContentType.XML;
if ("Content-Type".equalsIgnoreCase(object.optString("name"))) {
return object.optString("value");
}
}
}
return ContentType.JSON;
return "application/json";
}

private static JSONObject buildVirtualanObject(JSONArray responseArray, int j) {
JSONObject virtualanObj = new JSONObject();
ContentType contentType = getContentType(
String contentType = getContentType(
responseArray.optJSONObject(j).optJSONObject("originalRequest"));
virtualanObj.put("contentType", contentType.name());
virtualanObj.put("contentType", contentType);
virtualanObj.put("scenario", responseArray.optJSONObject(j).optString("name"));
virtualanObj.put("method",
responseArray.optJSONObject(j).optJSONObject("originalRequest")
Expand Down Expand Up @@ -290,10 +289,17 @@ private static void extractedOutput(JSONObject object, Item item, String path)
item.setResponseByField(outputFieldMap);
}
} else {
item.setHasOutputFileByPath(!object.optString("outputPaths").isEmpty());
item.setOutput(object.optString("output"));
if (item.getOutput() != null && object.optString("output").isEmpty()
&& "XML".equalsIgnoreCase(object.optString("contentType"))) {
if (!ApplicationConfiguration.getInline() && item.getInput().length() > 700) {
if(item.isHasOutputFileByPath()) {
item.setOutputFileByPath(Arrays.asList(object.optString("outputPaths").split(";")));
String fileName =
object.optString("scenario").replaceAll("[^a-zA-Z0-9.-]", "-") + "_response.txt";
createFile(item.getOutput(), path + "/" + fileName);
item.setOutputFile(fileName);
} else if (item.getOutput() != null && !object.optString("output").isEmpty()
&& object.optString("contentType").toLowerCase().contains("xml")) {
if (!ApplicationConfiguration.getInline() && item.getOutput().length() > 700) {
String fileName =
object.optString("scenario").replaceAll("[^a-zA-Z0-9.-]", "-") + "_response.xml";
createFile(item.getOutput(), path + "/" + fileName);
Expand All @@ -302,7 +308,7 @@ private static void extractedOutput(JSONObject object, Item item, String path)
item.setOutputInline(getStringAsList(item.getOutput()));
item.setHasOutputInline(item.getOutput());
}
} else if (item.getOutput() != null && !"".equalsIgnoreCase(item.getOutput())) {
} else if (item.getOutput() != null && !object.optString("output").isEmpty()) {
try {
Object jsonObject = getJSON(item.getOutput());
if (jsonObject instanceof JSONArray || jsonObject instanceof JSONObject) {
Expand Down Expand Up @@ -334,7 +340,7 @@ private static void extractedInput(JSONObject object, Item item, String path) th
item.setContentType(object.optString("contentType"));
item.setInput(object.optString("input"));
if (item.getInput() != null && !"".equalsIgnoreCase(item.getInput())
&& "XML".equalsIgnoreCase(object.optString("contentType"))) {
&& object.optString("contentType").toLowerCase().contains("xml")) {
if (!ApplicationConfiguration.getInline() && item.getInput().length() > 700) {
String fileName =
object.optString("scenario").replaceAll("[^a-zA-Z0-9.-]", "-") + "_request.xml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ Feature: {{feature}} - API Contract validation status
| {{{key}}} | {{{value}}} |
{{/responseByField}}
{{/hasResponseByField}}
{{#hasOutputFileByPath}}
And Verify {{resource}} response {{contentType}} include byPath {{{outputFile}}} includes in the response
{{#outputFileByPath}}
| {{{.}}} |
{{/outputFileByPath}}
{{/hasOutputFileByPath}}
{{^hasOutputFileByPath}}
{{#outputFile}}
And Verify api response XML File {{{outputFile}}} includes in the response
{{/outputFile}}
{{/hasOutputFileByPath}}
{{#hasOutputInline}}
And Verify api response inline includes in the response
{{#outputInline}}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<artifactId>idaithalam-project</artifactId>
<packaging>pom</packaging>
<name>idaithalam-project</name>
<version>1.1.7-SNAPSHOT</version>
<version>1.1.10-SNAPSHOT</version>
<url>https://virtualan.io</url>
<scm>
<connection>scm:git:ssh://git@github.com/virtualansoftware/idaithalam.git</connection>
Expand Down
1 change: 1 addition & 0 deletions samples/idaithalam-excel-apitesting/api-testing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<include name="executeApiTests_2"/>
<include name="executeApiTests_3"/>
<include name="executeApiTests_4"/>
<include name="executeApiTests_7"/>
</methods>
</class>
</classes>
Expand Down
2 changes: 1 addition & 1 deletion samples/idaithalam-excel-apitesting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<name>idaithalam-excel-apitesting</name>
<version>1.0.1-SNAPSHOT</version>
<properties>
<idaithalam.version>1.1.7-SNAPSHOT</idaithalam.version>
<idaithalam.version>1.1.9-SNAPSHOT</idaithalam.version>
<testng.ver>7.4.0</testng.ver>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
Expand Down
Loading

0 comments on commit b78be96

Please sign in to comment.