Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API wrapper support #42

Merged
merged 20 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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