Skip to content
Open
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
10 changes: 0 additions & 10 deletions activemq-kahadb-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,6 @@
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-legacy</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
9 changes: 2 additions & 7 deletions activemq-ra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-legacy</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.*;

import java.lang.reflect.Method;

Expand All @@ -26,31 +28,23 @@
import jakarta.resource.ResourceException;
import jakarta.resource.spi.endpoint.MessageEndpoint;

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

@Ignore
@RunWith(JMock.class)
public class MessageEndpointProxyTest {

private MessageEndpoint mockEndpoint;
private EndpointAndListener mockEndpointAndListener;
private Message stubMessage;
private MessageEndpointProxy endpointProxy;
private Mockery context;

@Before
public void setUp() {
context = new Mockery();
mockEndpoint = context.mock(MessageEndpoint.class);
context.mock(MessageListener.class);
mockEndpointAndListener = context.mock(EndpointAndListener.class);
stubMessage = context.mock(Message.class);
mockEndpoint = mock(MessageEndpoint.class);
mockEndpointAndListener = mock(EndpointAndListener.class);
stubMessage = mock(Message.class);
endpointProxy = new MessageEndpointProxy(mockEndpointAndListener);
}

Expand All @@ -66,27 +60,14 @@ public void testInvalidConstruction() {

@Test(timeout = 60000)
public void testSuccessfulCallSequence() throws Exception {
setupBeforeDeliverySuccessful();
setupOnMessageSuccessful();
setupAfterDeliverySuccessful();

doBeforeDeliveryExpectSuccess();
doOnMessageExpectSuccess();
doAfterDeliveryExpectSuccess();
}

@Test(timeout = 60000)
public void testBeforeDeliveryFailure() throws Exception {
context.checking(new Expectations() {{
oneOf (mockEndpointAndListener).beforeDelivery(with(any(Method.class)));
will(throwException(new ResourceException()));
}});
context.checking(new Expectations() {{
never (mockEndpointAndListener).onMessage(null);
never (mockEndpointAndListener).afterDelivery();
}});

setupExpectRelease();
doThrow(new ResourceException()).when(mockEndpointAndListener).beforeDelivery(any(Method.class));

try {
endpointProxy.beforeDelivery(ActiveMQEndpointWorker.ON_MESSAGE_METHOD);
Expand All @@ -102,16 +83,10 @@ public void testBeforeDeliveryFailure() throws Exception {

@Test(timeout = 60000)
public void testOnMessageFailure() throws Exception {
setupBeforeDeliverySuccessful();

context.checking(new Expectations() {{
oneOf (mockEndpointAndListener).onMessage(with(same(stubMessage)));
will(throwException(new RuntimeException()));
}});
doBeforeDeliveryExpectSuccess();

setupAfterDeliverySuccessful();
doThrow(new RuntimeException()).when(mockEndpointAndListener).onMessage(same(stubMessage));

doBeforeDeliveryExpectSuccess();
try {
endpointProxy.onMessage(stubMessage);
fail("An exception should have been thrown");
Expand All @@ -124,17 +99,11 @@ public void testOnMessageFailure() throws Exception {

@Test(timeout = 60000)
public void testAfterDeliveryFailure() throws Exception {
setupBeforeDeliverySuccessful();
setupOnMessageSuccessful();

context.checking(new Expectations() {{
oneOf (mockEndpointAndListener).afterDelivery(); will(throwException(new ResourceException()));
}});

setupExpectRelease();

doBeforeDeliveryExpectSuccess();
doOnMessageExpectSuccess();

doThrow(new ResourceException()).when(mockEndpointAndListener).afterDelivery();

try {
endpointProxy.afterDelivery();
fail("An exception should have been thrown");
Expand All @@ -152,30 +121,6 @@ private void doFullyDeadCheck() {
doReleaseExpectInvalidMessageEndpointException();
}

private void setupAfterDeliverySuccessful() throws Exception {
context.checking(new Expectations() {{
oneOf (mockEndpointAndListener).afterDelivery();
}});
}

private void setupOnMessageSuccessful() {
context.checking(new Expectations() {{
oneOf (mockEndpointAndListener).onMessage(with(stubMessage));
}});
}

private void setupBeforeDeliverySuccessful() throws Exception {
context.checking(new Expectations() {{
oneOf (mockEndpointAndListener).beforeDelivery(with(any(Method.class)));
}});
}

private void setupExpectRelease() {
context.checking(new Expectations() {{
oneOf (mockEndpointAndListener).release();
}});
}

private void doBeforeDeliveryExpectSuccess() {
try {
endpointProxy.beforeDelivery(ActiveMQEndpointWorker.ON_MESSAGE_METHOD);
Expand Down
Loading