Commit a3dbf0ed authored by Nicolas Bailliet's avatar Nicolas Bailliet
Browse files

x validation process at project level added, popover working (template...

x validation process at project level added, popover working (template modified, js and css minified in war pom)

git-svn-id: https://scm.gforge.inria.fr/authscm/ycadoret/svn/gazelle/Maven/simulators/gazelle-webservice-tester/branches/gazelle-webservice-tester-nbt@63954 356b4b1a-1d2b-0410-8bf1-ffa24008f01e
parent 129b4bcf
......@@ -27,7 +27,7 @@ import java.util.List;
@Name("executionResult")
@Scope(ScopeType.PAGE)
public class ExecutionResult {
public class ExecutionResult {
private static final Logger LOG = LoggerFactory.getLogger(ExecutionResult.class);
private Execution execution;
......
......@@ -8,12 +8,7 @@ import net.ihe.gazelle.hql.providers.EntityManagerService;
import net.ihe.gazelle.simulator.common.model.ApplicationConfiguration;
import net.ihe.gazelle.wstester.model.GwtTestStepResult;
import net.ihe.gazelle.wstester.model.ValidationResult;
import net.ihe.gazelle.wstester.model.XValidationResult;
import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage;
import org.slf4j.Logger;
......@@ -25,29 +20,17 @@ import javax.persistence.EntityManager;
import java.io.IOException;
import java.util.Map;
@Name("messageValidation")
@Scope(ScopeType.PAGE)
public class GwtTestStepValidation implements EVSClientValidatedObject {
public class GwtTestStepValidation extends GwtValidation implements EVSClientValidatedObject {
private static final Logger LOG = LoggerFactory.getLogger(GwtTestStepValidation.class);
private String gwtTestStepResultId;
private byte[] selectedMessage;
private byte[] xvalRequest;
private byte[] xvalResponse;
private GwtTestStepResult gwtTestStepResultSelected;
private String gwtTestStepXValOid;
private ValidationResult validationResult;
private XValidationResult xvalidationResult;
//private Map<String,byte[]> requestMap;
//private Map<String,byte[]> responseMap;
public GwtTestStepValidation() {
}
......@@ -58,22 +41,6 @@ public class GwtTestStepValidation implements EVSClientValidatedObject {
this.selectedMessage = selectedMessage;
}
//XValidation
public GwtTestStepValidation(String gwtTestStepResultId, byte[] request, byte[] response, String gwtTestStepXValOid) {
this.gwtTestStepResultId = gwtTestStepResultId;
this.xvalRequest = request;
this.xvalResponse = response;
this.gwtTestStepXValOid = gwtTestStepXValOid;
}
//XValidation
/*public GwtTestStepValidation(String gwtTestStepResultId, Map<String,byte[]> request, Map<String,byte[]> response, String gwtTestStepXValOid) {
this.gwtTestStepResultId = gwtTestStepResultId;
this.requestMap = request;
this.responseMap = response;
this.gwtTestStepXValOid = gwtTestStepXValOid;
}*/
public byte[] getSelectedMessage() {
return selectedMessage;
......@@ -83,22 +50,6 @@ public class GwtTestStepValidation implements EVSClientValidatedObject {
this.selectedMessage = selectedMessage;
}
public byte[] getXvalRequest() {
return xvalRequest;
}
public void setXvalRequest(byte[] xvalRequest) {
this.xvalRequest = xvalRequest;
}
public byte[] getXvalResponse() {
return xvalResponse;
}
public void setXvalResponse(byte[] xvalResponse) {
this.xvalResponse = xvalResponse;
}
public String getGwtTestStepResultId() {
return gwtTestStepResultId;
}
......@@ -115,38 +66,13 @@ public class GwtTestStepValidation implements EVSClientValidatedObject {
this.gwtTestStepResultSelected = gwtTestStepResultSelected;
}
public String getGwtTestStepXValOid() {
return gwtTestStepXValOid;
}
public void setGwtTestStepXValOid(String gwtTestStepXValOid) {
this.gwtTestStepXValOid = gwtTestStepXValOid;
}
public ValidationResult getValidationResult() {
return validationResult;
}
public void setValidationResult(ValidationResult validationResult) {
this.validationResult = validationResult;
}
public XValidationResult getXvalidationResult() {
return xvalidationResult;
}
public void setXvalidationResult(XValidationResult xvalidationResult) {
this.xvalidationResult = xvalidationResult;
}
@Create
public void initializePage() {
public void init() {
Map<String, String> urlParams = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
if (urlParams != null && urlParams.size() > 0) {
String[] parts = null;
//Validation process
if (urlParams.containsKey("id") && !urlParams.containsKey("oidxvallog")) {
if (urlParams.containsKey("id")) {
String externalId = ((String) urlParams.get("id"));
parts = externalId.split("_");
EntityManager entityManager = EntityManagerService.provideEntityManager();
......@@ -169,31 +95,14 @@ public class GwtTestStepValidation implements EVSClientValidatedObject {
getResultDetails(result);
}
}
//X Validation process
else {
String externalId = urlParams.get("id");
EntityManager entityManager = EntityManagerService.provideEntityManager();
if (externalId != null) {
gwtTestStepResultSelected = entityManager.find(GwtTestStepResult.class, Integer.parseInt(externalId));
if (gwtTestStepResultSelected == null) {
FacesMessages.instance().add(StatusMessage.Severity.ERROR, "The given id does not match any test step result in the " +
"database");
}
String xvalidationOid = EVSClientResults.getXValResultOidFromUrl(urlParams);
if (xvalidationOid != null) {
XValidationResult result = new XValidationResult(gwtTestStepResultSelected, xvalidationOid);
gwtTestStepResultSelected.setXvalidationResult(result);
getXValResultDetails(result);
}
}
}
gwtTestStepResultSelected.save();
try {
FacesContext.getCurrentInstance().getExternalContext().redirect("/gazelle-webservice-tester/executionResult.seam?id="
+ gwtTestStepResultSelected.getExecution().getId() + "&validation=" + urlParams.get("id"));
if (gwtTestStepResultSelected != null) {
FacesContext.getCurrentInstance().getExternalContext().redirect("/gazelle-webservice-tester/executionResult.seam?id="
+ gwtTestStepResultSelected.getExecution().getId() + "&validation=" + urlParams.get("id"));
}
} catch (IOException e) {
LOG.error(e.getMessage());
}
......@@ -214,17 +123,6 @@ public class GwtTestStepValidation implements EVSClientValidatedObject {
validationResult = result.save();
}
private void getXValResultDetails(final XValidationResult result) {
String evsclientUrl = ApplicationConfiguration.getValueOfVariable("evs_client_url");
String xvalidationDate = EVSClientResults.getXValidationDate(result.getLogOid(), evsclientUrl);
result.setXvalidationDate(xvalidationDate);
String xvalidationStatus = EVSClientResults.getXValidationStatus(result.getLogOid(), evsclientUrl);
result.setXvalidationStatus(xvalidationStatus);
String linkToResult = EVSClientResults.getXValidationPermanentLink(result.getLogOid(), evsclientUrl);
result.setPermanentLink(linkToResult);
xvalidationResult = result.save();
}
@Override
public String getUniqueKey() {
return gwtTestStepResultId;
......@@ -242,8 +140,8 @@ public class GwtTestStepValidation implements EVSClientValidatedObject {
@Override
public PartSource getXValRequestPartSource() {
if (xvalRequest != null) {
return PartSourceUtils.buildEncoded64PartSource(xvalRequest, getType());
if (selectedMessage != null) {
return PartSourceUtils.buildEncoded64PartSource(selectedMessage, getType());
} else {
return null;
}
......@@ -251,8 +149,8 @@ public class GwtTestStepValidation implements EVSClientValidatedObject {
@Override
public PartSource getXValResponsePartSource() {
if (xvalResponse != null) {
return PartSourceUtils.buildEncoded64PartSource(xvalResponse, getType());
if (selectedMessage != null) {
return PartSourceUtils.buildEncoded64PartSource(selectedMessage, getType());
} else {
return null;
}
......@@ -276,21 +174,4 @@ public class GwtTestStepValidation implements EVSClientValidatedObject {
}
}
public void xvalidate() throws IOException {
String evsClientUrl = ApplicationConfiguration.getValueOfVariable("evs_client_url");
String toolOid = ApplicationConfiguration.getValueOfVariable("tool_instance_oid");
if (evsClientUrl == null) {
LOG.error("evs_client_url is missing in app_configuration table");
} else if (toolOid == null) {
LOG.error("tool_instance_oid is missing in app_configuration table");
} else {
ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
EVSClientServletConnector.sendToXValidation(this, extContext, evsClientUrl, toolOid, gwtTestStepXValOid);
}
}
}
......@@ -6,6 +6,7 @@ import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
import com.eviware.soapui.impl.wsdl.testcase.WsdlProjectRunner;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageExchangeTestStepResult;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlPropertiesTestStep;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlRunTestCaseTestStep;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStepResult;
import com.eviware.soapui.model.TestPropertyHolder;
......@@ -13,6 +14,7 @@ import com.eviware.soapui.model.iface.MessageExchange;
import com.eviware.soapui.model.support.PropertiesMap;
import com.eviware.soapui.model.testsuite.TestCase;
import com.eviware.soapui.model.testsuite.TestCaseRunner;
import com.eviware.soapui.model.testsuite.TestProperty;
import com.eviware.soapui.model.testsuite.TestRunner;
import com.eviware.soapui.model.testsuite.TestStep;
import com.eviware.soapui.model.testsuite.TestStepResult;
......@@ -34,6 +36,8 @@ import net.ihe.gazelle.wstester.model.CustomProperty;
import net.ihe.gazelle.wstester.model.CustomPropertyUsed;
import net.ihe.gazelle.wstester.model.Execution;
import net.ihe.gazelle.wstester.model.GwtProject;
import net.ihe.gazelle.wstester.model.GwtProjectResult;
import net.ihe.gazelle.wstester.model.GwtProjectResultQuery;
import net.ihe.gazelle.wstester.model.GwtTestCase;
import net.ihe.gazelle.wstester.model.GwtTestStepResult;
import net.ihe.gazelle.wstester.model.GwtTestSuite;
......@@ -41,6 +45,8 @@ import net.ihe.gazelle.wstester.model.Keystore;
import net.ihe.gazelle.wstester.model.SoapuiProject;
import net.ihe.gazelle.wstester.model.TestComponent;
import net.ihe.gazelle.wstester.model.TestInstanceResult;
import net.ihe.gazelle.wstester.model.TestStepInfo;
import net.ihe.gazelle.wstester.model.XValidatorInputInfo;
import net.ihe.gazelle.wstester.util.Application;
import net.ihe.gazelle.wstester.util.WsClient;
import org.apache.commons.csv.CSVFormat;
......@@ -60,7 +66,11 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class RunInstanceAction {
private static final Logger LOG = LoggerFactory.getLogger(RunInstanceAction.class);
......@@ -160,6 +170,7 @@ public class RunInstanceAction {
if (!testCaseRunnerList.isEmpty()) {
List<GwtTestStepResult> gwtTestStepResultList = iterateThroughTestCaseRunnerList(testCaseRunnerList);
execution.setTestStepResults(gwtTestStepResultList);
execution.setProjectResults(currentProject.getGwtProject().getGwtProjectResults());
execution = ExecutionDao.mergeExecution(execution);
}
} else {
......@@ -182,6 +193,7 @@ public class RunInstanceAction {
gwtTestStepResultList = iterateThroughTestCaseRunnerList((List<TestCaseRunner>) (List<?>) testRunners);
}
execution.setTestStepResults(gwtTestStepResultList);
execution.setProjectResults(currentProject.getGwtProject().getGwtProjectResults());
execution = ExecutionDao.mergeExecution(execution);
}
moveLogs();
......@@ -190,6 +202,8 @@ public class RunInstanceAction {
public List<TestRunner> startExecution(WsdlProject project) {
List<TestRunner> listResult = new ArrayList<>();
Map<String, TestProperty> testProperties = project.getProperties();
detectOidsInProjectCustomProperties(currentProject.getGwtProject(), testProperties);
if (project != null) {
setCustomPropertiesInSoapUi(project);
if (currentProject.getKeystore() != null) {
......@@ -257,6 +271,16 @@ public class RunInstanceAction {
List<GwtTestStepResult> gwtTestStepResultList = new ArrayList<>();
for (TestCaseRunner results : listResult) {
List<WsdlPropertiesTestStep> propertiesTestSteps = results.getTestCase().getTestStepsOfType(WsdlPropertiesTestStep.class);
for (WsdlPropertiesTestStep propertytestStep : propertiesTestSteps) {
String propertyTestStepName = propertytestStep.getLabel();
if (propertyTestStepName.contains("xval_")) {
String xvalidatorIndex = propertyTestStepName.split("_")[1].split(" ")[0]; //We only keep the index in the property name
affectPropertiesToGwtProjectResult(propertytestStep, results, xvalidatorIndex);
}
}
for (TestStepResult result : results.getResults()) {
TransactionInstance transactionInstance = new TransactionInstance();
if (execution.getTestInstanceResult() != null) {
......@@ -285,7 +309,6 @@ public class RunInstanceAction {
}
}
}
return gwtTestStepResultList;
}
......@@ -315,6 +338,119 @@ public class RunInstanceAction {
}
}
private void detectOidsInProjectCustomProperties(GwtProject project, Map<String, TestProperty> testProperties) {
Set<Map.Entry<String, TestProperty>> setTestProperties = testProperties.entrySet();
Iterator<Map.Entry<String, TestProperty>> testPropertiesIterator = setTestProperties.iterator();
Map<String, String> xvalidatorOidsMap = new HashMap<>();
List<GwtProjectResult> gwtProjectResultList = new ArrayList<>();
List<String> indexList = new ArrayList<>();
if (project.getXvalidatorOidsMap().isEmpty()) {
while (testPropertiesIterator.hasNext()) {
Map.Entry<String, TestProperty> entry = testPropertiesIterator.next();
if (entry.getKey().contains("oid_xval_")) {
if (!currentProject.getGwtProject().getXvalidatorOidsMap().containsValue(entry.getValue().getValue())) {
String[] stringSplitted = entry.getKey().split("_");
String index = stringSplitted[stringSplitted.length - 1];
if (!indexList.contains(index)) {
indexList.add(index);
xvalidatorOidsMap.put(index, entry.getValue().getValue());
GwtProjectResult projectResult = new GwtProjectResult(project, index, entry.getValue().getValue(), execution);
gwtProjectResultList.add(projectResult);
projectResult.save();
}
}
}
}
project.setXvalidatorOidsMap(xvalidatorOidsMap);
} else {
for (GwtProjectResult projectResult : project.getGwtProjectResults()) {
projectResult.setExecution(execution);
projectResult.save();
}
}
}
private void affectPropertiesToGwtProjectResult(WsdlPropertiesTestStep propertiesTestStep, TestCaseRunner runner, String xvalidatorIndex) {
GwtProjectResult correspondingGwtProjectResult = getGwtProjectResultFromXValidatorIndex(xvalidatorIndex);
List<TestStepInfo> testStepInfoList = new ArrayList<>();
List<XValidatorInputInfo> xValidatorInputInfoList = new ArrayList<>();
Map<String, TestProperty> testPropertyMap = propertiesTestStep.getProperties();
Set<Map.Entry<String, TestProperty>> setTestProperties = testPropertyMap.entrySet();
Iterator<Map.Entry<String, TestProperty>> testPropertiesIterator = setTestProperties.iterator();
while (testPropertiesIterator.hasNext()) {
Map.Entry<String, TestProperty> entry = testPropertiesIterator.next();
String inputName = entry.getKey().trim();
String propertyValue = entry.getValue().getValue();
String[] splittedPropertyValue = propertyValue.split("/");
String testStepName = splittedPropertyValue[0];
String inputType = splittedPropertyValue[1];
byte[] messageContent = new byte[0];
for (TestStepResult testStepResult : runner.getResults()) {
TransactionInstance transactionInstance = new TransactionInstance();
if (testStepResult.getTestStep().getLabel().equals(testStepName)) {
if (testStepResult instanceof WsdlMessageExchangeTestStepResult) {
for (MessageExchange messageExchange : ((WsdlMessageExchangeTestStepResult) testStepResult).getMessageExchanges()) {
messageContent = extractMessageFromTransactionInstance(messageExchange, transactionInstance, inputType);
}
} else if (testStepResult instanceof WsdlTestRequestStepResult) {
for (MessageExchange messageExchange : ((WsdlTestRequestStepResult) testStepResult).getMessageExchanges()) {
messageContent = extractMessageFromTransactionInstance(messageExchange, transactionInstance, inputType);
}
}
}
}
TestStepInfo testStepInfo = new TestStepInfo(correspondingGwtProjectResult, testStepName, inputType);
XValidatorInputInfo xValidatorInputInfo = new XValidatorInputInfo(correspondingGwtProjectResult, inputName, messageContent, inputType);
testStepInfoList.add(testStepInfo);
xValidatorInputInfoList.add(xValidatorInputInfo);
}
correspondingGwtProjectResult.setTestStepInfoList(testStepInfoList);
correspondingGwtProjectResult.setxValidatorInputInfoList(xValidatorInputInfoList);
correspondingGwtProjectResult.save();
}
private GwtProjectResult getGwtProjectResultFromXValidatorIndex(String xvalidatorIndex) {
GwtProjectResultQuery query = new GwtProjectResultQuery();
query.project().id().eq(currentProject.getGwtProject().getId());
query.getList();
query.xvalidatorOidIndex().eq(xvalidatorIndex);
GwtProjectResult projectResult = query.getUniqueResult();
return projectResult;
}
private byte[] extractMessageFromTransactionInstance(MessageExchange messageExchange, TransactionInstance transactionInstance, String inputType) {
byte[] messageContent;
if (inputType.equals("REQUEST")) {
MessageInstance request = new MessageInstance();
request.setContent(messageExchange.getRequestContent());
transactionInstance.setRequest(request);
LOG.info("Request : " + messageExchange.getRequestContent());
messageContent = transactionInstance.getRequest().getContent();
return messageContent;
} else if (inputType.equals("RESPONSE")) {
MessageInstance response = new MessageInstance();
response.setContent(messageExchange.getResponseContent());
transactionInstance.setResponse(response);
LOG.info("Response : " + messageExchange.getResponseContent());
messageContent = transactionInstance.getResponse().getContent();
return messageContent;
} else {
LOG.error("Error wrong inputType" + inputType);
return null;
}
}
public GwtTestStepResult createGwtTestStepResult(TestStepResult result, MessageExchange messageExchange, TransactionInstance
transactionInstance, Execution execution) {
MessageInstance request = new MessageInstance();
......@@ -345,17 +481,21 @@ public class RunInstanceAction {
public void createExecutionWithCustomProperties() {
execution = new Execution();
prepareExecution();
execution.setCustomPropertiesUsed(getCustomPropertiesUsed(componentToExecute));
execution = ExecutionDao.mergeExecution(execution);
}
public boolean createExecutionAndTestInstanceResult() {
GazelleTRMServiceStub.TrmTestInstance testInstance = WsClient.getTestInstanceById(testInstanceId);
if (testInstance != null) {
execution = new Execution();
prepareExecution();
GwtTestSuite gwtTestSuite = GwtTestSuiteDao.getGwtTestSuite(testInstance.getTest().getKeyword(), currentProject.getLabel());
if (gwtTestSuite != null) {
execution.setTestInstanceResult(new TestInstanceResult(testInstanceId, gwtTestSuite));
execution.getTestInstanceResult().setExecution(execution);
execution = ExecutionDao.mergeExecution(execution);
return true;
} else {
execution = null;
......@@ -582,10 +722,10 @@ public class RunInstanceAction {
public void addKeystore(Keystore keystore) {
if (keystore != null) {
SoapUI.getSettings().setString(SSLSettings.KEYSTORE, keystore.getPath());
if (keystore.getPassword() != null) {
SoapUI.getSettings().setString(SSLSettings.KEYSTORE_PASSWORD, keystore.getPassword());
}
SoapUI.getSettings().setString(SSLSettings.KEYSTORE, keystore.getPath());
SoapUI.getSettings().setBoolean(HttpSettings.AUTHENTICATE_PREEMPTIVELY, true);
}
}
......
......@@ -38,10 +38,8 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@Name("uploadProject")
......@@ -202,6 +200,7 @@ public class UploadProject implements Serializable {
List<TestCase> testCases = suite.getTestCaseList();
List<GwtTestCase> gwtTestCases = new ArrayList<>();
for (TestCase testCase : testCases) {
GwtTestCase gwtTestCase = new GwtTestCase();
gwtTestCase.setLabel(testCase.getName());
gwtTestCase.setTestSuite(gwtTestSuite);
......@@ -216,7 +215,6 @@ public class UploadProject implements Serializable {
GwtTestStep gwtTestStep = new GwtTestStep();
String testStepName = testStep.getName();
gwtTestStep.setLabel(testStepName);
affectOidXValPropertyToTestStep(gwtTestStep, testStepName, testProperties);
gwtTestStep.setTestCase(gwtTestCase);
gwtTestStep.setDisable(testStep.isDisabled());
gwtTestSteps.add(gwtTestStep);
......@@ -237,20 +235,6 @@ public class UploadProject implements Serializable {
}
}
private void affectOidXValPropertyToTestStep(GwtTestStep gwtTestStep, String testStepName, Map<String, TestProperty> testProperties) {
Set<Map.Entry<String, TestProperty>> setTestProperties = testProperties.entrySet();
Iterator<Map.Entry<String, TestProperty>> testPropertiesIterator = setTestProperties.iterator();
while (testPropertiesIterator.hasNext()) {
Map.Entry<String, TestProperty> entry = testPropertiesIterator.next();
String oidxvalName = entry.getKey();
String oidxval = entry.getValue().getValue();
if (oidxvalName.contains(testStepName)) {
gwtTestStep.setOid_xval(oidxval);
}
}
}
private void moveTmpFile() {
soapuiProject = SoapuiProjectDao.mergeSoapuiProject(soapuiProject);
String target = PreferenceService.getString("project_directory") + soapuiProject.getId() + soapuiProject.getLabel() + ".xml";
......
......@@ -67,12 +67,21 @@ public class Execution implements Serializable {
@OneToMany(
fetch = FetchType.EAGER,
targetEntity = CustomPropertyUsed.class,
targetEntity = GwtProjectResult.class,
mappedBy = "execution",
cascade = CascadeType.ALL,
orphanRemoval = true
)
@Fetch(value = FetchMode.SUBSELECT)
private List<GwtProjectResult> projectResults;
@OneToMany(
fetch = FetchType.EAGER,
targetEntity = CustomPropertyUsed.class,
mappedBy = "execution",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<CustomPropertyUsed> customPropertiesUsed;
@OneToOne(fetch = FetchType.LAZY,
......@@ -87,10 +96,11 @@ public class Execution implements Serializable {
super();
}