use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.
the class RadiusRequestHandlerTest method testRunReject.
/**
* Test that when run is called with an RejectAllHandler that the resultant promise returns a RadiusResponse
* containing an ACCESS_REJECT packet.
*
* @throws InterruptedException - when an interrupt occurs.
* @throws RadiusProcessingException - when something goes wrong processing a RADIUS packet.
* @throws UnknownHostException - if the host can't be determined
*/
@Test(enabled = true)
public void testRunReject() throws UnknownHostException, InterruptedException, RadiusProcessingException {
// given
final RadiusRequestContext reqCtx = mock(RadiusRequestContext.class);
final ClientConfig clientConfig = mock(ClientConfig.class);
String url = "forgerock.org";
InetSocketAddress socketAddress = new InetSocketAddress(Inet4Address.getByName(url), 6836);
when(reqCtx.getClientConfig()).thenReturn(clientConfig);
when(reqCtx.getSource()).thenReturn(socketAddress);
when(clientConfig.getName()).thenReturn("TestConfig");
when(clientConfig.getAccessRequestHandlerClass()).thenReturn(RejectAllHandler.class);
final ByteBuffer bfr = Utils.toBuffer(res);
final PromiseImpl<RadiusResponse, RadiusProcessingException> promise = PromiseImpl.create();
EventBus eventBus = new EventBus();
AccessRequestHandlerFactory accessRequestHandlerFactory = mock(AccessRequestHandlerFactory.class);
when(accessRequestHandlerFactory.getAccessRequestHandler(reqCtx)).thenReturn(new RejectAllHandler());
final RadiusRequestHandler handler = new RadiusRequestHandler(accessRequestHandlerFactory, reqCtx, bfr, promise, promise, eventBus);
handler.run();
// when
final RadiusResponse result = promise.getOrThrow();
// then
assertThat(result.getResponsePacket().getType()).isEqualTo(PacketType.ACCESS_REJECT);
verify(reqCtx, times(1)).send(isA(AccessReject.class));
}
use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.
the class RadiusRequestHandlerTest method testRun.
/**
* Test that when run is called with an AcceptAllHandler then the RadiusAuthResponse contains a success code and an
* AcceptResponse is sent.
*
* @throws InterruptedException - when an interrupt occurs.
* @throws RadiusProcessingException - when something goes wrong processing a RADIUS packet.
* @throws UnknownHostException - if the host can't be determined
*/
@Test(enabled = true)
public void testRun() throws UnknownHostException, InterruptedException, RadiusProcessingException {
// given
final RadiusRequestContext reqCtx = mock(RadiusRequestContext.class);
final ClientConfig clientConfig = mock(ClientConfig.class);
String url = "forgerock.org";
InetSocketAddress socketAddress = new InetSocketAddress(Inet4Address.getByName(url), 6836);
when(reqCtx.getClientConfig()).thenReturn(clientConfig);
when(reqCtx.getSource()).thenReturn(socketAddress);
when(clientConfig.getName()).thenReturn("TestConfig");
final ByteBuffer bfr = Utils.toBuffer(res);
final PromiseImpl<RadiusResponse, RadiusProcessingException> promise = PromiseImpl.create();
EventBus eventBus = new EventBus();
AccessRequestHandlerFactory accessRequestHandlerFactory = mock(AccessRequestHandlerFactory.class);
when(accessRequestHandlerFactory.getAccessRequestHandler(reqCtx)).thenReturn(new AcceptAllHandler());
final RadiusRequestHandler handler = new RadiusRequestHandler(accessRequestHandlerFactory, reqCtx, bfr, promise, promise, eventBus);
handler.run();
// when
final RadiusResponse result = promise.getOrThrow();
// then
assertThat(result.getResponsePacket().getType()).isEqualTo(PacketType.ACCESS_ACCEPT);
verify(reqCtx, times(1)).send(isA(AccessAccept.class));
}
use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.
the class RadiusServerEventRegistrarTest method packetProcessed.
/**
* Test the following method.
*
* @see org.forgerock.openam.radius.server.monitoring.RadiusServerEventRegistrar#packetProcessed
*/
@Test(enabled = true)
public void packetProcessed() {
// Given
EventBus eventBus = new EventBus();
final RadiusServerEventRegistrar eventRegistrar = new RadiusServerEventRegistrar(eventBus);
// When
eventRegistrar.packetProcessed();
// Then
assertThat(eventRegistrar.getNumberOfPacketsProcessed()).isEqualTo(1);
}
use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.
the class RadiusServerEventRegistrarTest method packetReceived.
/**
* Test the following method.
*
* @see org.forgerock.openam.radius.server.monitoring.RadiusServerEventRegistrar#packetReceived
*/
@Test(enabled = true)
public void packetReceived() {
// Given
EventBus eventBus = new EventBus();
final RadiusServerEventRegistrar eventRegistrar = new RadiusServerEventRegistrar(eventBus);
// When
eventRegistrar.packetReceived();
// Then
assertThat(eventRegistrar.getNumberOfPacketsRecieved()).isEqualTo(1);
}
use of org.forgerock.guava.common.eventbus.EventBus in project OpenAM by OpenRock.
the class RadiusServerEventRegistrarTest method packetAccepted.
/**
* Test the following method.
*
* @see org.forgerock.openam.radius.server.monitoring.RadiusServerEventRegistrar#packetAccepted
*/
@Test(enabled = true)
public void packetAccepted() {
// Given
EventBus eventBus = new EventBus();
final RadiusServerEventRegistrar eventRegistrar = new RadiusServerEventRegistrar(eventBus);
// When
eventRegistrar.packetAccepted();
// Then
assertThat(eventRegistrar.getNumberOfAcceptedPackets()).isEqualTo(1);
}
Aggregations