Search in sources :

Example 1 with State

use of com.microsoft.azure.sdk.iot.device.transport.State in project azure-iot-sdk-java by Azure.

the class AmqpsTransportTest method constructorSetsStateToClosed.

// Tests_SRS_AMQPSTRANSPORT_15_002: [The constructor shall set the transport state to CLOSED.]
@Test
public void constructorSetsStateToClosed() {
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    State state = Deencapsulation.getField(transport, "state");
    assertEquals(State.CLOSED, state);
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) State(com.microsoft.azure.sdk.iot.device.transport.State) Test(org.junit.Test)

Example 2 with State

use of com.microsoft.azure.sdk.iot.device.transport.State in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnectionTest method constructorCopiesAllData.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_002: [The constructor shall save the configuration into private member variables.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_003: [The constructor shall initialize the sender and receiver
// endpoint private member variables using the send/receiveEndpointFormat constants and device id.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_004: [The constructor shall initialize a new Handshaker
// (Proton) object to handle communication handshake.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_005: [The constructor shall initialize a new FlowController
// (Proton) object to handle communication flow.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_006: [The constructor shall set its state to CLOSED.]
@Test
public void constructorCopiesAllData() throws IOException {
    baseExpectations();
    AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    DeviceClientConfig actualConfig = Deencapsulation.getField(connection, "config");
    String actualHostName = Deencapsulation.getField(connection, "hostName");
    String actualUserName = Deencapsulation.getField(connection, "userName");
    String actualSendEndpoint = Deencapsulation.getField(connection, "sendEndpoint");
    String actualReceiveEndpoint = Deencapsulation.getField(connection, "receiveEndpoint");
    assertEquals(mockConfig, actualConfig);
    assertEquals(hostName + ":" + amqpPort, actualHostName);
    assertEquals(deviceId + "@sas." + hubName, actualUserName);
    String expectedSendEndpoint = "/devices/test-deviceId/messages/events";
    assertEquals(expectedSendEndpoint, actualSendEndpoint);
    String expectedReceiveEndpoint = "/devices/test-deviceId/messages/devicebound";
    assertEquals(expectedReceiveEndpoint, actualReceiveEndpoint);
    new Verifications() {

        {
            new Handshaker();
            times = 1;
            new FlowController();
            times = 1;
        }
    };
    State actualState = Deencapsulation.getField(connection, "state");
    assertEquals(State.CLOSED, actualState);
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) Handshaker(org.apache.qpid.proton.reactor.Handshaker) DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) State(com.microsoft.azure.sdk.iot.device.transport.State) FlowController(org.apache.qpid.proton.reactor.FlowController) Test(org.junit.Test)

Example 3 with State

use of com.microsoft.azure.sdk.iot.device.transport.State in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnectionTest method onLinkRemoteOpen.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_041: [The connection state shall be considered OPEN when the sender link is open remotely.]
@Test
public void onLinkRemoteOpen() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockEvent.getLink();
            result = mockSender;
            mockSender.getName();
            result = "sender";
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    connection.onLinkRemoteOpen(mockEvent);
    State expectedState = State.OPEN;
    State actualState = Deencapsulation.getField(connection, "state");
    assertEquals(expectedState, actualState);
    new Verifications() {

        {
            mockEvent.getLink();
            times = 1;
            mockSender.getName();
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) State(com.microsoft.azure.sdk.iot.device.transport.State) Test(org.junit.Test)

Example 4 with State

use of com.microsoft.azure.sdk.iot.device.transport.State in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnectionTest method closeClosesAllProtonVariablesAndStopsProtonReactor.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_012: [The function shall set the status of the AMQPS connection to CLOSED.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_013: [The function shall close the AMQPS sender and receiver links,
// the AMQPS session and the AMQPS connection.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_014: [The function shall stop the Proton reactor.]
@Test
public void closeClosesAllProtonVariablesAndStopsProtonReactor() throws IOException, InterruptedException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockReactorFuture.cancel(true);
            mockExecutorService.shutdown();
        }
    };
    new MockUp<AmqpsIotHubConnection>() {

        @Mock
        void open() {
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "state", State.OPEN);
    Deencapsulation.setField(connection, "sender", mockSender);
    Deencapsulation.setField(connection, "receiver", mockReceiver);
    Deencapsulation.setField(connection, "session", mockSession);
    Deencapsulation.setField(connection, "connection", mockConnection);
    Deencapsulation.setField(connection, "executorService", mockExecutorService);
    connection.close();
    State actualState = Deencapsulation.getField(connection, "state");
    assertEquals(State.CLOSED, actualState);
    new Verifications() {

        {
            mockSender.close();
            times = 1;
            mockReceiver.close();
            times = 1;
            mockSession.close();
            times = 1;
            mockConnection.close();
            times = 1;
            mockExecutorService.shutdown();
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) State(com.microsoft.azure.sdk.iot.device.transport.State) Test(org.junit.Test)

Example 5 with State

use of com.microsoft.azure.sdk.iot.device.transport.State in project azure-iot-sdk-java by Azure.

the class AmqpsTransportTest method openSetsStateToOpenIfSuccessful.

// Tests_SRS_AMQPSTRANSPORT_15_006: [If the connection was opened successfully, the transport state shall be set to OPEN.]
@Test
public void openSetsStateToOpenIfSuccessful() throws IOException {
    new NonStrictExpectations() {

        {
            new AmqpsIotHubConnection(mockConfig, false);
            result = mockConnection;
        }
    };
    final AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    State state = Deencapsulation.getField(transport, "state");
    assertEquals(State.OPEN, state);
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) State(com.microsoft.azure.sdk.iot.device.transport.State) Test(org.junit.Test)

Aggregations

State (com.microsoft.azure.sdk.iot.device.transport.State)9 Test (org.junit.Test)9 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)4 AmqpsTransport (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport)3 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)3 Verifications (mockit.Verifications)3 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)2 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)2 DeviceClientConfig (com.microsoft.azure.sdk.iot.device.DeviceClientConfig)1 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)1 FlowController (org.apache.qpid.proton.reactor.FlowController)1 Handshaker (org.apache.qpid.proton.reactor.Handshaker)1