1 package org
.argeo
.slc
.lib
.detached
;
4 import java
.util
.Properties
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.argeo
.slc
.core
.SlcException
;
10 import org
.argeo
.slc
.core
.structure
.tree
.TreeSRelatedHelper
;
11 import org
.argeo
.slc
.core
.test
.TestDefinition
;
12 import org
.argeo
.slc
.core
.test
.TestRun
;
13 import org
.argeo
.slc
.core
.test
.context
.ContextUtils
;
14 import org
.argeo
.slc
.detached
.DetachedClient
;
15 import org
.argeo
.slc
.detached
.DetachedStep
;
16 import org
.argeo
.slc
.detached
.DetachedAnswer
;
17 import org
.argeo
.slc
.detached
.DetachedRequest
;
18 import org
.springframework
.beans
.BeansException
;
19 import org
.springframework
.beans
.PropertyValue
;
20 import org
.springframework
.beans
.factory
.BeanFactory
;
21 import org
.springframework
.beans
.factory
.BeanFactoryAware
;
22 import org
.springframework
.beans
.factory
.BeanInitializationException
;
23 import org
.springframework
.beans
.factory
.BeanNameAware
;
24 import org
.springframework
.beans
.factory
.InitializingBean
;
25 import org
.springframework
.beans
.factory
.config
.BeanDefinition
;
26 import org
.springframework
.beans
.factory
.config
.BeanReference
;
27 import org
.springframework
.beans
.factory
.support
.BeanDefinitionRegistry
;
29 public class DetachedTestDefinition
extends TreeSRelatedHelper
implements
30 TestDefinition
, BeanNameAware
, BeanFactoryAware
, InitializingBean
{
31 private final static Log log
= LogFactory
32 .getLog(DetachedTestDefinition
.class);
34 private DetachedStep step
;
35 private DetachedClient client
;
38 private String thisBeanName
= null;
39 private BeanDefinitionRegistry beanDefinitionRegistry
= null;
40 private String stepBeanName
= null;
42 public void execute(TestRun testRun
) {
43 DetachedTestData testData
= testRun
.getTestData();
44 Map
<String
, Object
> values
= testData
.getValues();
45 Properties inputParameters
= new Properties();
46 inputParameters
.putAll(values
);// TODO: check conversions to string
48 DetachedRequest request
= new DetachedRequest();
49 request
.setPath(getBasePath().toString());
50 request
.setUuid(UUID
.randomUUID().toString());
51 request
.setRef(stepBeanName
);
52 request
.setProperties(inputParameters
);
55 client
.sendRequest(request
);
56 log
.debug("Sent detached request #" + request
.getUuid()
57 + " for step " + stepBeanName
);
58 } catch (Exception e
) {
59 throw new SlcException("Could not send request for step "
64 DetachedAnswer answer
= client
.receiveAnswer();
65 Properties outputParameters
= answer
.getProperties();
66 for (Object key
: outputParameters
.keySet())
67 testData
.getValues().put(key
.toString(),
68 outputParameters
.get(key
));
69 log
.debug("Received detached answer #" + answer
.getUuid()
70 + " for step " + stepBeanName
);
71 } catch (Exception e
) {
72 throw new SlcException("Could not receive answer #"
73 + request
.getUuid() + " for step " + stepBeanName
, e
);
76 ContextUtils
.compareReachedExpected(testData
, testRun
.getTestResult(),
80 public void setBeanName(String name
) {
81 this.thisBeanName
= name
;
84 public void setBeanFactory(BeanFactory beanFactory
) throws BeansException
{
85 if (beanFactory
instanceof BeanDefinitionRegistry
)
86 beanDefinitionRegistry
= (BeanDefinitionRegistry
) beanFactory
;
88 throw new BeanInitializationException(
89 "Require BeanDefinitionRegistry");
92 public void afterPropertiesSet() throws Exception
{
93 if (stepBeanName
== null) {
94 // Introspects bean factory in order to find step bean name
95 BeanDefinition thisBeanDef
= beanDefinitionRegistry
96 .getBeanDefinition(thisBeanName
);
97 PropertyValue propValue
= thisBeanDef
.getPropertyValues()
98 .getPropertyValue("step");
99 Object stepBeanRef
= propValue
.getValue();
100 log
.info("stepBeanRef.class=" + stepBeanRef
.getClass());
101 BeanReference ref
= (BeanReference
) stepBeanRef
;
102 stepBeanName
= ref
.getBeanName();
106 public void setStep(DetachedStep step
) {
110 public void setClient(DetachedClient client
) {
111 this.client
= client
;
114 public void setStepBeanName(String stepBeanName
) {
115 this.stepBeanName
= stepBeanName
;