Search in sources :

Example 6 with ProtonSession

use of io.vertx.proton.ProtonSession in project hono by eclipse.

the class ForwardingDownstreamAdapterTest method setup.

/**
 * Initializes mocks etc.
 */
@Before
public void setup() {
    attachments = mock(Record.class);
    ProtonSession session = mock(ProtonSession.class);
    con = mock(ProtonConnection.class);
    when(con.getRemoteContainer()).thenReturn("downstream");
    when(con.createSession()).thenReturn(session);
    when(con.attachments()).thenReturn(attachments);
    connectionFactory = newMockConnectionFactory(con, false);
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) ProtonSession(io.vertx.proton.ProtonSession) Record(org.apache.qpid.proton.engine.Record) Before(org.junit.Before)

Example 7 with ProtonSession

use of io.vertx.proton.ProtonSession in project hono by eclipse.

the class AbstractRequestResponseEndpointTest method setUp.

/**
 * Initializes common fixture.
 */
@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() {
    connection = mock(ProtonConnection.class);
    vertx = mock(Vertx.class);
    eventBus = mock(EventBus.class);
    receiver = mock(ProtonReceiver.class);
    when(receiver.handler(any())).thenReturn(receiver);
    when(receiver.closeHandler(any())).thenReturn(receiver);
    when(receiver.setAutoAccept(any(Boolean.class))).thenReturn(receiver);
    when(receiver.setPrefetch(any(Integer.class))).thenReturn(receiver);
    when(receiver.setQoS(any(ProtonQoS.class))).thenReturn(receiver);
    when(vertx.eventBus()).thenReturn(eventBus);
    final ProtonSession session = mock(ProtonSession.class);
    when(session.getConnection()).thenReturn(connection);
    sender = mock(ProtonSender.class);
    when(sender.getName()).thenReturn("mocked sender");
    when(sender.isOpen()).thenReturn(Boolean.TRUE);
    when(sender.getSession()).thenReturn(session);
    authService = mock(AuthorizationService.class);
    when(authService.isAuthorized(any(HonoUser.class), any(ResourceIdentifier.class), anyString())).thenReturn(Future.succeededFuture(Boolean.TRUE));
    formalMessageVerification = mock(BiFunction.class);
    when(formalMessageVerification.apply(any(ResourceIdentifier.class), any(Message.class))).thenReturn(Boolean.TRUE);
    requestMessageHandler = mock(BiFunction.class);
    endpoint = getEndpoint();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonSession(io.vertx.proton.ProtonSession) Message(org.apache.qpid.proton.message.Message) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) ProtonConnection(io.vertx.proton.ProtonConnection) ProtonSender(io.vertx.proton.ProtonSender) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) ProtonQoS(io.vertx.proton.ProtonQoS) HonoUser(org.eclipse.hono.auth.HonoUser) AuthorizationService(org.eclipse.hono.service.auth.AuthorizationService) BiFunction(java.util.function.BiFunction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with ProtonSession

use of io.vertx.proton.ProtonSession in project hono by eclipse.

the class AbstractRequestResponseEndpointTest method testFreeSubscription.

/**
 * Verify that a second response link to the same address is being accepted if the first is released before.
 */
@Test
public void testFreeSubscription() {
    final ProtonConnection con1 = mock(ProtonConnection.class);
    final ProtonSession session1 = mock(ProtonSession.class);
    when(session1.getConnection()).thenReturn(con1);
    final ProtonConnection con2 = mock(ProtonConnection.class);
    final ProtonSender sender1 = mock(ProtonSender.class);
    when(sender1.getSession()).thenReturn(session1);
    final ProtonSender sender2 = mock(ProtonSender.class);
    // WHEN a first sender attaches
    endpoint.onLinkAttach(con1, sender1, REPLY_RESOURCE);
    // THEN open has to be called
    verify(sender1).open();
    // WHEN the connection closed
    endpoint.onConnectionClosed(con1);
    // WHEN a new link is attached
    endpoint.onLinkAttach(con2, sender2, REPLY_RESOURCE);
    // THEN open has to be called
    verify(sender2).open();
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) ProtonSender(io.vertx.proton.ProtonSender) ProtonSession(io.vertx.proton.ProtonSession) Test(org.junit.jupiter.api.Test)

Aggregations

ProtonSession (io.vertx.proton.ProtonSession)8 ProtonConnection (io.vertx.proton.ProtonConnection)6 ProtonSender (io.vertx.proton.ProtonSender)4 Handler (io.vertx.core.Handler)2 Vertx (io.vertx.core.Vertx)2 ProtonQoS (io.vertx.proton.ProtonQoS)2 ProtonReceiver (io.vertx.proton.ProtonReceiver)2 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 AsyncResult (io.vertx.core.AsyncResult)1 CompositeFuture (io.vertx.core.CompositeFuture)1 Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 EventBus (io.vertx.core.eventbus.EventBus)1 Async (io.vertx.ext.unit.Async)1 Timeout (io.vertx.junit5.Timeout)1 VertxExtension (io.vertx.junit5.VertxExtension)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)1