use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method constructor_create_sas_token.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_005: [The constructor shall create a SAS token object using the IotHubConnectionString]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_006: [The constructor shall store connection string, hostname, username and sasToken]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_007: [The constructor shall create a new instance of AmqpSend object]
@Test
public void constructor_create_sas_token() throws Exception {
// Arrange
String iotHubName = "IOTHUBNAME";
String hostName = "HOSTNAME";
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
new Expectations() {
{
iotHubServiceSasToken = new IotHubServiceSasToken(withNotNull());
amqpSend = new AmqpSend(anyString, anyString, anyString, iotHubServiceClientProtocol);
}
};
// Act
ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
// Assert
assertNotEquals(hostName, Deencapsulation.getField(serviceClient, "hostName"));
assertEquals(iotHubConnectionString.getUserString(), Deencapsulation.getField(serviceClient, "userName"));
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method constructor_input_null.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_004: [The constructor shall throw IllegalArgumentException if the input object is null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_input_null() throws Exception {
// Arrange
IotHubConnectionString iotHubConnectionString = null;
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
// Act
ServiceClient serviceClient = Deencapsulation.newInstance(ServiceClient.class, iotHubConnectionString, iotHubServiceClientProtocol);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method open_call_amqpsender_open.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_009: [The function shall call open() on the member AMQP sender object]
@Test
public void open_call_amqpsender_open() throws Exception {
// Arrange
String iotHubName = "IOTHUBNAME";
String hostName = "HOSTNAME";
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
// Assert
new Expectations() {
{
amqpSend.open();
}
};
// Act
serviceClient.open();
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringTest method getUrlDevice_good_case.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_12_003: [The function shall create a URL object from the given deviceId using the following format: https:hostname/devices/deviceId?api-version=201X-XX-XX] StringBuilder stringBuilder = new StringBuilder();
@Test
public void getUrlDevice_good_case() throws Exception {
// Arrange
String deviceId = "xxx-device";
String iotHubName = "b.c.d";
String hostName = "HOSTNAME." + iotHubName;
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
String expected = "https://HOSTNAME.b.c.d/devices/xxx-device?api-version=2016-11-14";
// Act
String actual = iotHubConnectionString.getUrlDevice(deviceId).toString();
// Assert
assertEquals("Device URL mismatch!", expected, actual);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringTest method getUrlTwinTags_throwsOnNullDeviceID.
@Test(expected = IllegalArgumentException.class)
public void getUrlTwinTags_throwsOnNullDeviceID() throws Exception {
//arrange
String iotHubName = "b.c.d";
String hostName = "HOSTNAME." + iotHubName;
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
String deviceId = null;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
//act
String actual = iotHubConnectionString.getUrlTwinTags(deviceId).toString();
}
Aggregations