SWS-951 - Add tests and polish
This commit is contained in:
@@ -1,12 +1,27 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ws.client.support.interceptor;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.ws.client.WebServiceClientException;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* Default implementation of the {@code ClientInterceptor} interface, for simplified implementation of
|
||||
* pre-only/post-only interceptors.
|
||||
*
|
||||
@@ -15,29 +30,31 @@ import org.springframework.ws.context.MessageContext;
|
||||
*/
|
||||
public abstract class ClientInterceptorAdapter implements ClientInterceptor {
|
||||
|
||||
/** Logger available to subclasses */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
/**
|
||||
* Logger available to subclasses
|
||||
*/
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@Override
|
||||
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing by default.
|
||||
*/
|
||||
@Override
|
||||
public void afterCompletion(MessageContext messageContext, Exception ex) throws WebServiceClientException {
|
||||
/**
|
||||
* Does nothing by default.
|
||||
*/
|
||||
@Override
|
||||
public void afterCompletion(MessageContext messageContext, Exception ex) throws WebServiceClientException {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ws.client.support.interceptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.ws.client.WebServiceClientException;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class ClientInterceptorAdapterTest {
|
||||
|
||||
@Test
|
||||
public void handleEmptyInterceptor() {
|
||||
ClientInterceptor interceptor = new ClientInterceptorAdapter() {};
|
||||
|
||||
Assert.assertTrue(interceptor.handleRequest(null));
|
||||
Assert.assertTrue(interceptor.handleResponse(null));
|
||||
Assert.assertTrue(interceptor.handleFault(null));
|
||||
|
||||
interceptor.afterCompletion(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleTestAdapter() {
|
||||
TestClientInterceptorAdapter interceptor = new TestClientInterceptorAdapter(new ArrayList<>());
|
||||
|
||||
Assert.assertFalse(interceptor.handleRequest(null));
|
||||
Assert.assertFalse(interceptor.handleResponse(null));
|
||||
Assert.assertFalse(interceptor.handleFault(null));
|
||||
|
||||
interceptor.afterCompletion(null, null);
|
||||
|
||||
List<String> bits = interceptor.getBits();
|
||||
|
||||
Assert.assertTrue(bits.contains("handled request"));
|
||||
Assert.assertTrue(bits.contains("handled response"));
|
||||
Assert.assertTrue(bits.contains("handled fault"));
|
||||
Assert.assertTrue(bits.contains("handled afterCompletion"));
|
||||
}
|
||||
|
||||
static class TestClientInterceptorAdapter extends ClientInterceptorAdapter {
|
||||
|
||||
private final List<String> bits;
|
||||
|
||||
public TestClientInterceptorAdapter(List<String> bits) {
|
||||
this.bits = bits;
|
||||
}
|
||||
|
||||
public List<String> getBits() {
|
||||
return bits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
|
||||
bits.add("handled request");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
|
||||
bits.add("handled response");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
|
||||
bits.add("handled fault");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(MessageContext messageContext, Exception ex) throws WebServiceClientException {
|
||||
bits.add("handled afterCompletion");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user