use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method constructor_initialize_properties.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_12_006: [The constructor shall initialize all properties to default value]
@Test
public void constructor_initialize_properties() {
// Arrange
String utcTimeDefault = "0001-01-01T00:00:00";
String offsetTimeDefault = "0001-01-01T00:00:00-00:00";
String deviceId = "xxx-device";
// Act
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, deviceId, SymmetricKey.class);
// Assert
assertNotEquals(null, device);
assertNotEquals(device.getSymmetricKey(), null);
assertEquals("xxx-device", device.getDeviceId());
assertEquals("", device.getGenerationId());
assertEquals("", device.geteTag());
assertEquals(DeviceConnectionState.Disconnected, device.getConnectionState());
assertEquals(utcTimeDefault, device.getConnectionStateUpdatedTime());
assertEquals(offsetTimeDefault, device.getLastActivityTime());
assertEquals(0, device.getCloudToDeviceMessageCount());
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method conversionToDeviceParserWithSelfSignedAuthentication.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_018: [This method shall return a new instance of a DeviceParser object that is populated using the properties of this.]
@Test
public void conversionToDeviceParserWithSelfSignedAuthentication() {
// arrange
BaseDevice deviceSelf = Deencapsulation.newInstance(BaseDevice.class, "deviceSelf", AuthenticationType.SELF_SIGNED);
// act
DeviceParser parserSelf = reflectivelyInvokeToDeviceParser(deviceSelf);
// assert
assertEquals(AuthenticationTypeParser.SELF_SIGNED, parserSelf.getAuthenticationParser().getType());
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method conversionToDeviceParserWithSASAuthentication.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_018: [This method shall return a new instance of a DeviceParser object that is populated using the properties of this.]
@Test
public void conversionToDeviceParserWithSASAuthentication() {
// arrange
BaseDevice deviceSAS = Deencapsulation.newInstance(BaseDevice.class, "deviceSAS", AuthenticationType.SAS);
// act
DeviceParser parserSAS = reflectivelyInvokeToDeviceParser(deviceSAS);
// assert
assertEquals(AuthenticationTypeParser.SAS, parserSAS.getAuthenticationParser().getType());
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method conversionFromDeviceParserWithCertificateAuthorityAuthentication.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_014: [This constructor shall create a new Device object using the values within the provided parser.]
@Test
public void conversionFromDeviceParserWithCertificateAuthorityAuthentication() {
// arrange
DeviceParser parserCA = new DeviceParser();
parserCA.setAuthenticationParser(Deencapsulation.newInstance(AuthenticationParser.class));
parserCA.getAuthenticationParser().setType(AuthenticationTypeParser.CERTIFICATE_AUTHORITY);
parserCA.setDeviceId("deviceCA");
// act
BaseDevice deviceCA = reflectivelyInvokeDeviceParserConstructor(parserCA);
// assert
assertNull(deviceCA.getPrimaryThumbprint());
assertNull(deviceCA.getSecondaryThumbprint());
assertNull(deviceCA.getSymmetricKey());
assertEquals(AuthenticationType.CERTIFICATE_AUTHORITY, deviceCA.getAuthenticationType());
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutPrimaryThumbprintSaved.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_020: [If this device uses self signed authentication, but does not have a primary and secondary thumbprint saved, an IllegalStateException shall be thrown.]
@Test(expected = IllegalStateException.class)
public void toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutPrimaryThumbprintSaved() {
// arrange
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SELF_SIGNED);
X509Thumbprint thumbprint = Deencapsulation.newInstance(X509Thumbprint.class);
Deencapsulation.setField(thumbprint, "primaryThumbprint", null);
AuthenticationMechanism authentication = new AuthenticationMechanism(SAMPLE_THUMBPRINT, SAMPLE_THUMBPRINT);
Deencapsulation.setField(authentication, "thumbprint", thumbprint);
Deencapsulation.setField(device, "authentication", authentication);
// act
reflectivelyInvokeToDeviceParser(device);
}
Aggregations