Skip to content

Commit

Permalink
Add API wrapper support (#42)
Browse files Browse the repository at this point in the history
* handle wrapper and test definition via interface
* optimized foreach to stream
* add xlsx with API wrappers
* handle wrapper sheet as optional feature
* excel expected response Restel Variables
* custom string equals comparator
* add test for apiwrapper and custom string comparator
* Changes to add the request resposne to the test api.
Removed unused code
* add demo and integration test sheets with wrapper
* fix wrapper sheet column name is dependant on DTO

Co-authored-by: Kannan R <[email protected]>
  • Loading branch information
bharathyes and kannangce authored May 12, 2022
1 parent 770bde7 commit 17f9531
Show file tree
Hide file tree
Showing 23 changed files with 590 additions and 214 deletions.
Binary file modified quickstart/jsonbox_test.xlsx
Binary file not shown.
6 changes: 3 additions & 3 deletions src/main/java/com/techconative/restel/core/RestelRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.techconative.restel.core.managers.RestelTestManager;
import com.techconative.restel.core.model.RestelSuite;
import com.techconative.restel.core.model.RestelTestMethod;
import com.techconative.restel.core.model.RestelTestApiDefinition;
import com.techconative.restel.core.model.RestelTestScenario;
import com.techconative.restel.testng.TestCase;
import java.util.*;
Expand Down Expand Up @@ -93,11 +93,11 @@ private static XmlSuite getSuite(String suiteName) {
}

/**
* Translate the {@link RestelTestMethod} into {@link XmlTest} instances.
* Translate the {@link RestelTestApiDefinition} into {@link XmlTest} instances.
*
* @param parentSuite The suite instance to which the created {@link XmlTest} instances will fall
* under.
* @param restelExec The {@link RestelTestMethod}s that will be translated.
* @param restelExec The {@link RestelTestApiDefinition}s that will be translated.
* @return List of {@link XmlTest} that has been translated.
*/
private static Set<XmlTest> getTestList(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package com.techconative.restel.core.managers;

import com.techconative.restel.core.model.BaseConfiguration;
import com.techconative.restel.core.model.RestelSuite;
import com.techconative.restel.core.model.RestelTestMethod;
import com.techconative.restel.core.model.RestelTestScenario;
import com.techconative.restel.core.model.*;
import com.techconative.restel.core.parser.Parser;
import com.techconative.restel.core.parser.ParserEnums;
import com.techconative.restel.core.parser.config.ParserConfig;
import com.techconative.restel.core.parser.dto.BaseConfig;
import com.techconative.restel.core.parser.dto.TestApiDefinitions;
import com.techconative.restel.core.parser.dto.TestScenarios;
import com.techconative.restel.core.parser.dto.TestSuites;
import com.techconative.restel.core.parser.dto.*;
import com.techconative.restel.exception.RestelException;
import com.techconative.restel.utils.RestelUtils;
import java.io.File;
Expand All @@ -27,7 +21,9 @@ public class ExcelParseManager {

private String filepath;

private List<RestelTestMethod> testMethods;
private List<RestelTestApiDefinition> testMethods;
private Map<String, RestelTestApiDefinition> testMethodMap;
private List<RestelTestApiWrapper> testApiWrappers;
private List<RestelSuite> suites;
private List<RestelTestScenario> execGroups;
private BaseConfiguration baseConfig;
Expand Down Expand Up @@ -55,6 +51,9 @@ private void init() {
List<TestApiDefinitions> testDefs =
(List<TestApiDefinitions>)
excelData.get(ParserEnums.TEST_API_DEFINITIONS.toString().toLowerCase());
List<TestApiWrappers> testWrappers =
(List<TestApiWrappers>)
excelData.get(ParserEnums.TEST_API_WRAPPERS.toString().toLowerCase());
List<TestSuites> testSuites =
(List<TestSuites>) excelData.get(ParserEnums.TEST_SUITES.toString().toLowerCase());
List<TestScenarios> testSuiteExecutions =
Expand All @@ -64,14 +63,21 @@ private void init() {
(BaseConfig) excelData.get(ParserEnums.BASE_CONFIG.toString().toLowerCase()));

testMethods = createTestMethod(testDefs, baseConfig);
if ((testWrappers != null) && !testWrappers.isEmpty()) {
testApiWrappers = createTestApiWrapper(testWrappers);
}
suites = createSuites(testSuites);
execGroups = createExecGroups(testSuiteExecutions);
}

public List<RestelTestMethod> getTestMethods() {
public List<RestelTestApiDefinition> getTestMethods() {
return testMethods;
}

public List<RestelTestApiWrapper> getTestApiWrappers() {
return testApiWrappers;
}

public List<RestelSuite> getSuites() {
return suites;
}
Expand All @@ -92,28 +98,29 @@ private BaseConfiguration createBaseConfigure(BaseConfig config) {
* creates List of RestelTestMethod from TestDefinitions
*
* @param testApiDefinitions List of {@link TestApiDefinitions}
* @return list of {@link RestelTestMethod}
* @return list of {@link RestelTestApiDefinition}
*/
private List<RestelTestMethod> createTestMethod(
private List<RestelTestApiDefinition> createTestMethod(
List<TestApiDefinitions> testApiDefinitions, BaseConfiguration baseConfig) {
if (testApiDefinitions.isEmpty()) {
throw new RestelException("TEST_DEF_EMPTY");
}

// Create a Map od case name and its Method definition.
Map<String, RestelTestMethod> testMethodMap = new HashMap<>();
testApiDefinitions.forEach(
testDefinition ->
testMethodMap.put(
testDefinition.getApiUniqueName(),
RestelUtils.createTestMethod(testDefinition, baseConfig)));
testMethodMap =
testApiDefinitions.stream()
.collect(
Collectors.toMap(
TestApiDefinitions::getApiUniqueName,
x -> RestelUtils.createTestMethod(x, baseConfig)));

return testApiDefinitions.stream()
.map(
testDefinition -> {
RestelTestMethod testMethod = testMethodMap.get(testDefinition.getApiUniqueName());
RestelTestApiDefinition testMethod =
testMethodMap.get(testDefinition.getApiUniqueName());
if (!StringUtils.isEmpty(testDefinition.getDependsOn())) {
List<RestelTestMethod> dependents =
List<RestelApiDefinition> dependents =
Arrays.asList(testDefinition.getDependsOn().split(",")).stream()
.map(
name -> {
Expand All @@ -133,6 +140,12 @@ private List<RestelTestMethod> createTestMethod(
.collect(Collectors.toList());
}

private List<RestelTestApiWrapper> createTestApiWrapper(List<TestApiWrappers> testWrappers) {
return testWrappers.stream()
.map(x -> RestelUtils.createTestWrapper(x, testMethodMap))
.collect(Collectors.toList());
}

/**
* creates List of RestelSuites from TestSuites
*
Expand Down
Loading

0 comments on commit 17f9531

Please sign in to comment.