Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions rt/ws/rm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,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>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,32 @@
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.ws.rm.v200702.Identifier;

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.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
*
*/
public class AbstractEndpointTest {

private IMocksControl control;
private RMEndpoint rme;

@Before
public void setUp() {
control = EasyMock.createNiceControl();
rme = control.createMock(RMEndpoint.class);
}

@After
public void tearDown() {
control.verify();
rme = mock(RMEndpoint.class);
}

@Test
public void testAccessors() {
Endpoint ae = control.createMock(Endpoint.class);
EasyMock.expect(rme.getApplicationEndpoint()).andReturn(ae);
RMManager mgr = control.createMock(RMManager.class);
EasyMock.expect(rme.getManager()).andReturn(mgr);
control.replay();
Endpoint ae = mock(Endpoint.class);
when(rme.getApplicationEndpoint()).thenReturn(ae);
RMManager mgr = mock(RMManager.class);
when(rme.getManager()).thenReturn(mgr);

AbstractEndpoint tested = new AbstractEndpoint(rme);
assertSame(rme, tested.getReliableEndpoint());
assertSame(ae, tested.getEndpoint());
Expand All @@ -64,15 +56,14 @@ public void testAccessors() {

@Test
public void testGenerateSequenceIdentifier() {
RMManager mgr = control.createMock(RMManager.class);
EasyMock.expect(rme.getManager()).andReturn(mgr);
SequenceIdentifierGenerator generator = control.createMock(SequenceIdentifierGenerator.class);
EasyMock.expect(mgr.getIdGenerator()).andReturn(generator);
Identifier id = control.createMock(Identifier.class);
EasyMock.expect(generator.generateSequenceIdentifier()).andReturn(id);
control.replay();
RMManager mgr = mock(RMManager.class);
when(rme.getManager()).thenReturn(mgr);
SequenceIdentifierGenerator generator = mock(SequenceIdentifierGenerator.class);
when(mgr.getIdGenerator()).thenReturn(generator);
Identifier id = mock(Identifier.class);
when(generator.generateSequenceIdentifier()).thenReturn(id);

AbstractEndpoint tested = new AbstractEndpoint(rme);
assertSame(id, tested.generateSequenceIdentifier());
control.verify();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,31 @@
import org.apache.cxf.ws.policy.AssertionInfoMap;
import org.apache.cxf.ws.policy.PolicyAssertion;

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.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
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 AbstractRMInterceptorTest {

private IMocksControl control;

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

@After
public void tearDown() {
control.verify();
}

@Test
public void testAccessors() {
RMInterceptor interceptor = new RMInterceptor();
assertEquals(Phase.PRE_LOGICAL, interceptor.getPhase());
Bus bus = control.createMock(Bus.class);
RMManager busMgr = control.createMock(RMManager.class);
EasyMock.expect(bus.getExtension(RMManager.class)).andReturn(busMgr);
RMManager mgr = control.createMock(RMManager.class);
Bus bus = mock(Bus.class);
RMManager busMgr = mock(RMManager.class);
when(bus.getExtension(RMManager.class)).thenReturn(busMgr);
RMManager mgr = mock(RMManager.class);

control.replay();
assertNull(interceptor.getBus());
interceptor.setBus(bus);
assertSame(bus, interceptor.getBus());
Expand All @@ -83,15 +69,15 @@ public void testAccessors() {
@Test
public void testHandleMessageSequenceFaultNoBinding() {
RMInterceptor interceptor = new RMInterceptor();
Message message = control.createMock(Message.class);
SequenceFault sf = control.createMock(SequenceFault.class);
Message message = mock(Message.class);
SequenceFault sf = mock(SequenceFault.class);
interceptor.setSequenceFault(sf);
Exchange ex = control.createMock(Exchange.class);
EasyMock.expect(message.getExchange()).andReturn(ex).anyTimes();
Endpoint e = control.createMock(Endpoint.class);
EasyMock.expect(ex.getEndpoint()).andReturn(e);
EasyMock.expect(e.getBinding()).andReturn(null);
control.replay();
Exchange ex = mock(Exchange.class);
when(message.getExchange()).thenReturn(ex);
Endpoint e = mock(Endpoint.class);
when(ex.getEndpoint()).thenReturn(e);
when(e.getBinding()).thenReturn(null);

try {
interceptor.handleMessage(message);
fail("Expected Fault not thrown.");
Expand All @@ -103,23 +89,23 @@ public void testHandleMessageSequenceFaultNoBinding() {
@Test
public void testHandleMessageSequenceFault() {
RMInterceptor interceptor = new RMInterceptor();
Message message = control.createMock(Message.class);
SequenceFault sf = control.createMock(SequenceFault.class);
Message message = mock(Message.class);
SequenceFault sf = mock(SequenceFault.class);
interceptor.setSequenceFault(sf);
Exchange ex = control.createMock(Exchange.class);
EasyMock.expect(message.getExchange()).andReturn(ex).anyTimes();
Endpoint e = control.createMock(Endpoint.class);
EasyMock.expect(ex.getEndpoint()).andReturn(e);
Binding b = control.createMock(Binding.class);
EasyMock.expect(e.getBinding()).andReturn(b);
RMManager mgr = control.createMock(RMManager.class);
Exchange ex = mock(Exchange.class);
when(message.getExchange()).thenReturn(ex);
Endpoint e = mock(Endpoint.class);
when(ex.getEndpoint()).thenReturn(e);
Binding b = mock(Binding.class);
when(e.getBinding()).thenReturn(b);
RMManager mgr = mock(RMManager.class);
interceptor.setManager(mgr);
BindingFaultFactory bff = control.createMock(BindingFaultFactory.class);
EasyMock.expect(mgr.getBindingFaultFactory(b)).andReturn(bff);
Fault fault = control.createMock(Fault.class);
EasyMock.expect(bff.createFault(sf, message)).andReturn(fault);
EasyMock.expect(bff.toString(fault)).andReturn("f");
control.replay();
BindingFaultFactory bff = mock(BindingFaultFactory.class);
when(mgr.getBindingFaultFactory(b)).thenReturn(bff);
Fault fault = mock(Fault.class);
when(bff.createFault(sf, message)).thenReturn(fault);
when(bff.toString(fault)).thenReturn("f");

try {
interceptor.handleMessage(message);
fail("Expected Fault not thrown.");
Expand All @@ -131,10 +117,10 @@ public void testHandleMessageSequenceFault() {
@Test
public void testHandleMessageRMException() {
RMInterceptor interceptor = new RMInterceptor();
Message message = control.createMock(Message.class);
RMException rme = control.createMock(RMException.class);
Message message = mock(Message.class);
RMException rme = mock(RMException.class);
interceptor.setRMException(rme);
control.replay();

try {
interceptor.handleMessage(message);
fail("Expected Fault not thrown.");
Expand All @@ -146,23 +132,25 @@ public void testHandleMessageRMException() {
@Test
public void testAssertReliability() {
RMInterceptor interceptor = new RMInterceptor();
Message message = control.createMock(Message.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
AssertionInfoMap aim = control.createMock(AssertionInfoMap.class);
Message message = mock(Message.class);
when(message.get(AssertionInfoMap.class)).thenReturn(null);
AssertionInfoMap aim = mock(AssertionInfoMap.class);
Collection<AssertionInfo> ais = new ArrayList<>();
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).times(2);
PolicyAssertion a = control.createMock(PolicyAssertion.class);
when(message.get(AssertionInfoMap.class)).thenReturn(aim);
PolicyAssertion a = mock(PolicyAssertion.class);
AssertionInfo ai = new AssertionInfo(a);
EasyMock.expectLastCall();
control.replay();

interceptor.assertReliability(message);
assertFalse(ai.isAsserted());
aim.put(RM10Constants.RMASSERTION_QNAME, ais);
interceptor.assertReliability(message);
assertFalse(ai.isAsserted());
verify(message, times(2)).get(AssertionInfoMap.class);

ais.add(ai);
interceptor.assertReliability(message);

verify(message, times(3)).get(AssertionInfoMap.class);
}

class RMInterceptor extends AbstractRMInterceptor<Message> {
Expand Down
Loading