Skip to content

Commit

Permalink
CXF-8846: Get rid of EasyMock in cxf-rt-bindings-soap (#1307)
Browse files Browse the repository at this point in the history
  • Loading branch information
reta authored Jun 23, 2023
1 parent 8cd5925 commit 539ec7f
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 141 deletions.
5 changes: 3 additions & 2 deletions rt/bindings/soap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${cxf.mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,20 @@
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.service.model.ServiceInfo;

import org.easymock.EasyMock;
import org.easymock.IMocksControl;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RPCInInterceptorTest extends TestBase {

private static final String TNS = "http://apache.org/hello_world_rpclit";

private static final String OPNAME = "sendReceiveData";

private IMocksControl control = EasyMock.createNiceControl();

@Before
public void setUp() throws Exception {
super.setUp();
Expand All @@ -64,19 +62,16 @@ public void setUp() throws Exception {
boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setIndex(0);
soapMessage.getExchange().put(BindingOperationInfo.class, boi);

control.reset();
Service service = control.createMock(Service.class);
Service service = mock(Service.class);
JAXBDataBinding dataBinding = new JAXBDataBinding(MyComplexStruct.class);
service.getDataBinding();
EasyMock.expectLastCall().andReturn(dataBinding).anyTimes();
service.getServiceInfos();
when(service.getDataBinding()).thenReturn(dataBinding);

List<ServiceInfo> list = Arrays.asList(si);
EasyMock.expectLastCall().andReturn(list).anyTimes();
EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
when(service.getServiceInfos()).thenReturn(list);
when(service.isEmpty()).thenReturn(true);

soapMessage.getExchange().put(Service.class, service);
soapMessage.getExchange().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
control.replay();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
import org.apache.cxf.staxutils.DepthXMLStreamReader;
import org.apache.cxf.staxutils.StaxUtils;

import org.easymock.EasyMock;
import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RPCOutInterceptorTest extends TestBase {

Expand All @@ -57,8 +57,6 @@ public class RPCOutInterceptorTest extends TestBase {

private ByteArrayOutputStream baos = new ByteArrayOutputStream(64 * 1024);

private IMocksControl control = EasyMock.createNiceControl();

@Before
public void setUp() throws Exception {
super.setUp();
Expand All @@ -70,19 +68,16 @@ public void setUp() throws Exception {
boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setIndex(0);
soapMessage.getExchange().put(BindingOperationInfo.class, boi);

control.reset();
Service service = control.createMock(Service.class);
EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
Service service = mock(Service.class);
when(service.isEmpty()).thenReturn(true);
JAXBDataBinding dataBinding = new JAXBDataBinding(MyComplexStruct.class);
service.getDataBinding();
EasyMock.expectLastCall().andReturn(dataBinding).anyTimes();
service.getServiceInfos();
when(service.getDataBinding()).thenReturn(dataBinding);

List<ServiceInfo> list = Arrays.asList(si);
EasyMock.expectLastCall().andReturn(list).anyTimes();
when(service.getServiceInfos()).thenReturn(list);

soapMessage.getExchange().put(Service.class, service);
soapMessage.getExchange().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
control.replay();

MyComplexStruct mcs = new MyComplexStruct();
mcs.setElem1("elem1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,21 @@
import org.apache.cxf.transport.DestinationFactoryManager;
import org.apache.cxf.wsdl11.WSDLServiceBuilder;

import org.easymock.EasyMock;
import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ServiceModelUtilTest {
private static final String WSDL_PATH = "test-soap-header.wsdl";
private Service service;
private ServiceInfo serviceInfo;

private IMocksControl control;
private Bus bus;
private BindingFactoryManager bindingFactoryManager;

Expand All @@ -74,17 +72,15 @@ public void setUp() throws Exception {
}
}

control = EasyMock.createNiceControl();
bus = control.createMock(Bus.class);
bindingFactoryManager = control.createMock(BindingFactoryManager.class);
bus = mock(Bus.class);
bindingFactoryManager = mock(BindingFactoryManager.class);
WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus);

EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager);
when(bus.getExtension(BindingFactoryManager.class)).thenReturn(bindingFactoryManager);

DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
DestinationFactoryManager dfm = mock(DestinationFactoryManager.class);
when(bus.getExtension(DestinationFactoryManager.class)).thenReturn(dfm);

control.replay();
serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,18 @@
import org.apache.cxf.wsdl.WSDLConstants;
import org.apache.cxf.wsdl11.WSDLServiceBuilder;

import org.easymock.IMocksControl;
import org.junit.Before;
import org.junit.Test;

import static org.easymock.EasyMock.createNiceControl;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class SoapBindingFactoryTest {
IMocksControl control;

@Before
public void setUp() {
control = createNiceControl();
}

private Bus getMockBus() {
return control.createMock(Bus.class);
return mock(Bus.class);
}

private BindingFactoryManager getBindingFactoryManager(String ns, Bus bus) throws BusException {
Expand All @@ -84,13 +74,10 @@ public void testNoBodyParts() throws Exception {

BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);

bus.getExtension(BindingFactoryManager.class);
expectLastCall().andReturn(bfm).anyTimes();
when(bus.getExtension(BindingFactoryManager.class)).thenReturn(bfm);

DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

control.replay();
DestinationFactoryManager dfm = mock(DestinationFactoryManager.class);
when(bus.getExtension(DestinationFactoryManager.class)).thenReturn(dfm);

WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
ServiceInfo serviceInfo = builder
Expand Down Expand Up @@ -133,13 +120,10 @@ public void testFactory() throws Exception {

BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);

bus.getExtension(BindingFactoryManager.class);
expectLastCall().andReturn(bfm).anyTimes();

DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
when(bus.getExtension(BindingFactoryManager.class)).thenReturn(bfm);

control.replay();
DestinationFactoryManager dfm = mock(DestinationFactoryManager.class);
when(bus.getExtension(DestinationFactoryManager.class)).thenReturn(dfm);

WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
ServiceInfo serviceInfo = builder
Expand Down Expand Up @@ -180,12 +164,10 @@ public void testSoap12Factory() throws Exception {

BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP12, bus);

expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm);

DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
when(bus.getExtension(BindingFactoryManager.class)).thenReturn(bfm);

control.replay();
DestinationFactoryManager dfm = mock(DestinationFactoryManager.class);
when(bus.getExtension(DestinationFactoryManager.class)).thenReturn(dfm);

WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
ServiceInfo serviceInfo = builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
import org.apache.cxf.transport.DestinationFactoryManager;
import org.apache.cxf.wsdl11.WSDLServiceBuilder;

import org.easymock.EasyMock;
import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;

import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TestBase {

Expand Down Expand Up @@ -118,10 +118,9 @@ protected ServiceInfo getMockedServiceModel(String wsdlUrl) throws Exception {
wsdlReader.setFeature("javax.wsdl.verbose", false);
Definition def = wsdlReader.readWSDL(wsdlUrl);

IMocksControl control = EasyMock.createNiceControl();
Bus bus = control.createMock(Bus.class);
BindingFactoryManager bindingFactoryManager = control.createMock(BindingFactoryManager.class);
DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
Bus bus = mock(Bus.class);
BindingFactoryManager bindingFactoryManager = mock(BindingFactoryManager.class);
DestinationFactoryManager dfm = mock(DestinationFactoryManager.class);
WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus);

Service service = null;
Expand All @@ -133,9 +132,8 @@ protected ServiceInfo getMockedServiceModel(String wsdlUrl) throws Exception {
}
}

EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager);
EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
control.replay();
when(bus.getExtension(BindingFactoryManager.class)).thenReturn(bindingFactoryManager);
when(bus.getExtension(DestinationFactoryManager.class)).thenReturn(dfm);

ServiceInfo serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
serviceInfo.setProperty(WSDLServiceBuilder.WSDL_DEFINITION, null);
Expand Down
Loading

0 comments on commit 539ec7f

Please sign in to comment.