add/remove InterceptHandlers with server running

This commit is contained in:
IODBEEC1
2016-07-09 09:09:57 +02:00
parent d5399995c3
commit ed9d91e527
5 changed files with 67 additions and 1 deletions
@@ -29,6 +29,8 @@ import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
/**
* @author Wagner Macedo
@@ -122,4 +124,29 @@ public class BrokerInterceptorTest {
interval();
assertEquals(80, n.get());
}
@Test
public void testAddAndRemoveInterceptHandler() throws Exception {
InterceptHandler interceptHandlerMock1 = mock(InterceptHandler.class);
InterceptHandler interceptHandlerMock2 = mock(InterceptHandler.class);
// add
interceptor.addInterceptHandler(interceptHandlerMock1);
interceptor.addInterceptHandler(interceptHandlerMock2);
Subscription subscription = new Subscription("cli1", "o2", AbstractMessage.QOSType.MOST_ONE);
interceptor.notifyTopicSubscribed(subscription, "cli1234");
interval();
verify(interceptHandlerMock1).onSubscribe(refEq(new InterceptSubscribeMessage(subscription, "cli1234")));
verify(interceptHandlerMock2).onSubscribe(refEq(new InterceptSubscribeMessage(subscription, "cli1234")));
// remove
interceptor.removeInterceptHandler(interceptHandlerMock1);
interceptor.notifyTopicSubscribed(subscription, "cli1235");
interval();
verifyNoMoreInteractions(interceptHandlerMock1);
verify(interceptHandlerMock2).onSubscribe(refEq(new InterceptSubscribeMessage(subscription, "cli1235")));
}
}