Skip to content

Commit 6b3f990

Browse files
committed
SWS-951 - Add tests and polish
1 parent b02a8be commit 6b3f990

File tree

2 files changed

+140
-26
lines changed

2 files changed

+140
-26
lines changed
Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
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+
*/
116
package org.springframework.ws.client.support.interceptor;
217

318
import org.apache.commons.logging.Log;
419
import org.apache.commons.logging.LogFactory;
20+
521
import org.springframework.ws.client.WebServiceClientException;
622
import org.springframework.ws.context.MessageContext;
723

824
/**
9-
*
1025
* Default implementation of the {@code ClientInterceptor} interface, for simplified implementation of
1126
* pre-only/post-only interceptors.
1227
*
@@ -15,29 +30,31 @@
1530
*/
1631
public abstract class ClientInterceptorAdapter implements ClientInterceptor {
1732

18-
/** Logger available to subclasses */
19-
protected final Log logger = LogFactory.getLog(getClass());
20-
21-
@Override
22-
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
23-
return true;
24-
}
25-
26-
@Override
27-
public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
28-
return true;
29-
}
30-
31-
@Override
32-
public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
33-
return true;
34-
}
35-
36-
/**
37-
* Does nothing by default.
38-
*/
39-
@Override
40-
public void afterCompletion(MessageContext messageContext, Exception ex) throws WebServiceClientException {
41-
42-
}
33+
/**
34+
* Logger available to subclasses
35+
*/
36+
protected final Log logger = LogFactory.getLog(getClass());
37+
38+
@Override
39+
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
40+
return true;
41+
}
42+
43+
@Override
44+
public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
45+
return true;
46+
}
47+
48+
@Override
49+
public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
50+
return true;
51+
}
52+
53+
/**
54+
* Does nothing by default.
55+
*/
56+
@Override
57+
public void afterCompletion(MessageContext messageContext, Exception ex) throws WebServiceClientException {
58+
59+
}
4360
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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

Comments
 (0)