use of com.eviware.soapui.support.types.StringToStringsMap in project microcks by microcks.
the class SoapUIScriptEngineBinder method bindSoapUIEnvironment.
/**
* Create and bind a SoapUI environment for a ScriptEngine.
* @param engine The engine to enrich with binding environment.
* @param requestContent The content of request to use as data
* @param request The wrapped incoming servlet request.
*/
public static void bindSoapUIEnvironment(ScriptEngine engine, String requestContent, HttpServletRequest request) {
// Build a map of header values.
StringToStringsMap headers = new StringToStringsMap();
for (String headerName : Collections.list(request.getHeaderNames())) {
headers.put(headerName, Collections.list(request.getHeaders(headerName)));
}
// Build a fake request container.
FakeSoapUIMockRequest mockRequest = new FakeSoapUIMockRequest(requestContent, headers);
mockRequest.setRequest(request);
// Create bindings and put content according to SoapUI binding environment.
Bindings bindings = engine.createBindings();
bindings.put("mockRequest", mockRequest);
bindings.put("log", log);
engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
}
use of com.eviware.soapui.support.types.StringToStringsMap in project microcks by microcks.
the class SoapUITestStepsRunner method runOperationTestSteps.
/**
* Run all the Operation test steps defined into the SoapUI project and having the name
* contained into testStepNames (if not null nor empty).
* @param operation The operation to run tests for
* @param testResult TestResults that aggregate results within.
* @param endpointUrl The URL of the endpoint to use for request test steps.
* @param testStepNames A list of test step names to execute
* @return A list of TestReturn wrapper objects (one by executed test step)
*/
public List<TestReturn> runOperationTestSteps(Operation operation, TestResult testResult, String endpointUrl, List<String> testStepNames) {
// Remember to force no proxy otherwise SoapUI will use system settings and will
// make them generally applied to everything going out through Apache Http Client
// (and maybe also JDK HttpURLConnection ?).
ProxyUtils.setProxyEnabled(false);
String operationName = operation.getName();
List<TestReturn> results = new ArrayList<TestReturn>();
for (TestSuite testSuite : project.getTestSuiteList()) {
for (TestCase testCase : testSuite.getTestCaseList()) {
// Depending on testCase type build an accurate runner.
TestCaseRunner testCaseRunner = buildTestCaseRunner(testCase);
if (testCaseRunner != null) {
for (TestStep testStep : testCase.getTestStepList()) {
if (testStep instanceof HttpRequestTestStep && testStep instanceof OperationTestStep && (testStepNames == null || testStepNames.contains(testStep.getName()))) {
log.debug("Looking up for testStep for operation '{}'", operationName);
if (operationName.equals(((OperationTestStep) testStep).getOperation().getName())) {
log.debug("Picking up step '{}' for running SoapUI test", testStep.getName());
// Set the endpointUrl using this common interface for Soap and Rest requests.
((HttpRequestTestStep) testStep).getHttpRequest().setEndpoint(endpointUrl);
// Add or override existing headers with test specific ones for operation and globals.
if (testResult.getOperationsHeaders() != null) {
Set<Header> headers = new HashSet<>();
if (testResult.getOperationsHeaders().getGlobals() != null) {
headers.addAll(testResult.getOperationsHeaders().getGlobals());
}
if (testResult.getOperationsHeaders().get(operationName) != null) {
headers.addAll(testResult.getOperationsHeaders().get(operationName));
}
if (headers.size() > 0) {
StringToStringsMap headersMap = new StringToStringsMap();
for (Header header : headers) {
headersMap.put(header.getName(), new ArrayList<>(header.getValues()));
}
((HttpRequestTestStep) testStep).getHttpRequest().setRequestHeaders(headersMap);
}
}
// Running tests also checks linked assertions.
TestStepResult result = testStep.run(testCaseRunner, testCaseRunner.getRunContext());
log.debug("SoapUI test result is " + result.getStatus());
results.add(extractTestReturn(testStep.getName(), result));
}
}
}
}
}
}
return results;
}
Aggregations