Search in sources :

Example 16 with DeviceClientConfig

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

the class DeviceClientConfigTest method getAndSetDeviceMethodAndTwinMessageCallbackAndContextsMatch.

@Test
public void getAndSetDeviceMethodAndTwinMessageCallbackAndContextsMatch(@Mocked final MessageCallback mockCallback) throws URISyntaxException {
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final String sharedAccessToken = null;
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
    DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
    Object dMContext = new Object();
    config.setDeviceMethodMessageCallback(mockCallback, dMContext);
    Object testContextDM = config.getDeviceMethodMessageContext();
    Object dTcontext = new Object();
    config.setDeviceTwinMessageCallback(mockCallback, dTcontext);
    Object testContextDT = config.getDeviceTwinMessageContext();
    final Object expectedDTContext = dTcontext;
    assertThat(testContextDT, is(expectedDTContext));
    assertEquals(config.getDeviceTwinMessageCallback(), mockCallback);
    final Object expectedDMContext = dMContext;
    assertThat(testContextDM, is(expectedDMContext));
    assertEquals(config.getDeviceMethodMessageCallback(), mockCallback);
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 17 with DeviceClientConfig

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

the class DeviceClientConfigTest method getAndSetMessageCallbackContextsMatch.

// Tests_SRS_DEVICECLIENTCONFIG_11_006: [The function shall set the message callback, with its associated context.]
// Tests_SRS_DEVICECLIENTCONFIG_11_011: [The function shall return the current message context.]
@Test
public void getAndSetMessageCallbackContextsMatch(@Mocked final MessageCallback mockCallback) throws URISyntaxException {
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final String sharedAccessToken = null;
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
    DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
    Object context = new Object();
    config.setMessageCallback(mockCallback, context);
    Object testContext = config.getMessageContext();
    final Object expectedContext = context;
    assertThat(testContext, is(expectedContext));
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 18 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig 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 19 with DeviceClientConfig

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

the class IotHubSasTokenTest method doesNotSetInvalidSASToken.

// Tests_SRS_IOTHUBSASTOKEN_25_008: [**The required format for the SAS Token shall be verified and IllegalArgumentException is thrown if unmatched.**]**
//Tests_SRS_IOTHUBSASTOKEN_11_001: [**The SAS token shall have the format `SharedAccessSignature sig=<signature >&se=<expiryTime>&sr=<resourceURI>`. The params can be in any order.**]**
@Test(expected = IllegalArgumentException.class)
public void doesNotSetInvalidSASToken() throws URISyntaxException {
    String sastoken = "SharedAccessSignature sr =sample-iothub-hostname.net%2fdevices%2fsample-device-ID&sig =S3%2flPidfBF48B7%2fOFAxMOYH8rpOneq68nu61D%2fBP6fo%3d&se =1469813873";
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, "iothub.sample-iothub-hostname.net", "sample-device-ID", null, sastoken);
    IotHubSasToken token = new IotHubSasToken(new DeviceClientConfig(iotHubConnectionString), 0);
    String tokenStr = token.toString();
    assertTrue(tokenStr != sastoken);
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 20 with DeviceClientConfig

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

the class IotHubSasTokenTest method setValidSASTokenCorrectly.

// Tests_SRS_IOTHUBSASTOKEN_25_007: [**If device key is not provided in config then the SASToken from config shall be used.**]**
@Test
public void setValidSASTokenCorrectly() throws URISyntaxException {
    String sastoken = "SharedAccessSignature sr=sample-iothub-hostname.net%2fdevices%2fsample-device-ID&sig=S3%2flPidfBF48B7%2fOFAxMOYH8rpOneq68nu61D%2fBP6fo%3d&se=1469813873";
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, "iothub.sample-iothub-hostname.net", "sample-device-ID", null, sastoken);
    IotHubSasToken token = new IotHubSasToken(new DeviceClientConfig(iotHubConnectionString), 0);
    String tokenStr = token.toString();
    assertTrue(tokenStr == sastoken);
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Aggregations

DeviceClientConfig (com.microsoft.azure.sdk.iot.device.DeviceClientConfig)32 Test (org.junit.Test)32 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)31 IotHubSasToken (com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken)9 NonStrictExpectations (mockit.NonStrictExpectations)3 IotHubSSLContext (com.microsoft.azure.sdk.iot.device.IotHubSSLContext)2 MessageCallback (com.microsoft.azure.sdk.iot.device.MessageCallback)1 State (com.microsoft.azure.sdk.iot.device.transport.State)1 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)1 FlowController (org.apache.qpid.proton.reactor.FlowController)1 Handshaker (org.apache.qpid.proton.reactor.Handshaker)1