Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix npe in session #11

Merged
merged 2 commits into from
Apr 17, 2013
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<apollo-version>1.6</apollo-version>
<activemq-version>5.8.0</activemq-version>
<mvnplugins-version>1.15</mvnplugins-version>
<mockito.version>1.9.5</mockito.version>
</properties>

<url>http://${forge-project-id}.fusesource.org/</url>
Expand Down
14 changes: 7 additions & 7 deletions stompjms-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@
<scope>test</scope>
</dependency>

<!-- to enable the webconsole in the apollo broker -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>apollo-web</artifactId>
<version>${apollo-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId>
<version>7.1.6.v20100715</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.fusesource.stomp.jms;

import org.fusesource.hawtbuf.AsciiBuffer;
import org.fusesource.hawtbuf.Buffer;
import org.fusesource.hawtdispatch.CustomDispatchSource;
import org.fusesource.hawtdispatch.Dispatch;
import org.fusesource.hawtdispatch.OrderedEventAggregator;
Expand All @@ -29,8 +28,6 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import static org.fusesource.stomp.client.Constants.*;

/**
* implementation of a Jms Message Consumer
*/
Expand Down Expand Up @@ -231,7 +228,7 @@ StompJmsMessage ack(final StompJmsMessage message) {
if( message.getAcknowledgeCallback()!=null ) {
// Message has been received by the app.. expand the credit window
// so that we receive more messages.
StompFrame frame = session.serverAdaptor.createCreditFrame(this, message.getFrame());
StompFrame frame = session.channel.serverAdaptor.createCreditFrame(this, message.getFrame());
if( frame != null ) {
try {
session.channel.sendFrame(frame);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.fusesource.stomp.jms;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import javax.jms.Session;
import javax.jms.TemporaryQueue;
import javax.jms.TemporaryTopic;

import static org.junit.Assert.assertSame;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

/**
* @author zapodot at gmail dot com
*/
@RunWith(MockitoJUnitRunner.class)
public class StompJmsSessionUntransactedTest {

@Mock
private StompJmsConnection stompJmsConnection;

@Mock
private StompChannel stompChannel;

@Mock
private StompServerAdaptor stompServerAdaptor;

@Mock
private StompJmsPrefetch stompJmsPrefetch;

@Mock
private TemporaryQueue temporaryQueue;

@Mock
private TemporaryTopic temporaryTopic;
private StompJmsSession stompJmsSession;

@Before
public void setUp() throws Exception {
when(stompJmsConnection.createChannel(any(StompJmsSession.class))).thenReturn(stompChannel);
stompJmsConnection.prefetch = stompJmsPrefetch;

when(stompChannel.getServerAdaptor()).thenReturn(stompServerAdaptor);
when(stompServerAdaptor.createTemporaryQueue(any(StompJmsSession.class))).thenReturn(temporaryQueue);
when(stompServerAdaptor.createTemporaryTopic(any(StompJmsSession.class))).thenReturn(temporaryTopic);
stompJmsSession = new StompJmsSession(stompJmsConnection, Session.AUTO_ACKNOWLEDGE, false);

}

@Test
public void testCreateTemporaryQueue() throws Exception {
assertSame(temporaryQueue, stompJmsSession.createTemporaryQueue());
verify(stompJmsConnection).createChannel(any(StompJmsSession.class));
verify(stompChannel).getServerAdaptor();
verify(stompServerAdaptor).createTemporaryQueue(same(stompJmsSession));

}

@Test
public void testCreateTemporaryTopic() throws Exception {
assertSame(temporaryTopic, stompJmsSession.createTemporaryTopic());
verify(stompJmsConnection).createChannel(any(StompJmsSession.class));
verify(stompChannel).getServerAdaptor();
verify(stompServerAdaptor).createTemporaryTopic(same(stompJmsSession));
}

@After
public void tearDown() throws Exception {
verifyNoMoreInteractions(stompJmsConnection, stompChannel, stompServerAdaptor);

}
}