1 package org
.argeo
.slc
.jms
;
3 import javax
.jms
.Destination
;
5 import org
.apache
.commons
.logging
.Log
;
6 import org
.apache
.commons
.logging
.LogFactory
;
7 import org
.argeo
.slc
.SlcException
;
8 import org
.argeo
.slc
.core
.attachment
.Attachment
;
9 import org
.argeo
.slc
.core
.attachment
.SimpleAttachment
;
10 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
11 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResultListener
;
12 import org
.argeo
.slc
.msg
.test
.tree
.AddTreeTestResultAttachmentRequest
;
13 import org
.argeo
.slc
.msg
.test
.tree
.CloseTreeTestResultRequest
;
14 import org
.argeo
.slc
.msg
.test
.tree
.CreateTreeTestResultRequest
;
15 import org
.argeo
.slc
.msg
.test
.tree
.ResultPartRequest
;
16 import org
.argeo
.slc
.test
.TestResultPart
;
17 import org
.springframework
.jms
.JmsException
;
18 import org
.springframework
.jms
.core
.JmsTemplate
;
20 public class JmsTreeTestResultListener
implements TreeTestResultListener
{
21 private final Log log
= LogFactory
.getLog(getClass());
23 private Boolean onlyOnClose
= false;
24 private JmsTemplate jmsTemplate
;
26 private Destination executionEventDestination
;
28 public void resultPartAdded(TreeTestResult testResult
,
29 TestResultPart testResultPart
) {
34 if (testResult
.getResultParts().size() == 1
35 && testResult
.getResultParts().values().iterator().next()
36 .getParts().size() == 1) {
37 CreateTreeTestResultRequest req
= new CreateTreeTestResultRequest(
40 if (log
.isDebugEnabled())
41 log
.debug("Send create result request for result "
42 + testResult
.getUuid());
44 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
46 ResultPartRequest req
= new ResultPartRequest(testResult
);
48 if (log
.isDebugEnabled())
49 log
.debug("Send result parts for result "
50 + testResult
.getUuid());
52 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
54 } catch (JmsException e
) {
55 log
.warn("Could not notify result part to server: "
57 if (log
.isTraceEnabled())
58 log
.debug("Original error.", e
);
59 } catch (Exception e
) {
60 throw new SlcException("Could not notify to JMS", e
);
64 public void close(TreeTestResult testResult
) {
67 CreateTreeTestResultRequest req
= new CreateTreeTestResultRequest(
70 if (log
.isDebugEnabled())
71 log
.debug("Send create result request for result "
72 + testResult
.getUuid());
74 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
76 CloseTreeTestResultRequest req
= new CloseTreeTestResultRequest(
79 if (log
.isDebugEnabled())
80 log
.debug("Send close result request for result "
81 + testResult
.getUuid());
83 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
86 } catch (JmsException e
) {
87 log
.warn("Could not notify result close to server: "
89 if (log
.isTraceEnabled())
90 log
.debug("Original error.", e
);
91 } catch (Exception e
) {
92 throw new SlcException("Could not notify to JMS", e
);
96 public void addAttachment(TreeTestResult testResult
, Attachment attachment
) {
98 AddTreeTestResultAttachmentRequest req
= new AddTreeTestResultAttachmentRequest();
99 req
.setResultUuid(testResult
.getUuid());
100 req
.setAttachment((SimpleAttachment
) attachment
);
101 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
103 } catch (JmsException e
) {
105 .warn("Could not notify attachment to server: "
107 if (log
.isTraceEnabled())
108 log
.debug("Original error.", e
);
109 } catch (Exception e
) {
110 throw new SlcException("Could not notify to JMS", e
);
115 public void setOnlyOnClose(Boolean onlyOnClose
) {
116 this.onlyOnClose
= onlyOnClose
;
119 public void setJmsTemplate(JmsTemplate jmsTemplate
) {
120 this.jmsTemplate
= jmsTemplate
;
123 public void setExecutionEventDestination(
124 Destination executionEventDestination
) {
125 this.executionEventDestination
= executionEventDestination
;