use of org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor in project activemq-artemis by apache.
the class RemotingServiceImplTest method testInterceptorsAreAddedOnCreationOfServiceRegistry.
/**
* Tests ensures that both interceptors from the service registry and also interceptors defined in the configuration
* are added to the RemotingServiceImpl on creation
*/
@Test
public void testInterceptorsAreAddedOnCreationOfServiceRegistry() throws Exception {
Field incomingInterceptors = RemotingServiceImpl.class.getDeclaredField("incomingInterceptors");
Field outgoingInterceptors = RemotingServiceImpl.class.getDeclaredField("outgoingInterceptors");
incomingInterceptors.setAccessible(true);
outgoingInterceptors.setAccessible(true);
serviceRegistry.addIncomingInterceptor(new FakeInterceptor());
serviceRegistry.addOutgoingInterceptor(new FakeInterceptor());
List<String> interceptorClassNames = new ArrayList<>();
interceptorClassNames.add(FakeInterceptor.class.getCanonicalName());
configuration.setIncomingInterceptorClassNames(interceptorClassNames);
configuration.setOutgoingInterceptorClassNames(interceptorClassNames);
remotingService = new RemotingServiceImpl(null, configuration, null, null, null, null, null, serviceRegistry);
assertTrue(((List) incomingInterceptors.get(remotingService)).size() == 2);
assertTrue(((List) outgoingInterceptors.get(remotingService)).size() == 2);
assertTrue(((List) incomingInterceptors.get(remotingService)).contains(serviceRegistry.getIncomingInterceptors(null).get(0)));
assertTrue(((List) outgoingInterceptors.get(remotingService)).contains(serviceRegistry.getOutgoingInterceptors(null).get(0)));
}
use of org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor in project activemq-artemis by apache.
the class RemotingServiceImplTest method testPropagatingInterceptors.
/**
* Tests that the service registry gets propaged into remotingService.
*/
@Test
public void testPropagatingInterceptors() throws Exception {
for (int i = 0; i < 5; i++) {
serviceRegistry.addIncomingInterceptor(new FakeInterceptor());
}
remotingService = new RemotingServiceImpl(null, configuration, null, null, null, null, null, serviceRegistry);
assertTrue(remotingService.getIncomingInterceptors().size() == 5);
assertTrue(remotingService.getIncomingInterceptors().get(0) instanceof FakeInterceptor);
assertTrue(remotingService.getIncomingInterceptors().get(0) != remotingService.getIncomingInterceptors().get(1));
}
use of org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor in project activemq-artemis by apache.
the class RemotingServiceImplTest method testSetInterceptorsAddsBothInterceptorsFromConfigAndServiceRegistry.
/**
* Tests ensures that setInterceptors methods adds both interceptors from the service registry and also interceptors
* defined in the configuration.
*/
@Test
public void testSetInterceptorsAddsBothInterceptorsFromConfigAndServiceRegistry() throws Exception {
Method method = RemotingServiceImpl.class.getDeclaredMethod("setInterceptors", Configuration.class);
Field incomingInterceptors = RemotingServiceImpl.class.getDeclaredField("incomingInterceptors");
Field outgoingInterceptors = RemotingServiceImpl.class.getDeclaredField("outgoingInterceptors");
method.setAccessible(true);
incomingInterceptors.setAccessible(true);
outgoingInterceptors.setAccessible(true);
serviceRegistry.addIncomingInterceptor(new FakeInterceptor());
serviceRegistry.addOutgoingInterceptor(new FakeInterceptor());
List<String> interceptorClassNames = new ArrayList<>();
interceptorClassNames.add(FakeInterceptor.class.getCanonicalName());
configuration.setIncomingInterceptorClassNames(interceptorClassNames);
configuration.setOutgoingInterceptorClassNames(interceptorClassNames);
method.invoke(remotingService, configuration);
assertTrue(((List) incomingInterceptors.get(remotingService)).size() == 2);
assertTrue(((List) outgoingInterceptors.get(remotingService)).size() == 2);
assertTrue(((List) incomingInterceptors.get(remotingService)).contains(serviceRegistry.getIncomingInterceptors(null).get(0)));
assertTrue(((List) outgoingInterceptors.get(remotingService)).contains(serviceRegistry.getOutgoingInterceptors(null).get(0)));
}
Aggregations