2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.jms
;
19 import javax
.jms
.Destination
;
21 import org
.apache
.commons
.logging
.Log
;
22 import org
.apache
.commons
.logging
.LogFactory
;
23 import org
.argeo
.slc
.SlcException
;
24 import org
.argeo
.slc
.core
.attachment
.Attachment
;
25 import org
.argeo
.slc
.core
.attachment
.SimpleAttachment
;
26 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
27 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResultListener
;
28 import org
.argeo
.slc
.msg
.test
.tree
.AddTreeTestResultAttachmentRequest
;
29 import org
.argeo
.slc
.msg
.test
.tree
.CloseTreeTestResultRequest
;
30 import org
.argeo
.slc
.msg
.test
.tree
.CreateTreeTestResultRequest
;
31 import org
.argeo
.slc
.msg
.test
.tree
.ResultPartRequest
;
32 import org
.argeo
.slc
.test
.TestResultPart
;
33 import org
.springframework
.jms
.JmsException
;
34 import org
.springframework
.jms
.core
.JmsTemplate
;
36 public class JmsTreeTestResultListener
implements TreeTestResultListener
{
37 private final Log log
= LogFactory
.getLog(getClass());
39 private Boolean onlyOnClose
= false;
40 private JmsTemplate jmsTemplate
;
42 private Destination executionEventDestination
;
44 public void resultPartAdded(TreeTestResult testResult
,
45 TestResultPart testResultPart
) {
50 if (testResult
.getResultParts().size() == 1
51 && testResult
.getResultParts().values().iterator().next()
52 .getParts().size() == 1) {
53 CreateTreeTestResultRequest req
= new CreateTreeTestResultRequest(
56 if (log
.isDebugEnabled())
57 log
.debug("Send create result request for result "
58 + testResult
.getUuid());
60 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
62 ResultPartRequest req
= new ResultPartRequest(testResult
);
64 if (log
.isDebugEnabled())
65 log
.debug("Send result parts for result "
66 + testResult
.getUuid());
68 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
70 } catch (JmsException e
) {
71 log
.warn("Could not notify result part to server: "
73 if (log
.isTraceEnabled())
74 log
.debug("Original error.", e
);
75 } catch (Exception e
) {
76 throw new SlcException("Could not notify to JMS", e
);
80 public void close(TreeTestResult testResult
) {
83 CreateTreeTestResultRequest req
= new CreateTreeTestResultRequest(
86 if (log
.isDebugEnabled())
87 log
.debug("Send create result request for result "
88 + testResult
.getUuid());
90 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
92 CloseTreeTestResultRequest req
= new CloseTreeTestResultRequest(
95 if (log
.isDebugEnabled())
96 log
.debug("Send close result request for result "
97 + testResult
.getUuid());
99 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
102 } catch (JmsException e
) {
103 log
.warn("Could not notify result close to server: "
105 if (log
.isTraceEnabled())
106 log
.debug("Original error.", e
);
107 } catch (Exception e
) {
108 throw new SlcException("Could not notify to JMS", e
);
112 public void addAttachment(TreeTestResult testResult
, Attachment attachment
) {
114 AddTreeTestResultAttachmentRequest req
= new AddTreeTestResultAttachmentRequest();
115 req
.setResultUuid(testResult
.getUuid());
116 req
.setAttachment((SimpleAttachment
) attachment
);
117 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
119 } catch (JmsException e
) {
121 .warn("Could not notify attachment to server: "
123 if (log
.isTraceEnabled())
124 log
.debug("Original error.", e
);
125 } catch (Exception e
) {
126 throw new SlcException("Could not notify to JMS", e
);
131 public void setOnlyOnClose(Boolean onlyOnClose
) {
132 this.onlyOnClose
= onlyOnClose
;
135 public void setJmsTemplate(JmsTemplate jmsTemplate
) {
136 this.jmsTemplate
= jmsTemplate
;
139 public void setExecutionEventDestination(
140 Destination executionEventDestination
) {
141 this.executionEventDestination
= executionEventDestination
;