ACTIVEMQ6-55: add a test of the listener method throwing the NPE

This commit is contained in:
Robert Gemmell 2015-03-12 14:25:57 +00:00 committed by Clebert Suconic
parent 983effca9d
commit 7ef95ae977
2 changed files with 116 additions and 1 deletions

View File

@ -47,12 +47,13 @@ public abstract class AbstractConnectionContext extends ProtonInitializable impl
private final Map<Session, AbstractProtonSessionContext> sessions = new ConcurrentHashMap<>(); private final Map<Session, AbstractProtonSessionContext> sessions = new ConcurrentHashMap<>();
protected LocalListener listener = new LocalListener();
public AbstractConnectionContext(AMQPConnectionCallback connectionCallback) public AbstractConnectionContext(AMQPConnectionCallback connectionCallback)
{ {
this.connectionCallback = connectionCallback; this.connectionCallback = connectionCallback;
connectionCallback.setConnection(this); connectionCallback.setConnection(this);
handler.addEventHandler(new LocalListener()); handler.addEventHandler(listener);
} }
public SASLResult getSASLResult() public SASLResult getSASLResult()

View File

@ -0,0 +1,114 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.proton.plug.context;
import io.netty.buffer.ByteBuf;
import org.apache.qpid.proton.engine.Connection;
import org.apache.qpid.proton.engine.Link;
import org.apache.qpid.proton.engine.Session;
import org.junit.Test;
import org.proton.plug.AMQPConnectionCallback;
import org.proton.plug.AMQPConnectionContext;
import org.proton.plug.AMQPSessionCallback;
import org.proton.plug.ServerSASL;
import org.proton.plug.exceptions.ActiveMQAMQPException;
import org.proton.plug.handler.EventHandler;
public class AbstractConnectionContextTest
{
@Test
public void testListenerDoesntThrowNPEWhenClosingLinkWithNullContext() throws Exception
{
TestConnectionContext connectionContext = new TestConnectionContext(new TestConnectionCallback());
EventHandler listener = connectionContext.getListener();
Connection protonConnection = Connection.Factory.create();
Session protonSession = protonConnection.session();
Link link = protonSession.receiver("link");
link.setContext(null);
listener.onRemoteClose(link);
}
private class TestConnectionContext extends AbstractConnectionContext
{
public TestConnectionContext(AMQPConnectionCallback connectionCallback)
{
super(connectionCallback);
}
@Override
protected void remoteLinkOpened(Link link) throws Exception
{
}
@Override
protected AbstractProtonSessionContext newSessionExtension(Session realSession) throws ActiveMQAMQPException
{
return null;
}
public EventHandler getListener()
{
return listener;
}
}
private class TestConnectionCallback implements AMQPConnectionCallback
{
@Override
public void close()
{
}
@Override
public void onTransport(ByteBuf bytes, AMQPConnectionContext connection)
{
}
@Override
public AMQPSessionCallback createSessionCallback(AMQPConnectionContext connection)
{
return null;
}
@Override
public void setConnection(AMQPConnectionContext connection)
{
}
@Override
public AMQPConnectionContext getConnection()
{
return null;
}
@Override
public ServerSASL[] getSASLMechnisms()
{
return null;
}
}
}