import org.apache.commons.logging.LogFactory;
import org.argeo.slc.core.SlcException;
import org.argeo.slc.core.structure.tree.TreeSRelatedHelper;
+import org.argeo.slc.core.test.SimpleResultPart;
import org.argeo.slc.core.test.TestDefinition;
+import org.argeo.slc.core.test.TestResult;
import org.argeo.slc.core.test.TestRun;
+import org.argeo.slc.core.test.TestStatus;
import org.argeo.slc.core.test.context.ContextUtils;
-import org.argeo.slc.detached.DetachedClient;
-import org.argeo.slc.detached.DetachedStep;
import org.argeo.slc.detached.DetachedAnswer;
+import org.argeo.slc.detached.DetachedClient;
import org.argeo.slc.detached.DetachedRequest;
+import org.argeo.slc.detached.DetachedStep;
+import org.argeo.slc.detached.ui.UiStep;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.BeanFactory;
private DetachedClient client;
// Spring properties
- private String thisBeanName = null;
+ private String testDefBeanName = null;
private BeanDefinitionRegistry beanDefinitionRegistry = null;
- private String stepBeanName = null;
+ private String stepRef = null;
public void execute(TestRun testRun) {
- DetachedTestData testData = testRun.getTestData();
- Map<String, Object> values = testData.getValues();
- Properties inputParameters = new Properties();
- inputParameters.putAll(values);// TODO: check conversions to string
+ // Look for step bean name
+ String stepBeanNameT = null;
+ if (this.stepRef == null && step != null) {
+ if (step instanceof UiStep) {
+ stepBeanNameT = ((UiStep) step).getBeanName();
+ } else {
+ // Introspects bean factory in order to find step bean name
+ BeanDefinition thisBeanDef = beanDefinitionRegistry
+ .getBeanDefinition(testDefBeanName);
+ PropertyValue propValue = thisBeanDef.getPropertyValues()
+ .getPropertyValue("step");
+ Object stepBeanRef = propValue.getValue();
+ BeanReference ref = (BeanReference) stepBeanRef;
+ stepBeanNameT = ref.getBeanName();
+ }
+ } else if (this.stepRef != null) {
+ stepBeanNameT = this.stepRef;
+ }
+ // Execute
DetachedRequest request = new DetachedRequest();
request.setPath(getBasePath().toString());
request.setUuid(UUID.randomUUID().toString());
- request.setRef(stepBeanName);
- request.setProperties(inputParameters);
+ request.setRef(stepBeanNameT);
+
+ DetachedTestData testData = testRun.getTestData();
+ if (testData != null) {
+ Map<String, Object> values = testData.getValues();
+ Properties inputParameters = new Properties();
+ inputParameters.putAll(values);// TODO: check conversions to string
+ request.setProperties(inputParameters);
+ }
try {
client.sendRequest(request);
} catch (Exception e) {
throw new SlcException("Could not send request for step "
- + stepBeanName, e);
+ + stepBeanNameT, e);
}
try {
throw new SlcException("Error when executing step "
+ answer.getUuid() + ": " + answer.getLog());
else
- log.info("Step answer: " + answer.getLog());
- Properties outputParameters = answer.getProperties();
- for (Object key : outputParameters.keySet())
- testData.getValues().put(key.toString(),
- outputParameters.get(key));
+ log.info("Received answer for '" + request.getRef() + "' ("
+ + answer.getStatusAsString() + "):" + answer.getLog());
+
+ if (testData != null) {
+ Properties outputParameters = answer.getProperties();
+ for (Object key : outputParameters.keySet())
+ testData.getValues().put(key.toString(),
+ outputParameters.get(key));
+ }
} catch (Exception e) {
throw new SlcException("Could not receive answer #"
- + request.getUuid() + " for step " + stepBeanName, e);
+ + request.getUuid() + " for step " + stepBeanNameT, e);
}
- ContextUtils.compareReachedExpected(testData, testRun.getTestResult(),
- this);
+ if (testData != null) {
+ ContextUtils.compareReachedExpected(testData, testRun
+ .getTestResult(), this);
+ } else {
+ ((TestResult)testRun.getTestResult()).addResultPart(
+ new SimpleResultPart(TestStatus.PASSED, "Step "
+ + stepBeanNameT + " executed successfully"));
+ }
}
public void setBeanName(String name) {
- this.thisBeanName = name;
+ this.testDefBeanName = name;
}
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
}
public void afterPropertiesSet() throws Exception {
- if (stepBeanName == null) {
- // Introspects bean factory in order to find step bean name
- BeanDefinition thisBeanDef = beanDefinitionRegistry
- .getBeanDefinition(thisBeanName);
- PropertyValue propValue = thisBeanDef.getPropertyValues()
- .getPropertyValue("step");
- Object stepBeanRef = propValue.getValue();
- BeanReference ref = (BeanReference) stepBeanRef;
- stepBeanName = ref.getBeanName();
- }
}
public void setStep(DetachedStep step) {
this.client = client;
}
- public void setStepBeanName(String stepBeanName) {
- this.stepBeanName = stepBeanName;
+ public void setStepRef(String stepBeanName) {
+ this.stepRef = stepBeanName;
}
}