1+ /*
2+ * Copyright 2016 the original author or authors.
3+ *
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
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
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.
15+ */
16+ package org .springframework .ws .client .support .interceptor ;
17+
18+ import java .util .ArrayList ;
19+ import java .util .List ;
20+
21+ import org .junit .Assert ;
22+ import org .junit .Test ;
23+
24+ import org .springframework .ws .client .WebServiceClientException ;
25+ import org .springframework .ws .context .MessageContext ;
26+
27+ /**
28+ * @author Greg Turnquist
29+ */
30+ public class ClientInterceptorAdapterTest {
31+
32+ @ Test
33+ public void handleEmptyInterceptor () {
34+ ClientInterceptor interceptor = new ClientInterceptorAdapter () {};
35+
36+ Assert .assertTrue (interceptor .handleRequest (null ));
37+ Assert .assertTrue (interceptor .handleResponse (null ));
38+ Assert .assertTrue (interceptor .handleFault (null ));
39+
40+ interceptor .afterCompletion (null , null );
41+ }
42+
43+ @ Test
44+ public void handleTestAdapter () {
45+ TestClientInterceptorAdapter interceptor = new TestClientInterceptorAdapter (new ArrayList <>());
46+
47+ Assert .assertFalse (interceptor .handleRequest (null ));
48+ Assert .assertFalse (interceptor .handleResponse (null ));
49+ Assert .assertFalse (interceptor .handleFault (null ));
50+
51+ interceptor .afterCompletion (null , null );
52+
53+ List <String > bits = interceptor .getBits ();
54+
55+ Assert .assertTrue (bits .contains ("handled request" ));
56+ Assert .assertTrue (bits .contains ("handled response" ));
57+ Assert .assertTrue (bits .contains ("handled fault" ));
58+ Assert .assertTrue (bits .contains ("handled afterCompletion" ));
59+ }
60+
61+ static class TestClientInterceptorAdapter extends ClientInterceptorAdapter {
62+
63+ private final List <String > bits ;
64+
65+ public TestClientInterceptorAdapter (List <String > bits ) {
66+ this .bits = bits ;
67+ }
68+
69+ public List <String > getBits () {
70+ return bits ;
71+ }
72+
73+ @ Override
74+ public boolean handleRequest (MessageContext messageContext ) throws WebServiceClientException {
75+ bits .add ("handled request" );
76+ return false ;
77+ }
78+
79+ @ Override
80+ public boolean handleResponse (MessageContext messageContext ) throws WebServiceClientException {
81+ bits .add ("handled response" );
82+ return false ;
83+ }
84+
85+ @ Override
86+ public boolean handleFault (MessageContext messageContext ) throws WebServiceClientException {
87+ bits .add ("handled fault" );
88+ return false ;
89+ }
90+
91+ @ Override
92+ public void afterCompletion (MessageContext messageContext , Exception ex ) throws WebServiceClientException {
93+ bits .add ("handled afterCompletion" );
94+ }
95+ }
96+
97+ }
0 commit comments