From de7909cc9af1f575d0d4f73e4bfe17f1152fb225 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Sun, 2 Jul 2023 14:13:09 -0400 Subject: [PATCH] CXF-8857: Get rid of EasyMock in cxf-rt-frontend-jaxws --- rt/frontend/jaxws/pom.xml | 5 +- .../cxf/jaxws/JAXWSMethodInvokerTest.java | 50 ++++++------ ...bstractProtocolHandlerInterceptorTest.java | 49 +++++------- .../handler/HandlerChainBuilderTest.java | 8 +- .../LogicalHandlerInterceptorTest.java | 69 ++++++++--------- .../soap/SOAPHandlerInterceptorTest.java | 76 +++++++------------ .../JaxWsServiceConfigurationTest.java | 16 ++-- .../http_jaxws_spi/HttpHandlerImplTest.java | 19 ++--- .../JAXWSHttpSpiDestinationTest.java | 47 +++++------- .../JAXWSHttpSpiTransportFactoryTest.java | 15 ++-- 10 files changed, 148 insertions(+), 206 deletions(-) diff --git a/rt/frontend/jaxws/pom.xml b/rt/frontend/jaxws/pom.xml index 62db219d70b..6f8ec8ef2f3 100644 --- a/rt/frontend/jaxws/pom.xml +++ b/rt/frontend/jaxws/pom.xml @@ -56,8 +56,9 @@ test - org.easymock - easymock + org.mockito + mockito-core + ${cxf.mockito.version} test diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java index e31d98c91f8..f72728eb2f0 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java @@ -54,7 +54,6 @@ import org.apache.cxf.service.invoker.MethodDispatcher; import org.apache.cxf.service.model.BindingOperationInfo; -import org.easymock.EasyMock; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -64,23 +63,23 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class JAXWSMethodInvokerTest { private static final QName TEST_HEADER_NAME = new QName("testHeader"); - Factory factory = EasyMock.createMock(Factory.class); - Object target = EasyMock.createMock(Hello.class); + Factory factory = mock(Factory.class); + Object target = mock(Hello.class); @Test public void testFactoryBeans() throws Throwable { - Exchange ex = EasyMock.createMock(Exchange.class); - EasyMock.reset(factory); - factory.create(ex); - EasyMock.expectLastCall().andReturn(target); - EasyMock.replay(factory); + Exchange ex = mock(Exchange.class); + when(factory.create(ex)).thenReturn(target); JAXWSMethodInvoker jaxwsMethodInvoker = new JAXWSMethodInvoker(factory); Object object = jaxwsMethodInvoker.getServiceObject(ex); assertEquals("the target object and service object should be equal ", object, target); - EasyMock.verify(factory); } @@ -105,6 +104,8 @@ public void testSuspendedException() throws Throwable { assertSame(suspendedEx, serviceObject.getSuspendedException()); assertSame(originalException, suspendedEx.getRuntimeException()); } + + verify(factory, atLeastOnce()).release(ex, serviceObject); } @Test @@ -124,6 +125,8 @@ public void testFaultAvoidHeadersCopy() throws Throwable { Message outMsg = ex.getOutMessage(); assertNull(outMsg); } + + verify(factory, atLeastOnce()).release(ex, serviceObject); } @Test @@ -150,6 +153,8 @@ public void testFaultHeadersCopy() throws Throwable { assertEquals(1, headers.size()); assertEquals(TEST_HEADER_NAME, headers.get(0).getName()); } + + verify(factory, atLeastOnce()).release(ex, serviceObject); } @Test @@ -209,36 +214,27 @@ public void testProviderInterpretNullAsOneway() throws Throwable { .invoke(ex, new MessageContentsList(new Object[]{new StreamSource()})); assertNull(obj); assertTrue(ex.isOneWay()); + + verify(factory, atLeastOnce()).release(ex, serviceObject); } private JAXWSMethodInvoker prepareJAXWSMethodInvoker(Exchange ex, Object serviceObject, Method serviceMethod) throws Throwable { - EasyMock.reset(factory); - factory.create(ex); - EasyMock.expectLastCall().andReturn(serviceObject).anyTimes(); + when(factory.create(ex)).thenReturn(serviceObject); factory.release(ex, serviceObject); - EasyMock.expectLastCall().anyTimes(); - EasyMock.replay(factory); BindingOperationInfo boi = new BindingOperationInfo(); ex.put(BindingOperationInfo.class, boi); - Service serviceClass = EasyMock.createMock(Service.class); - serviceClass.size(); - EasyMock.expectLastCall().andReturn(0).anyTimes(); - serviceClass.isEmpty(); - EasyMock.expectLastCall().andReturn(true).anyTimes(); + Service serviceClass = mock(Service.class); + when(serviceClass.size()).thenReturn(0); + when(serviceClass.isEmpty()).thenReturn(true); ex.put(Service.class, serviceClass); - MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class); - serviceClass.get(MethodDispatcher.class.getName()); - EasyMock.expectLastCall().andReturn(md).anyTimes(); + MethodDispatcher md = mock(MethodDispatcher.class); + when(serviceClass.get(MethodDispatcher.class.getName())).thenReturn(md); - md.getMethod(boi); - EasyMock.expectLastCall().andReturn(serviceMethod).anyTimes(); - - EasyMock.replay(md); - EasyMock.replay(serviceClass); + when(md.getMethod(boi)).thenReturn(serviceMethod); // initialize the contextCache ex.getInMessage().getContextualProperty("dummy"); diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AbstractProtocolHandlerInterceptorTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AbstractProtocolHandlerInterceptorTest.java index d169dcc59d9..684fc4ff33a 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AbstractProtocolHandlerInterceptorTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AbstractProtocolHandlerInterceptorTest.java @@ -29,20 +29,17 @@ import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; -import org.easymock.IMocksControl; -import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.easymock.EasyMock.createNiceControl; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.isA; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class AbstractProtocolHandlerInterceptorTest { - private IMocksControl control; private Binding binding; private HandlerChainInvoker invoker; private IIOPMessage message; @@ -50,31 +47,24 @@ public class AbstractProtocolHandlerInterceptorTest { @Before public void setUp() { - control = createNiceControl(); - invoker = control.createMock(HandlerChainInvoker.class); - message = control.createMock(IIOPMessage.class); - exchange = control.createMock(Exchange.class); - binding = control.createMock(Binding.class); + invoker = mock(HandlerChainInvoker.class); + message = mock(IIOPMessage.class); + exchange = mock(Exchange.class); + binding = mock(Binding.class); @SuppressWarnings("rawtypes") List list = new ArrayList<>(); list.add(null); - expect(binding.getHandlerChain()).andReturn(list).anyTimes(); - } - - @After - public void tearDown() { - control.verify(); + when(binding.getHandlerChain()).thenReturn(list); } @Test public void testInterceptSuccess() { - expect(message.getExchange()).andReturn(exchange).anyTimes(); - expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes(); - expect(invoker.invokeProtocolHandlers(eq(false), - isA(MessageContext.class))).andReturn(true); - expect(exchange.getOutMessage()).andReturn(message); - control.replay(); + when(message.getExchange()).thenReturn(exchange); + when(exchange.get(HandlerChainInvoker.class)).thenReturn(invoker); + when(invoker.invokeProtocolHandlers(eq(false), + isA(MessageContext.class))).thenReturn(true); + when(exchange.getOutMessage()).thenReturn(message); IIOPHandlerInterceptor pi = new IIOPHandlerInterceptor(binding); assertEquals("unexpected phase", "user-protocol", pi.getPhase()); pi.handleMessage(message); @@ -82,13 +72,12 @@ public void testInterceptSuccess() { @Test public void testInterceptFailure() { - expect(message.getExchange()).andReturn(exchange).anyTimes(); - expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes(); - expect(exchange.getOutMessage()).andReturn(message); - expect( + when(message.getExchange()).thenReturn(exchange); + when(exchange.get(HandlerChainInvoker.class)).thenReturn(invoker); + when(exchange.getOutMessage()).thenReturn(message); + when( invoker.invokeProtocolHandlers(eq(false), - isA(MessageContext.class))).andReturn(false); - control.replay(); + isA(MessageContext.class))).thenReturn(false); IIOPHandlerInterceptor pi = new IIOPHandlerInterceptor(binding); pi.handleMessage(message); } diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainBuilderTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainBuilderTest.java index e2b0e957356..c3888500718 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainBuilderTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainBuilderTest.java @@ -35,7 +35,6 @@ import org.apache.cxf.jaxws.handler.types.PortComponentHandlerType; import org.apache.cxf.jaxws.handler.types.XsdStringType; -import org.easymock.EasyMock; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -45,16 +44,17 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; @SuppressWarnings("rawtypes") public class HandlerChainBuilderTest { - Handler[] allHandlers = {EasyMock.createMock(LogicalHandler.class), EasyMock.createMock(Handler.class), - EasyMock.createMock(Handler.class), EasyMock.createMock(LogicalHandler.class)}; + Handler[] allHandlers = {mock(LogicalHandler.class), mock(Handler.class), + mock(Handler.class), mock(LogicalHandler.class)}; Handler[] logicalHandlers = {allHandlers[0], allHandlers[3]}; Handler[] protocolHandlers = {allHandlers[1], allHandlers[2]}; - HandlerChainBuilder builder = new HandlerChainBuilder(EasyMock.createNiceMock(Bus.class)); + HandlerChainBuilder builder = new HandlerChainBuilder(mock(Bus.class)); @Test diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalHandlerInterceptorTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalHandlerInterceptorTest.java index 79fdca1d260..7d6a2eb9138 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalHandlerInterceptorTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalHandlerInterceptorTest.java @@ -38,21 +38,21 @@ import org.apache.cxf.transport.MessageObserver; import org.apache.handlers.types.AddNumbersResponse; -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.createNiceControl; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.isA; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class LogicalHandlerInterceptorTest { - private IMocksControl control; private Binding binding; private HandlerChainInvoker invoker; private Message message; @@ -60,11 +60,10 @@ public class LogicalHandlerInterceptorTest { @Before public void setUp() { - control = createNiceControl(); - binding = control.createMock(Binding.class); - invoker = control.createMock(HandlerChainInvoker.class); - message = control.createMock(Message.class); - exchange = control.createMock(Exchange.class); + binding = mock(Binding.class); + invoker = mock(HandlerChainInvoker.class); + message = mock(Message.class); + exchange = mock(Exchange.class); } @After @@ -88,21 +87,19 @@ public boolean handleMessage(LogicalMessageContext arg0) { }); @SuppressWarnings("rawtypes") List hList = CastUtils.cast(list); - expect(binding.getHandlerChain()).andReturn(hList).anyTimes(); - expect(invoker.getLogicalHandlers()).andReturn(list); - expect(message.getExchange()).andReturn(exchange).anyTimes(); - expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes(); - expect(message.keySet()).andReturn(new TreeSet()).anyTimes(); - expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker); - expect(exchange.getOutMessage()).andReturn(message); - expect(invoker.invokeLogicalHandlers(eq(true), isA(LogicalMessageContext.class))) - .andReturn(true); - - control.replay(); + when(binding.getHandlerChain()).thenReturn(hList); + when(invoker.getLogicalHandlers()).thenReturn(list); + when(message.getExchange()).thenReturn(exchange); + when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.TRUE); + when(message.keySet()).thenReturn(new TreeSet()); + when(exchange.get(HandlerChainInvoker.class)).thenReturn(invoker); + when(exchange.getOutMessage()).thenReturn(message); + when(invoker.invokeLogicalHandlers(eq(true), isA(LogicalMessageContext.class))) + .thenReturn(true); + LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding); - assertEquals("unexpected phase", "pre-protocol-frontend", li.getPhase()); + assertEquals("unwhened phase", "pre-protocol-frontend", li.getPhase()); li.handleMessage(message); - control.verify(); } //JAX-WS spec: If handler returns false, for a request-response MEP, if the message @@ -132,28 +129,24 @@ public boolean handleMessage(LogicalMessageContext messageContext) { }); HandlerChainInvoker invoker1 = new HandlerChainInvoker(list); - IMocksControl control1 = createNiceControl(); - Binding binding1 = control1.createMock(Binding.class); + Binding binding1 = mock(Binding.class); @SuppressWarnings("rawtypes") List hList = CastUtils.cast(list); - expect(binding1.getHandlerChain()).andReturn(hList).anyTimes(); - Exchange exchange1 = control1.createMock(Exchange.class); - expect(exchange1.get(HandlerChainInvoker.class)).andReturn(invoker1).anyTimes(); + when(binding1.getHandlerChain()).thenReturn(hList); + Exchange exchange1 = mock(Exchange.class); + when(exchange1.get(HandlerChainInvoker.class)).thenReturn(invoker1); Message outMessage = new MessageImpl(); outMessage.setExchange(exchange1); - InterceptorChain chain = control1.createMock(InterceptorChain.class); + InterceptorChain chain = spy(InterceptorChain.class); outMessage.setInterceptorChain(chain); chain.abort(); - EasyMock.expectLastCall(); - MessageObserver observer = control1.createMock(MessageObserver.class); - expect(exchange1.get(MessageObserver.class)).andReturn(observer).anyTimes(); + MessageObserver observer = spy(MessageObserver.class); + when(exchange1.get(MessageObserver.class)).thenReturn(observer); observer.onMessage(isA(Message.class)); - EasyMock.expectLastCall(); - - control1.replay(); LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding1); li.handleMessage(outMessage); - control1.verify(); + verify(chain, atLeastOnce()).abort(); + verify(observer, atLeastOnce()).onMessage(isA(Message.class)); } } \ No newline at end of file diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java index b1f9ebc7288..fc5204b3f9a 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java @@ -72,17 +72,16 @@ import org.apache.cxf.staxutils.PartialXMLStreamReader; import org.apache.cxf.staxutils.StaxUtils; -import org.easymock.IMocksControl; import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.easymock.EasyMock.createNiceControl; -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 SOAPHandlerInterceptorTest { @@ -126,15 +125,14 @@ public void close(MessageContext messageContext) { }); HandlerChainInvoker invoker = new HandlerChainInvoker(list); - IMocksControl control = createNiceControl(); - Binding binding = control.createMock(Binding.class); - expect(binding.getHandlerChain()).andReturn(list).anyTimes(); - Exchange exchange = control.createMock(Exchange.class); - expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes(); + Binding binding = mock(Binding.class); + when(binding.getHandlerChain()).thenReturn(list); + Exchange exchange = mock(Exchange.class); + when(exchange.get(HandlerChainInvoker.class)).thenReturn(invoker); SoapMessage message = new SoapMessage(new MessageImpl()); message.setExchange(exchange); // This is to set direction to outbound - expect(exchange.getOutMessage()).andReturn(message).anyTimes(); + when(exchange.getOutMessage()).thenReturn(message); CachedStream originalEmptyOs = new CachedStream(); XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(originalEmptyOs); @@ -165,12 +163,9 @@ public void handleMessage(SoapMessage message) throws Fault { chain.add(new SOAPHandlerInterceptor(binding)); message.setInterceptorChain(chain); - control.replay(); chain.doIntercept(message); - control.verify(); - writer.flush(); // Verify SOAPMessage @@ -231,13 +226,12 @@ public void close(MessageContext messageContext) { }); HandlerChainInvoker invoker = new HandlerChainInvoker(list); - IMocksControl control = createNiceControl(); - Binding binding = control.createMock(Binding.class); - expect(binding.getHandlerChain()).andReturn(list).anyTimes(); - Exchange exchange = control.createMock(Exchange.class); - expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes(); + Binding binding = mock(Binding.class); + when(binding.getHandlerChain()).thenReturn(list); + Exchange exchange = mock(Exchange.class); + when(exchange.get(HandlerChainInvoker.class)).thenReturn(invoker); // This is to set direction to inbound - expect(exchange.getOutMessage()).andReturn(null); + when(exchange.getOutMessage()).thenReturn(null); SoapMessage message = new SoapMessage(new MessageImpl()); message.setExchange(exchange); @@ -251,11 +245,8 @@ public void close(MessageContext messageContext) { message.getHeaders().add(new Header(new QName(node.getNamespaceURI(), node.getLocalName()), node)); - control.replay(); - SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding); li.handleMessage(message); - control.verify(); // Verify SOAPMessage header SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class); @@ -332,15 +323,14 @@ public void close(MessageContext messageContext) { }); HandlerChainInvoker invoker = new HandlerChainInvoker(list); - IMocksControl control = createNiceControl(); - Binding binding = control.createMock(Binding.class); - expect(binding.getHandlerChain()).andReturn(list).anyTimes(); - Exchange exchange = control.createMock(Exchange.class); - expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes(); + Binding binding = mock(Binding.class); + when(binding.getHandlerChain()).thenReturn(list); + Exchange exchange = mock(Exchange.class); + when(exchange.get(HandlerChainInvoker.class)).thenReturn(invoker); SoapMessage message = new SoapMessage(new MessageImpl()); message.setExchange(exchange); // This is to set direction to outbound - expect(exchange.getOutMessage()).andReturn(message).anyTimes(); + when(exchange.getOutMessage()).thenReturn(message); CachedStream originalEmptyOs = new CachedStream(); message.setContent(OutputStream.class, originalEmptyOs); @@ -372,12 +362,9 @@ public void handleMessage(SoapMessage message) throws Fault { }); chain.add(new SOAPHandlerInterceptor(binding)); message.setInterceptorChain(chain); - control.replay(); chain.doIntercept(message); - control.verify(); - // Verify SOAPMessage header SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class); @@ -418,24 +405,21 @@ public void close(MessageContext messageContext) { }); HandlerChainInvoker invoker = new HandlerChainInvoker(list); - IMocksControl control = createNiceControl(); - Binding binding = control.createMock(Binding.class); - Exchange exchange = control.createMock(Exchange.class); - expect(binding.getHandlerChain()).andReturn(list).anyTimes(); - expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes(); + Binding binding = mock(Binding.class); + Exchange exchange = mock(Exchange.class); + when(binding.getHandlerChain()).thenReturn(list); + when(exchange.get(HandlerChainInvoker.class)).thenReturn(invoker); // This is to set direction to inbound - expect(exchange.getOutMessage()).andReturn(null); + when(exchange.getOutMessage()).thenReturn(null); SoapMessage message = new SoapMessage(new MessageImpl()); message.setExchange(exchange); XMLStreamReader reader = preparemXMLStreamReader("resources/greetMeRpcLitReq.xml"); message.setContent(XMLStreamReader.class, reader); - control.replay(); SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding); li.handleMessage(message); - control.verify(); // Verify SOAPMessage SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class); @@ -472,15 +456,13 @@ public void close(MessageContext messageContext) { }); HandlerChainInvoker invoker = new HandlerChainInvoker(list); - IMocksControl control = createNiceControl(); - Binding binding = control.createMock(Binding.class); - expect(binding.getHandlerChain()).andReturn(list).anyTimes(); - SoapMessage message = control.createMock(SoapMessage.class); - Exchange exchange = control.createMock(Exchange.class); - expect(message.getExchange()).andReturn(exchange).anyTimes(); - expect(message.keySet()).andReturn(new HashSet<>()); - expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker); - control.replay(); + Binding binding = mock(Binding.class); + when(binding.getHandlerChain()).thenReturn(list); + SoapMessage message = mock(SoapMessage.class); + Exchange exchange = mock(Exchange.class); + when(message.getExchange()).thenReturn(exchange); + when(message.keySet()).thenReturn(new HashSet<>()); + when(exchange.get(HandlerChainInvoker.class)).thenReturn(invoker); SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding); Set understood = li.getUnderstoodHeaders(); diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceConfigurationTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceConfigurationTest.java index c1d342526a6..105bbdfe4a1 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceConfigurationTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceConfigurationTest.java @@ -40,8 +40,6 @@ import org.apache.cxf.wsdl11.CatalogWSDLLocator; import org.apache.cxf.wsdl11.WSDLServiceBuilder; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.Before; import org.junit.Test; @@ -49,6 +47,8 @@ import static org.junit.Assert.assertFalse; 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 JaxWsServiceConfigurationTest { @@ -153,10 +153,9 @@ private ServiceInfo getMockedServiceModel(String wsdlUrl) throws Exception { wsdlReader.setFeature("javax.wsdl.verbose", false); Definition def = wsdlReader.readWSDL(new CatalogWSDLLocator(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; @@ -168,9 +167,8 @@ private 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); diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/HttpHandlerImplTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/HttpHandlerImplTest.java index 792af94fd47..f094851574a 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/HttpHandlerImplTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/HttpHandlerImplTest.java @@ -23,25 +23,24 @@ import jakarta.xml.ws.spi.http.HttpExchange; import jakarta.xml.ws.spi.http.HttpHandler; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.After; import org.junit.Before; import org.junit.Test; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; + public class HttpHandlerImplTest { - private IMocksControl control; private HttpHandler handler; private JAXWSHttpSpiDestination destination; private HttpExchange exchange; @Before public void setUp() { - control = EasyMock.createNiceControl(); - destination = control.createMock(JAXWSHttpSpiDestination.class); + destination = mock(JAXWSHttpSpiDestination.class); handler = new HttpHandlerImpl(destination); - exchange = control.createMock(HttpExchange.class); + exchange = mock(HttpExchange.class); } @After @@ -49,18 +48,14 @@ public void tearDown() { exchange = null; handler = null; destination = null; - control = null; } @Test public void testHttpHandlerImpl() throws Exception { exchange.close(); - destination.doService(EasyMock.isA(HttpServletRequest.class), - EasyMock.isA(HttpServletResponse.class)); - control.replay(); - + destination.doService(isA(HttpServletRequest.class), + isA(HttpServletResponse.class)); handler.handle(exchange); - control.verify(); } } diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestinationTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestinationTest.java index e3a584d3d24..40aaebc6d4e 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestinationTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestinationTest.java @@ -32,23 +32,22 @@ import org.apache.cxf.transport.MessageObserver; import org.apache.cxf.transport.http.DestinationRegistryImpl; -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.easymock.EasyMock.isA; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class JAXWSHttpSpiDestinationTest { private static final String ADDRESS = "http://localhost:80/foo/bar"; private static final String CONTEXT_PATH = "/foo"; - private IMocksControl control; private Bus bus; private HttpContext context; private MessageObserver observer; @@ -56,12 +55,10 @@ public class JAXWSHttpSpiDestinationTest { @Before public void setUp() { - control = EasyMock.createNiceControl(); - bus = control.createMock(Bus.class); - bus.getExtension(org.apache.cxf.policy.PolicyDataEngine.class); - EasyMock.expectLastCall().andReturn(null).anyTimes(); - observer = control.createMock(MessageObserver.class); - context = control.createMock(HttpContext.class); + bus = mock(Bus.class); + when(bus.getExtension(org.apache.cxf.policy.PolicyDataEngine.class)).thenReturn(null); + observer = mock(MessageObserver.class); + context = mock(HttpContext.class); endpoint = new EndpointInfo(); endpoint.setAddress(ADDRESS); } @@ -75,7 +72,6 @@ public void tearDown() { @Test public void testCtor() throws Exception { - control.replay(); JAXWSHttpSpiDestination destination = new JAXWSHttpSpiDestination(bus, new DestinationRegistryImpl(), endpoint); @@ -89,7 +85,6 @@ public void testCtor() throws Exception { @Test public void testMessage() throws Exception { HttpExchange exchange = setUpExchange(); - control.replay(); JAXWSHttpSpiDestination destination = new JAXWSHttpSpiDestination(bus, new DestinationRegistryImpl(), endpoint); @@ -97,27 +92,23 @@ public void testMessage() throws Exception { destination.doService(new HttpServletRequestAdapter(exchange), new HttpServletResponseAdapter(exchange)); - - control.verify(); } private HttpExchange setUpExchange() throws Exception { - HttpExchange exchange = control.createMock(HttpExchange.class); - expect(exchange.getHttpContext()).andReturn(context).anyTimes(); - expect(exchange.getQueryString()).andReturn(null); - expect(exchange.getPathInfo()).andReturn(null); - expect(exchange.getRequestURI()).andReturn(CONTEXT_PATH); - expect(exchange.getContextPath()).andReturn(CONTEXT_PATH); + HttpExchange exchange = mock(HttpExchange.class); + when(exchange.getHttpContext()).thenReturn(context); + when(exchange.getQueryString()).thenReturn(null); + when(exchange.getPathInfo()).thenReturn(null); + when(exchange.getRequestURI()).thenReturn(CONTEXT_PATH); + when(exchange.getContextPath()).thenReturn(CONTEXT_PATH); Map> reqHeaders = new HashMap<>(); reqHeaders.put("Content-Type", Collections.singletonList("text/xml")); - expect(exchange.getRequestHeaders()).andReturn(reqHeaders).anyTimes(); - OutputStream responseBody = control.createMock(OutputStream.class); - responseBody.flush(); - EasyMock.expectLastCall(); - expect(exchange.getResponseBody()).andReturn(responseBody).anyTimes(); - observer.onMessage(isA(Message.class)); - EasyMock.expectLastCall(); + when(exchange.getRequestHeaders()).thenReturn(reqHeaders); + OutputStream responseBody = mock(OutputStream.class); + doNothing().when(responseBody).flush(); + when(exchange.getResponseBody()).thenReturn(responseBody); + doNothing().when(observer).onMessage(isA(Message.class)); return exchange; } diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiTransportFactoryTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiTransportFactoryTest.java index 49cff88ca27..2c8b1164c2e 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiTransportFactoryTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiTransportFactoryTest.java @@ -24,27 +24,26 @@ import org.apache.cxf.service.model.EndpointInfo; import org.apache.cxf.transport.Destination; -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.assertNotNull; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; public class JAXWSHttpSpiTransportFactoryTest { - private IMocksControl control; private HttpContext context; private JAXWSHttpSpiTransportFactory factory; private Bus bus; @Before public void setUp() { - control = EasyMock.createNiceControl(); - context = control.createMock(HttpContext.class); - bus = control.createMock(Bus.class); + context = mock(HttpContext.class); + bus = mock(Bus.class); factory = new JAXWSHttpSpiTransportFactory(context); } @@ -66,8 +65,7 @@ public void testGetDestination2() throws Exception { } public void getDestination(String endpointAddress) throws Exception { - context.setHandler(EasyMock.isA(HttpHandler.class)); - control.replay(); + doNothing().when(context).setHandler(isA(HttpHandler.class)); EndpointInfo endpoint = new EndpointInfo(); endpoint.setAddress(endpointAddress); @@ -78,7 +76,6 @@ public void getDestination(String endpointAddress) throws Exception { assertNotNull(destination.getAddress().getAddress()); assertEquals(endpointAddress, destination.getAddress().getAddress().getValue()); assertEquals(endpointAddress, endpoint.getAddress()); - control.verify(); } } \ No newline at end of file