use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method constructor_sets_status_and_symmetrickey.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_15_007: [The constructor shall store
// the input device status and symmetric key into a member variable]
@Test
public void constructor_sets_status_and_symmetrickey() throws NoSuchAlgorithmException {
// Arrange
String deviceId = "xxx-device";
DeviceStatus expectedDeviceStatus = DeviceStatus.Disabled;
SymmetricKey expectedSymmetricKey = new SymmetricKey();
// Act
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, deviceId, expectedSymmetricKey);
// Assert
assertEquals(expectedSymmetricKey, device.getSymmetricKey());
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method deviceConstructorWithSharedAccessSignatureGeneratesKeysCorrectly.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_012: [If the provided authenticationType is SAS, a symmetric key shall be generated but no thumbprint shall be generated]
@Test
public void deviceConstructorWithSharedAccessSignatureGeneratesKeysCorrectly() {
// act
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SAS);
// assert
assertNull(device.getPrimaryThumbprint());
assertNull(device.getSecondaryThumbprint());
assertNotNull(device.getSymmetricKey());
assertNotNull(device.getPrimaryKey());
assertNotNull(device.getSecondaryKey());
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutSymmetricKeySaved.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_019: [If this device uses sas authentication, but does not have a primary and secondary symmetric key saved, an IllegalStateException shall be thrown.]
@Test(expected = IllegalStateException.class)
public void toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutSymmetricKeySaved() {
// arrange
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SAS);
AuthenticationMechanism authenticationMechanism = new AuthenticationMechanism(new SymmetricKey());
Deencapsulation.setField(authenticationMechanism.getSymmetricKey(), "primaryKey", null);
Deencapsulation.setField(device, "authentication", authenticationMechanism);
// act
reflectivelyInvokeToDeviceParser(device);
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method conversionToDeviceParser.
// 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 conversionToDeviceParser() {
// arrange
String expectedDeviceId = "deviceCA";
boolean expectedForceUpdate = false;
int expectedCloudToDeviceMessageCount = 23;
DeviceConnectionState expectedConnectionState = DeviceConnectionState.Connected;
String expectedConnectionStateUpdatedTime = "2001-09-09T09:09:09";
String expectedETag = "1234";
String expectedGenerationId = "5678";
String expectedLastActivityTime = "2001-09-09T09:09:09";
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, expectedDeviceId, AuthenticationType.CERTIFICATE_AUTHORITY);
Deencapsulation.setField(device, "cloudToDeviceMessageCount", expectedCloudToDeviceMessageCount);
Deencapsulation.setField(device, "connectionState", expectedConnectionState);
Deencapsulation.setField(device, "connectionStateUpdatedTime", expectedConnectionStateUpdatedTime);
Deencapsulation.setField(device, "eTag", expectedETag);
Deencapsulation.setField(device, "generationId", expectedGenerationId);
Deencapsulation.setField(device, "lastActivityTime", expectedLastActivityTime);
// act
DeviceParser parser = reflectivelyInvokeToDeviceParser(device);
// assert
assertEquals(AuthenticationTypeParser.CERTIFICATE_AUTHORITY, parser.getAuthenticationParser().getType());
assertEquals(expectedCloudToDeviceMessageCount, parser.getCloudToDeviceMessageCount());
assertEquals(expectedConnectionState.toString(), parser.getConnectionState());
assertEquals(expectedDeviceId, parser.getDeviceId());
assertEquals("\"" + expectedETag + "\"", parser.geteTag());
assertEquals(expectedGenerationId, parser.getGenerationId());
assertEquals(ParserUtility.getDateTimeUtc(expectedLastActivityTime), parser.getLastActivityTime());
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method conversionFromDeviceParserWithSASAuthentication.
// 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 conversionFromDeviceParserWithSASAuthentication() {
// arrange
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");
// act
BaseDevice deviceSAS = reflectivelyInvokeDeviceParserConstructor(parserSAS);
// assert
assertNull(deviceSAS.getPrimaryThumbprint());
assertNull(deviceSAS.getSecondaryThumbprint());
assertNotNull(deviceSAS.getSymmetricKey());
assertEquals(AuthenticationType.SAS, deviceSAS.getAuthenticationType());
}
Aggregations