diff --git a/rt/management/pom.xml b/rt/management/pom.xml
index 9bf24b7b565..472d3bd9a34 100644
--- a/rt/management/pom.xml
+++ b/rt/management/pom.xml
@@ -81,8 +81,9 @@
test
- org.easymock
- easymock
+ org.mockito
+ mockito-core
+ ${cxf.mockito.version}
test
diff --git a/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java b/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
index 97494f14152..2e97f313caf 100644
--- a/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
+++ b/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
@@ -28,12 +28,17 @@
import org.apache.cxf.management.InstrumentationManager;
import org.apache.cxf.message.Message;
-import org.easymock.EasyMock;
+import org.junit.After;
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.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class CounterRepositoryTest {
private Bus bus;
@@ -52,31 +57,33 @@ public void setUp() throws Exception {
serviceCounter = new ObjectName("tandoori:type=counter,service=help");
operationCounter = new ObjectName("tandoori:type=counter,service=help,operation=me");
- bus = EasyMock.createMock(Bus.class);
- EasyMock.expect(bus.getInInterceptors()).andReturn(inlist).anyTimes();
- EasyMock.expect(bus.getOutInterceptors()).andReturn(outlist).anyTimes();
- EasyMock.expect(bus.getOutFaultInterceptors()).andReturn(faultlist).anyTimes();
- bus.getExtension(InstrumentationManager.class);
- EasyMock.expectLastCall().andReturn(null).anyTimes();
+ bus = mock(Bus.class);
+ when(bus.getInInterceptors()).thenReturn(inlist);
+ when(bus.getOutInterceptors()).thenReturn(outlist);
+ when(bus.getOutFaultInterceptors()).thenReturn(faultlist);
+ when(bus.getExtension(InstrumentationManager.class)).thenReturn(null);
cr = new CounterRepository();
- bus.setExtension(cr, CounterRepository.class);
- EasyMock.expectLastCall().once();
+ doNothing().when(bus).setExtension(cr, CounterRepository.class);
- EasyMock.replay(bus);
cr.setBus(bus);
}
+ @After
+ public void tearDown() {
+ verify(bus, times(1)).setExtension(cr, CounterRepository.class);
+ }
+
@Test
public void testIncreaseOneWayResponseCounter() throws Exception {
//cr.createCounter(operationCounter, true);
- MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- EasyMock.expect(mhtr.isOneWay()).andReturn(true).anyTimes();
- EasyMock.expect(mhtr.getEndTime()).andReturn((long)100000000).anyTimes();
- EasyMock.expect(mhtr.getHandlingTime()).andReturn((long)1000).anyTimes();
- EasyMock.expect(mhtr.getFaultMode()).andReturn(null).anyTimes();
- EasyMock.replay(mhtr);
+ MessageHandlingTimeRecorder mhtr = mock(MessageHandlingTimeRecorder.class);
+ when(mhtr.isOneWay()).thenReturn(true);
+ when(mhtr.getEndTime()).thenReturn((long)100000000);
+ when(mhtr.getHandlingTime()).thenReturn((long)1000);
+ when(mhtr.getFaultMode()).thenReturn(null);
+
cr.increaseCounter(serviceCounter, mhtr);
cr.increaseCounter(operationCounter, mhtr);
ResponseTimeCounter opCounter = (ResponseTimeCounter) cr.getCounter(operationCounter);
@@ -86,18 +93,17 @@ public void testIncreaseOneWayResponseCounter() throws Exception {
assertEquals("The Service counter isn't increased", sCounter.getNumInvocations(), 1);
verifyBus();
- EasyMock.verify(mhtr);
}
@Test
public void testIncreaseOneWayNoResponseCounter() throws Exception {
//cr.createCounter(operationCounter, true);
- MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- EasyMock.expect(mhtr.isOneWay()).andReturn(true).anyTimes();
- EasyMock.expect(mhtr.getEndTime()).andReturn((long)0).anyTimes();
- EasyMock.expect(mhtr.getFaultMode()).andReturn(null).anyTimes();
- EasyMock.replay(mhtr);
+ MessageHandlingTimeRecorder mhtr = mock(MessageHandlingTimeRecorder.class);
+ when(mhtr.isOneWay()).thenReturn(true);
+ when(mhtr.getEndTime()).thenReturn((long)0);
+ when(mhtr.getFaultMode()).thenReturn(null);
+
cr.increaseCounter(serviceCounter, mhtr);
cr.increaseCounter(operationCounter, mhtr);
ResponseTimeCounter opCounter = (ResponseTimeCounter) cr.getCounter(operationCounter);
@@ -107,17 +113,16 @@ public void testIncreaseOneWayNoResponseCounter() throws Exception {
assertEquals("The Service counter isn't increased", sCounter.getNumInvocations(), 1);
verifyBus();
- EasyMock.verify(mhtr);
}
@Test
public void testIncreaseResponseCounter() throws Exception {
- MessageHandlingTimeRecorder mhtr1 = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- EasyMock.expect(mhtr1.isOneWay()).andReturn(false).anyTimes();
- EasyMock.expect(mhtr1.getHandlingTime()).andReturn((long)1000).anyTimes();
- EasyMock.expect(mhtr1.getFaultMode()).andReturn(null).anyTimes();
- EasyMock.replay(mhtr1);
+ MessageHandlingTimeRecorder mhtr1 = mock(MessageHandlingTimeRecorder.class);
+ when(mhtr1.isOneWay()).thenReturn(false);
+ when(mhtr1.getHandlingTime()).thenReturn((long)1000);
+ when(mhtr1.getFaultMode()).thenReturn(null);
+
cr.createCounter(operationCounter);
cr.increaseCounter(serviceCounter, mhtr1);
cr.increaseCounter(operationCounter, mhtr1);
@@ -133,11 +138,11 @@ public void testIncreaseResponseCounter() throws Exception {
opCounter.getMinResponseTime(), (long)1000);
assertEquals("The Service counter isn't increased", sCounter.getNumInvocations(), 1);
- MessageHandlingTimeRecorder mhtr2 = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- EasyMock.expect(mhtr2.isOneWay()).andReturn(false).anyTimes();
- EasyMock.expect(mhtr2.getHandlingTime()).andReturn((long)2000).anyTimes();
- EasyMock.expect(mhtr2.getFaultMode()).andReturn(null).anyTimes();
- EasyMock.replay(mhtr2);
+ MessageHandlingTimeRecorder mhtr2 = mock(MessageHandlingTimeRecorder.class);
+ when(mhtr2.isOneWay()).thenReturn(false);
+ when(mhtr2.getHandlingTime()).thenReturn((long)2000);
+ when(mhtr2.getFaultMode()).thenReturn(null);
+
cr.increaseCounter(serviceCounter, mhtr2);
cr.increaseCounter(operationCounter, mhtr2);
assertEquals("The operation counter isn't increased", opCounter.getNumInvocations(), 2);
@@ -161,14 +166,10 @@ public void testIncreaseResponseCounter() throws Exception {
assertTrue(opCounter.getAvgResponseTime().intValue() == 0);
verifyBus();
- EasyMock.verify(mhtr1);
- EasyMock.verify(mhtr2);
}
private void verifyBus() {
- EasyMock.verify(bus);
-
// the numbers should match the implementation of CounterRepository
assertEquals(2, inlist.size());
assertEquals(1, outlist.size());
diff --git a/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java b/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
index 3023d2f1249..a76ab1cb086 100644
--- a/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
+++ b/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
@@ -34,9 +34,14 @@
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.service.model.OperationInfo;
-import org.easymock.EasyMock;
import org.junit.Before;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+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 AbstractMessageResponseTestBase {
protected static final QName SERVICE_NAME = new QName("http://org.apache.cxf", "hello");
@@ -63,10 +68,10 @@ public class AbstractMessageResponseTestBase {
@Before
public void setUp() throws Exception {
- message = EasyMock.createMock(Message.class);
- exchange = EasyMock.createMock(Exchange.class);
- bus = EasyMock.createMock(Bus.class);
- cRepository = EasyMock.createMock(CounterRepository.class);
+ message = mock(Message.class);
+ exchange = mock(Exchange.class);
+ bus = mock(Bus.class);
+ cRepository = mock(CounterRepository.class);
clientServiceCounterOName = new ObjectName(CLIENT_SERVICE_ONAME);
serverServiceCounterOName = new ObjectName(SERVER_SERVICE_ONAME);
clientOperationCounterOName = new ObjectName(CLIENT_SERVICE_ONAME
@@ -86,59 +91,49 @@ protected void setupCounterRepository(boolean increase, boolean isClient) {
operationCounterOName = serverOperationCounterOName;
}
BusFactory.setDefaultBus(bus);
- bus.getExtension(CounterRepository.class);
- EasyMock.expectLastCall().andReturn(cRepository).anyTimes();
+ when(bus.getExtension(CounterRepository.class)).thenReturn(cRepository);
if (increase) {
- EasyMock.expect(bus.getId()).andReturn(Bus.DEFAULT_BUS_ID).anyTimes();
- cRepository.increaseCounter(EasyMock.eq(serviceCounterOName),
- EasyMock.isA(MessageHandlingTimeRecorder.class));
- EasyMock.expectLastCall();
- cRepository.increaseCounter(EasyMock.eq(operationCounterOName),
- EasyMock.isA(MessageHandlingTimeRecorder.class));
- EasyMock.expectLastCall();
- EasyMock.expect(cRepository.getCounter(EasyMock.isA(ObjectName.class))).andReturn(null);
- EasyMock.replay(cRepository);
+ when(bus.getId()).thenReturn(Bus.DEFAULT_BUS_ID);
+ doNothing().when(cRepository).increaseCounter(eq(serviceCounterOName),
+ isA(MessageHandlingTimeRecorder.class));
+
+ doNothing().when(cRepository).increaseCounter(eq(operationCounterOName),
+ isA(MessageHandlingTimeRecorder.class));
+
+ when(cRepository.getCounter(any(ObjectName.class))).thenReturn(null);
}
- EasyMock.replay(bus);
// increase the number
}
protected void setupExchangeForMessage() {
- EasyMock.expect(exchange.getBus()).andReturn(bus).anyTimes();
-
- Service service = EasyMock.createMock(Service.class);
- EasyMock.expect(service.getName()).andReturn(SERVICE_NAME).anyTimes();
- EasyMock.expect(exchange.getService()).andReturn(service).anyTimes();
- EasyMock.replay(service);
+ when(exchange.getBus()).thenReturn(bus);
- Endpoint endpoint = EasyMock.createMock(Endpoint.class);
- EndpointInfo endpointInfo = EasyMock.createMock(EndpointInfo.class);
- EasyMock.expect(endpointInfo.getName()).andReturn(PORT_NAME).anyTimes();
- EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
- EasyMock.expect(endpoint.get("javax.management.ObjectName")).andReturn(null).anyTimes();
- EasyMock.expect(endpoint.put(EasyMock.eq("javax.management.ObjectName"), EasyMock.anyObject(ObjectName.class)))
- .andReturn(null).anyTimes();
- EasyMock.expect(exchange.getEndpoint()).andReturn(endpoint).anyTimes();
- EasyMock.replay(endpointInfo);
- EasyMock.replay(endpoint);
+ Service service = mock(Service.class);
+ when(service.getName()).thenReturn(SERVICE_NAME);
+ when(exchange.getService()).thenReturn(service);
+ Endpoint endpoint = mock(Endpoint.class);
+ EndpointInfo endpointInfo = mock(EndpointInfo.class);
+ when(endpointInfo.getName()).thenReturn(PORT_NAME);
+ when(endpoint.getEndpointInfo()).thenReturn(endpointInfo);
+ when(endpoint.get("javax.management.ObjectName")).thenReturn(null);
+ when(endpoint.put(eq("javax.management.ObjectName"), any(ObjectName.class))).thenReturn(null);
+ when(exchange.getEndpoint()).thenReturn(endpoint);
//EasyMock.expect(exchange.getBus()).andReturn(bus);
- EasyMock.expect(exchange.get("org.apache.cxf.management.service.counter.name")).andReturn(null).anyTimes();
+ when(exchange.get("org.apache.cxf.management.service.counter.name")).thenReturn(null);
}
protected void setupOperationForMessage() {
- OperationInfo op = EasyMock.createMock(OperationInfo.class);
- BindingOperationInfo bop = EasyMock.createMock(BindingOperationInfo.class);
- EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(bop);
- EasyMock.expect(bop.getOperationInfo()).andReturn(op);
- EasyMock.expect(op.getName()).andReturn(OPERATION_NAME);
- EasyMock.expect(op.getProperty("javax.management.ObjectName", ObjectName.class)).andReturn(null).anyTimes();
- op.setProperty(EasyMock.eq("javax.management.ObjectName"),
- EasyMock.anyObject(ObjectName.class));
- EasyMock.expectLastCall();
- EasyMock.replay(bop, op);
+ OperationInfo op = mock(OperationInfo.class);
+ BindingOperationInfo bop = mock(BindingOperationInfo.class);
+ when(exchange.getBindingOperationInfo()).thenReturn(bop);
+ when(bop.getOperationInfo()).thenReturn(op);
+ when(op.getName()).thenReturn(OPERATION_NAME);
+ when(op.getProperty("javax.management.ObjectName", ObjectName.class)).thenReturn(null);
+ doNothing().when(op).setProperty(eq("javax.management.ObjectName"),
+ any(ObjectName.class));
}
}
diff --git a/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java b/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java
index 1b360eb0266..1332b66bc09 100644
--- a/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java
+++ b/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java
@@ -24,11 +24,17 @@
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
-import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class ResponseTimeMessageInInterceptorTest extends AbstractMessageResponseTestBase {
@@ -41,31 +47,22 @@ public void testClientMessageIn() {
setupCounterRepository(true, true);
setupOperationForMessage();
setupExchangeForMessage();
- EasyMock.expect(message.getExchange()).andReturn(exchange);
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
- EasyMock.expect(exchange.getOutMessage()).andReturn(message).anyTimes();
- EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(null);
-
- EasyMock.expect(exchange.get(FaultMode.class)).andReturn(null);
- EasyMock.expect(exchange.isOneWay()).andReturn(false);
- MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- mhtr.endHandling();
- EasyMock.expectLastCall();
- mhtr.setFaultMode(null);
- EasyMock.expectLastCall();
-
- EasyMock.replay(mhtr);
- EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
- EasyMock.replay(exchange);
- EasyMock.replay(message);
+ when(message.getExchange()).thenReturn(exchange);
+ when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.TRUE);
+ when(exchange.getOutMessage()).thenReturn(message);
+ when(exchange.get("org.apache.cxf.management.counter.enabled")).thenReturn(null);
- rtmii.handleMessage(message);
- EasyMock.verify(message);
- EasyMock.verify(bus);
- EasyMock.verify(exchange);
- EasyMock.verify(mhtr);
- EasyMock.verify(cRepository);
+ when(exchange.get(FaultMode.class)).thenReturn(null);
+ when(exchange.isOneWay()).thenReturn(false);
+ MessageHandlingTimeRecorder mhtr = mock(MessageHandlingTimeRecorder.class);
+ doNothing().when(mhtr).endHandling();
+ doNothing().when(mhtr).setFaultMode(null);
+
+ when(exchange.get(MessageHandlingTimeRecorder.class)).thenReturn(mhtr);
+ rtmii.handleMessage(message);
+ verify(mhtr, atLeastOnce()).endHandling();
+ verify(mhtr, atLeastOnce()).setFaultMode(null);
}
@Test
@@ -93,31 +90,24 @@ public void testClientFaultMessageIn(FaultMode faultMode) {
setupCounterRepository(true, true);
setupExchangeForMessage();
setupOperationForMessage();
- EasyMock.expect(message.getExchange()).andReturn(exchange);
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
- EasyMock.expect(exchange.isOneWay()).andReturn(false);
- EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(true);
- exchange.put(FaultMode.class, faultMode);
- EasyMock.expectLastCall();
- EasyMock.expect(message.get(FaultMode.class)).andReturn(faultMode).anyTimes();
- EasyMock.expect(exchange.get(FaultMode.class)).andReturn(faultMode).anyTimes();
- EasyMock.expect(exchange.getOutMessage()).andReturn(message);
- MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- mhtr.endHandling();
- EasyMock.expectLastCall();
- mhtr.setFaultMode(faultMode);
- EasyMock.expectLastCall();
-
- EasyMock.replay(mhtr);
- EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
- EasyMock.replay(exchange);
- EasyMock.replay(message);
+ when(message.getExchange()).thenReturn(exchange);
+ when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.TRUE);
+ when(exchange.isOneWay()).thenReturn(false);
+ when(exchange.get("org.apache.cxf.management.counter.enabled")).thenReturn(true);
+ doNothing().when(exchange).put(FaultMode.class, faultMode);
+ when(message.get(FaultMode.class)).thenReturn(faultMode);
+ when(exchange.get(FaultMode.class)).thenReturn(faultMode);
+ when(exchange.getOutMessage()).thenReturn(message);
+ MessageHandlingTimeRecorder mhtr = mock(MessageHandlingTimeRecorder.class);
+ doNothing().when(mhtr).endHandling();
+ doNothing().when(mhtr).setFaultMode(faultMode);
+
+ when(exchange.get(MessageHandlingTimeRecorder.class)).thenReturn(mhtr);
rtmoi.handleFault(message);
- EasyMock.verify(message);
- EasyMock.verify(bus);
- EasyMock.verify(exchange);
- EasyMock.verify(mhtr);
+ verify(exchange, atLeastOnce()).put(FaultMode.class, faultMode);
+ verify(mhtr, atLeastOnce()).endHandling();
+ verify(mhtr, atLeastOnce()).setFaultMode(faultMode);
}
@@ -127,44 +117,36 @@ public void testServerOneWayMessageIn() {
// need to increase the counter and is not a client
setupCounterRepository(true, false);
setupExchangeForMessage();
- EasyMock.expect(message.getExchange()).andReturn(exchange);
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
- EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(null);
- EasyMock.expect(exchange.getOutMessage()).andReturn(message);
- MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- mhtr.beginHandling();
- EasyMock.expectLastCall();
-
- EasyMock.replay(mhtr);
- EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
-
-
- EasyMock.replay(exchange);
- EasyMock.replay(message);
-
+ when(message.getExchange()).thenReturn(exchange);
+ when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.FALSE);
+ when(exchange.get("org.apache.cxf.management.counter.enabled")).thenReturn(null);
+ when(exchange.getOutMessage()).thenReturn(message);
+ MessageHandlingTimeRecorder mhtr = mock(MessageHandlingTimeRecorder.class);
+ doNothing().when(mhtr).beginHandling();
+
+ when(exchange.get(MessageHandlingTimeRecorder.class)).thenReturn(mhtr);
rtmii.handleMessage(message);
- EasyMock.verify(message);
- EasyMock.verify(exchange);
- EasyMock.verify(mhtr);
+
+ verify(mhtr, atLeastOnce()).beginHandling();
}
@Test
public void testServiceMessageIn() {
setupCounterRepository(true, false);
setupExchangeForMessage();
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
- EasyMock.expect(message.getExchange()).andReturn(exchange);
- EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(null);
- EasyMock.expect(exchange.getOutMessage()).andReturn(message);
- EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(null);
- exchange.put(EasyMock.eq(MessageHandlingTimeRecorder.class),
- EasyMock.isA(MessageHandlingTimeRecorder.class));
- EasyMock.replay(exchange);
- EasyMock.replay(message);
+ when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.FALSE);
+ when(message.getExchange()).thenReturn(exchange);
+ when(exchange.get("org.apache.cxf.management.counter.enabled")).thenReturn(null);
+ when(exchange.getOutMessage()).thenReturn(message);
+ when(exchange.get(MessageHandlingTimeRecorder.class)).thenReturn(null);
+
+ doNothing().when(exchange).put(eq(MessageHandlingTimeRecorder.class),
+ isA(MessageHandlingTimeRecorder.class));
+
rtmii.handleMessage(message);
- EasyMock.verify(message);
- EasyMock.verify(exchange);
+ verify(exchange, atLeastOnce()).put(eq(MessageHandlingTimeRecorder.class),
+ isA(MessageHandlingTimeRecorder.class));
}
@Test
diff --git a/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java b/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java
index 06317e187a4..afbe32d89bc 100644
--- a/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java
+++ b/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java
@@ -22,9 +22,14 @@
import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
import org.apache.cxf.message.Message;
-import org.easymock.EasyMock;
import org.junit.Test;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
public class ResponseTimeMessageInvokerInterceptorTest extends AbstractMessageResponseTestBase {
private ResponseTimeMessageInvokerInterceptor invokerInterceptor =
@@ -38,25 +43,18 @@ public void testServerOneWayMessageIn() {
setupCounterRepository(true, false);
setupExchangeForMessage();
setupOperationForMessage();
- EasyMock.expect(message.getExchange()).andReturn(exchange);
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
- EasyMock.expect(exchange.getOutMessage()).andReturn(message);
- MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- mhtr.setOneWay(true);
- EasyMock.expectLastCall();
- mhtr.endHandling();
- EasyMock.expectLastCall();
-
- EasyMock.replay(mhtr);
- EasyMock.expect(exchange.isOneWay()).andReturn(true);
- EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
- EasyMock.replay(exchange);
- EasyMock.replay(message);
+ when(message.getExchange()).thenReturn(exchange);
+ when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.FALSE);
+ when(exchange.getOutMessage()).thenReturn(message);
+ MessageHandlingTimeRecorder mhtr = mock(MessageHandlingTimeRecorder.class);
+ doNothing().when(mhtr).setOneWay(true);
+ doNothing().when(mhtr).endHandling();
+
+ when(exchange.isOneWay()).thenReturn(true);
+ when(exchange.get(MessageHandlingTimeRecorder.class)).thenReturn(mhtr);
rtmii.handleMessage(message);
- EasyMock.verify(message);
- EasyMock.verify(bus);
- EasyMock.verify(exchange);
- EasyMock.verify(mhtr);
+ verify(mhtr, atLeastOnce()).setOneWay(true);
+ verify(mhtr, atLeastOnce()).endHandling();
}
}
diff --git a/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java b/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java
index 7ea8a241f42..4ee64aa1722 100644
--- a/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java
+++ b/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java
@@ -24,9 +24,15 @@
import org.apache.cxf.message.FaultMode;
import org.apache.cxf.message.Message;
-import org.easymock.EasyMock;
import org.junit.Test;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
public class ResponseTimeMessageOutInterceptorTest extends AbstractMessageResponseTestBase {
private ResponseTimeMessageOutInterceptor rtmoi = new ResponseTimeMessageOutInterceptor();
@@ -36,28 +42,22 @@ public void testServerMessageOut() {
setupCounterRepository(true, false);
setupExchangeForMessage();
setupOperationForMessage();
- EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE).anyTimes();
- EasyMock.expect(message.getExchange()).andReturn(exchange);
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
- EasyMock.expect(exchange.getOutMessage()).andReturn(message).anyTimes();
- EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(null);
- EasyMock.expect(exchange.get(Exception.class)).andReturn(null);
- EasyMock.expect(exchange.get(FaultMode.class)).andReturn(null);
- MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- mhtr.endHandling();
- EasyMock.expectLastCall();
- mhtr.setFaultMode(null);
- EasyMock.expectLastCall();
- EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr).anyTimes();
- EasyMock.replay(mhtr);
- EasyMock.replay(exchange);
- EasyMock.replay(message);
+ when(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn(Boolean.FALSE);
+ when(message.getExchange()).thenReturn(exchange);
+ when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.FALSE);
+ when(exchange.getOutMessage()).thenReturn(message);
+ when(exchange.get("org.apache.cxf.management.counter.enabled")).thenReturn(null);
+ when(exchange.get(Exception.class)).thenReturn(null);
+ when(exchange.get(FaultMode.class)).thenReturn(null);
+ MessageHandlingTimeRecorder mhtr = mock(MessageHandlingTimeRecorder.class);
+ doNothing().when(mhtr).endHandling();
+ doNothing().when(mhtr).setFaultMode(null);
+
+ when(exchange.get(MessageHandlingTimeRecorder.class)).thenReturn(mhtr);
rtmoi.handleMessage(message);
- EasyMock.verify(message);
- EasyMock.verify(bus);
- EasyMock.verify(exchange);
- EasyMock.verify(mhtr);
+ verify(mhtr, atLeastOnce()).endHandling();
+ verify(mhtr, atLeastOnce()).setFaultMode(null);
}
@Test
@@ -84,24 +84,13 @@ public void testServerFaultMessageOut(FaultMode faultMode) {
// need to increase the counter and is not a client
setupCounterRepository(true, false);
setupExchangeForMessage();
- EasyMock.expect(message.getExchange()).andReturn(exchange);
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
- EasyMock.expect(message.get(FaultMode.class)).andReturn(faultMode).anyTimes();
- EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(null);
- EasyMock.expectLastCall();
- EasyMock.expect(exchange.get(FaultMode.class)).andReturn(faultMode).anyTimes();
- MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
-
- EasyMock.replay(mhtr);
- //EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
- EasyMock.replay(exchange);
- EasyMock.replay(message);
+ when(message.getExchange()).thenReturn(exchange);
+ when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.FALSE);
+ when(message.get(FaultMode.class)).thenReturn(faultMode);
+ when(exchange.get("org.apache.cxf.management.counter.enabled")).thenReturn(null);
+ when(exchange.get(FaultMode.class)).thenReturn(faultMode);
rtmoi.handleFault(message);
- EasyMock.verify(message);
- EasyMock.verify(bus);
- EasyMock.verify(exchange);
- EasyMock.verify(mhtr);
}
@Test
@@ -110,43 +99,34 @@ public void testClientOneWayMessageOut() {
setupCounterRepository(true, true);
setupExchangeForMessage();
setupOperationForMessage();
- EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
- EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE).anyTimes();
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
- EasyMock.expect(exchange.getOutMessage()).andReturn(message).anyTimes();
- EasyMock.expect(exchange.get(FaultMode.class)).andReturn(null);
- EasyMock.expect(exchange.get(Exception.class)).andReturn(null);
- EasyMock.expect(exchange.isOneWay()).andReturn(true).anyTimes();
- MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
- EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr).anyTimes();
- EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(null);
-
- InterceptorChain chain = EasyMock.createMock(InterceptorChain.class);
- EasyMock.expect(message.getInterceptorChain()).andReturn(chain);
- chain.add(EasyMock.isA(ResponseTimeMessageOutInterceptor.EndingInterceptor.class));
- EasyMock.expectLastCall();
- EasyMock.replay(exchange);
- EasyMock.replay(message);
+ when(message.getExchange()).thenReturn(exchange);
+ when(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn(Boolean.FALSE);
+ when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.TRUE);
+ when(exchange.getOutMessage()).thenReturn(message);
+ when(exchange.get(FaultMode.class)).thenReturn(null);
+ when(exchange.get(Exception.class)).thenReturn(null);
+ when(exchange.isOneWay()).thenReturn(true);
+ MessageHandlingTimeRecorder mhtr = mock(MessageHandlingTimeRecorder.class);
+ when(exchange.get(MessageHandlingTimeRecorder.class)).thenReturn(mhtr);
+ when(exchange.get("org.apache.cxf.management.counter.enabled")).thenReturn(null);
+
+ InterceptorChain chain = mock(InterceptorChain.class);
+ when(message.getInterceptorChain()).thenReturn(chain);
+ doNothing().when(chain).add(isA(ResponseTimeMessageOutInterceptor.EndingInterceptor.class));
rtmoi.handleMessage(message);
rtmoi.getEndingInterceptor().handleMessage(message);
- EasyMock.verify(message);
- EasyMock.verify(bus);
- EasyMock.verify(exchange);
+ verify(chain, atLeastOnce()).add(isA(ResponseTimeMessageOutInterceptor.EndingInterceptor.class));
}
@Test
public void testClientMessageOut() {
- EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE).anyTimes();
- EasyMock.expect(message.getExchange()).andReturn(exchange);
- EasyMock.expect(exchange.getBus()).andReturn(bus);
- EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(null);
- EasyMock.replay(exchange);
- EasyMock.replay(message);
- rtmoi.handleMessage(message);
- EasyMock.verify(message);
- EasyMock.verify(exchange);
+ when(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn(Boolean.FALSE);
+ when(message.getExchange()).thenReturn(exchange);
+ when(exchange.getBus()).thenReturn(bus);
+ when(exchange.get("org.apache.cxf.management.counter.enabled")).thenReturn(null);
+ rtmoi.handleMessage(message);
}
}