use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class DeviceTest method createFromId_success.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_003: [The constructor shall create a new instance of Device using the given deviceId and return with it]
@Test
public void createFromId_success() {
// Arrange
String deviceId = "xxx-device";
new Expectations() {
{
Deencapsulation.newInstance(Device.class, new Class[] { String.class, DeviceStatus.class, SymmetricKey.class }, deviceId, null, null);
}
};
// Act
Device device = Device.createFromId(deviceId, null, null);
// Assert
assertNotEquals(device, null);
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class DeviceTest method constructor_create_initialize_properties.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_28_001: [The constructor shall set the deviceId, status and symmetricKey.]
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_006: [The constructor shall initialize all properties to default values]
@Test
public void constructor_create_initialize_properties() {
// Arrange
String deviceId = "xxx-device";
DeviceStatus expectedDeviceStatus = DeviceStatus.Enabled;
String utcTimeDefault = "0001-01-01T00:00:00";
String offsetTimeDefault = "0001-01-01T00:00:00-00:00";
// Act
Device device = Deencapsulation.newInstance(Device.class, new Class[] { String.class, DeviceStatus.class, SymmetricKey.class }, deviceId, null, null);
// Assert
assertEquals(deviceId, device.getDeviceId());
assertNotEquals(null, device.getSymmetricKey());
assertEquals("", device.getGenerationId());
assertEquals("", device.geteTag());
assertEquals(DeviceStatus.Enabled, device.getStatus());
assertEquals("", device.getStatusReason());
assertEquals(utcTimeDefault, device.getStatusUpdatedTime());
assertEquals(DeviceConnectionState.Disconnected, device.getConnectionState());
assertEquals(utcTimeDefault, device.getConnectionStateUpdatedTime());
assertEquals(offsetTimeDefault, device.getLastActivityTime());
assertEquals(0, device.getCloudToDeviceMessageCount());
assertNull(device.getCapabilities());
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class DeviceTest method setScopeSetsScope.
@Test
public void setScopeSetsScope() {
// arrange
String scope = "scope";
Device device = Device.createDevice("device", AuthenticationType.SAS);
// act
device.setScope(scope);
// assert
String actualScope = Deencapsulation.getField(device, "scope");
assertEquals(scope, actualScope);
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class DeviceTest method conversionFromDeviceParserWithSASAuthentication.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_34_014: [This constructor shall create a new Device object using the values within the provided parser.]
@Test
public void conversionFromDeviceParserWithSASAuthentication() {
// arrange
String scope = "scope";
DeviceParser parserSAS = new DeviceParser();
parserSAS.setAuthenticationParser(Deencapsulation.newInstance(AuthenticationParser.class));
parserSAS.getAuthenticationParser().setType(AuthenticationTypeParser.SAS);
parserSAS.getAuthenticationParser().setSymmetricKey(new SymmetricKeyParser(SAMPLE_KEY, SAMPLE_KEY));
parserSAS.setDeviceId("deviceSAS");
parserSAS.setScope(scope);
// act
Device deviceSAS = reflectivelyInvokeDeviceParserConstructor(parserSAS);
// assert
assertNull(deviceSAS.getPrimaryThumbprint());
assertNull(deviceSAS.getSecondaryThumbprint());
assertNotNull(deviceSAS.getSymmetricKey());
assertEquals(AuthenticationType.SAS, deviceSAS.getAuthenticationType());
assertEquals(scope, deviceSAS.getScope());
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class DeviceTest method constructor2_create_initialize_properties.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_28_002: [The constructor shall set the deviceId and symmetricKey.]
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_28_003: [The constructor shall initialize all properties to default values]
@Test
public void constructor2_create_initialize_properties() {
// Arrange
String deviceId = "xxx-device";
String utcTimeDefault = "0001-01-01T00:00:00";
String offsetTimeDefault = "0001-01-01T00:00:00-00:00";
// Act
Device device = Deencapsulation.newInstance(Device.class, new Class[] { String.class, AuthenticationType.class }, deviceId, AuthenticationType.SAS);
// Assert
assertEquals(deviceId, device.getDeviceId());
assertNotNull(device.getSymmetricKey());
assertEquals("", device.getGenerationId());
assertEquals("", device.geteTag());
assertEquals(DeviceStatus.Enabled, device.getStatus());
assertEquals("", device.getStatusReason());
assertEquals(utcTimeDefault, device.getStatusUpdatedTime());
assertEquals(DeviceConnectionState.Disconnected, device.getConnectionState());
assertEquals(utcTimeDefault, device.getConnectionStateUpdatedTime());
assertEquals(offsetTimeDefault, device.getLastActivityTime());
assertEquals(0, device.getCloudToDeviceMessageCount());
assertNull(device.getCapabilities());
}
Aggregations