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 /** JMS based tree test result listener implementation. */
37 public class JmsTreeTestResultListener
implements TreeTestResultListener
{
38 private final Log log
= LogFactory
.getLog(getClass());
40 private Boolean onlyOnClose
= false;
41 private JmsTemplate jmsTemplate
;
43 private Destination executionEventDestination
;
45 public void resultPartAdded(TreeTestResult testResult
,
46 TestResultPart testResultPart
) {
51 if (testResult
.getResultParts().size() == 1
52 && testResult
.getResultParts().values().iterator().next()
53 .getParts().size() == 1) {
54 CreateTreeTestResultRequest req
= new CreateTreeTestResultRequest(
57 if (log
.isTraceEnabled())
58 log
.trace("Send create result request for result "
59 + testResult
.getUuid());
61 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
63 ResultPartRequest req
= new ResultPartRequest(testResult
);
65 if (log
.isTraceEnabled())
66 log
.trace("Send result parts for result "
67 + testResult
.getUuid());
69 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
71 } catch (JmsException e
) {
72 log
.warn("Could not notify result part to server: "
74 if (log
.isTraceEnabled())
75 log
.debug("Original error.", e
);
76 } catch (Exception e
) {
77 throw new SlcException("Could not notify to JMS", e
);
81 public void close(TreeTestResult testResult
) {
84 CreateTreeTestResultRequest req
= new CreateTreeTestResultRequest(
87 if (log
.isTraceEnabled())
88 log
.trace("Send onClose create result request for result "
89 + testResult
.getUuid());
91 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
93 CloseTreeTestResultRequest req
= new CloseTreeTestResultRequest(
96 if (log
.isTraceEnabled())
97 log
.trace("Send close result request for result "
98 + testResult
.getUuid());
100 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
103 } catch (JmsException e
) {
104 log
.warn("Could not notify result close to server: "
106 if (log
.isTraceEnabled())
107 log
.debug("Original error.", e
);
108 } catch (Exception e
) {
109 throw new SlcException("Could not notify to JMS", e
);
113 public void addAttachment(TreeTestResult testResult
, Attachment attachment
) {
118 AddTreeTestResultAttachmentRequest req
= new AddTreeTestResultAttachmentRequest();
119 req
.setResultUuid(testResult
.getUuid());
120 req
.setAttachment((SimpleAttachment
) attachment
);
121 jmsTemplate
.convertAndSend(executionEventDestination
, req
);
123 } catch (JmsException e
) {
125 .warn("Could not notify attachment to server: "
127 if (log
.isTraceEnabled())
128 log
.debug("Original error.", e
);
129 } catch (Exception e
) {
130 throw new SlcException("Could not notify to JMS", e
);
135 /** Publishes the test result only when it gets closed. */
136 public void setOnlyOnClose(Boolean onlyOnClose
) {
137 this.onlyOnClose
= onlyOnClose
;
140 public void setJmsTemplate(JmsTemplate jmsTemplate
) {
141 this.jmsTemplate
= jmsTemplate
;
144 public void setExecutionEventDestination(
145 Destination executionEventDestination
) {
146 this.executionEventDestination
= executionEventDestination
;