use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportDeviceTest method constructorWithParserGeneratesMissingSecondaryKeyWhenSASAuthenticated.
// Codes_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_058: [If the provided parser uses SAS authentication and is missing one or both symmetric keys, two new keys will be generated.]
@Test
public void constructorWithParserGeneratesMissingSecondaryKeyWhenSASAuthenticated() {
// arrange
ExportImportDeviceParser parser = new ExportImportDeviceParser();
parser.setId("someDevice");
parser.setAuthentication(new AuthenticationParser());
parser.getAuthenticationFinal().setType(AuthenticationTypeParser.SAS);
parser.getAuthenticationFinal().setSymmetricKey(new SymmetricKeyParser());
parser.getAuthenticationFinal().getSymmetricKey().setPrimaryKey(SAMPLE_KEY);
// act
ExportImportDevice device = reflectivelyInvokeExportImportDeviceParserConstructor(parser);
// assert
assertNotNull(device.getAuthenticationFinal());
assertNotNull(device.getAuthenticationFinal().getSymmetricKey());
assertNotNull(device.getAuthenticationFinal().getSymmetricKey().getPrimaryKey());
assertNotNull(device.getAuthenticationFinal().getSymmetricKey().getSecondaryKey());
assertNotEquals(SAMPLE_KEY, device.getAuthenticationFinal().getSymmetricKey().getPrimaryKey());
}
use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportDeviceTest method equalsWorks.
@Test
public void equalsWorks() {
// arrange
ExportImportDevice device1 = createTestDevice(new AuthenticationMechanism(AuthenticationType.CERTIFICATE_AUTHORITY), ImportMode.Create, DeviceStatus.Disabled);
ExportImportDevice device2 = createTestDevice(new AuthenticationMechanism(AuthenticationType.CERTIFICATE_AUTHORITY), ImportMode.Create, DeviceStatus.Disabled);
ExportImportDevice device3 = createTestDevice(new AuthenticationMechanism(AuthenticationType.CERTIFICATE_AUTHORITY), ImportMode.CreateOrUpdate, DeviceStatus.Disabled);
ExportImportDevice device4 = createTestDevice(new AuthenticationMechanism(AuthenticationType.CERTIFICATE_AUTHORITY), ImportMode.Create, DeviceStatus.Enabled);
ExportImportDevice device5 = createTestDevice(new AuthenticationMechanism(AuthenticationType.SELF_SIGNED), ImportMode.Create, DeviceStatus.Enabled);
// assert
assertEquals(device1, device2);
assertNotEquals(device1, device3);
assertNotEquals(device1, device4);
assertNotEquals(device1, device5);
assertNotEquals(device1, 1);
}
use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportDeviceTest method gettersAndSettersWork.
// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_15_001: [The ExportImportDevice class shall have the following properties: Id, Etag, ImportMode, Status, StatusReason, Authentication]
@Test
public void gettersAndSettersWork() {
// arrange
ExportImportDevice device = Deencapsulation.newInstance(ExportImportDevice.class, new Class[] {});
AuthenticationMechanism expectedAuthentication = new AuthenticationMechanism(AuthenticationType.CERTIFICATE_AUTHORITY);
String expectedETag = "etag";
String expectedId = "id";
ImportMode expectedImportMode = ImportMode.Create;
DeviceStatus expectedStatus = DeviceStatus.Disabled;
String expectedStatusReason = "test";
// act
device.setAuthentication(expectedAuthentication);
device.seteTag(expectedETag);
device.setId(expectedId);
device.setImportMode(expectedImportMode);
device.setStatus(expectedStatus);
device.setStatusReason(expectedStatusReason);
// assert
assertEquals(expectedAuthentication, device.getAuthenticationFinal());
assertEquals(expectedETag, device.geteTag());
assertEquals(expectedId, device.getId());
assertEquals(expectedImportMode, device.getImportMode());
assertEquals(expectedStatus, device.getStatus());
assertEquals(expectedStatusReason, device.getStatusReason());
}
use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportDeviceTest method conversionToExportImportDeviceParser.
// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_054: [This method shall convert this into an ExportImportDeviceParser object and return it.]
@Test
public void conversionToExportImportDeviceParser() {
// arrange
ExportImportDevice deviceCA = new ExportImportDevice();
deviceCA.setId("deviceCA");
deviceCA.setAuthentication(new AuthenticationMechanism(AuthenticationType.CERTIFICATE_AUTHORITY));
deviceCA.setImportMode(ImportMode.CreateOrUpdate);
deviceCA.setStatus(DeviceStatus.Enabled);
ExportImportDevice deviceSelf = new ExportImportDevice();
deviceSelf.setId("deviceSelf");
deviceSelf.setAuthentication(new AuthenticationMechanism(AuthenticationType.SELF_SIGNED));
ExportImportDevice deviceSAS = new ExportImportDevice();
deviceSAS.setId("deviceSAS");
deviceSAS.setAuthentication(new AuthenticationMechanism(AuthenticationType.SAS));
// act
ExportImportDeviceParser parserCA = reflectivelyInvokeToExportImportDeviceParser(deviceCA);
ExportImportDeviceParser parserSelf = reflectivelyInvokeToExportImportDeviceParser(deviceSelf);
ExportImportDeviceParser parserSAS = reflectivelyInvokeToExportImportDeviceParser(deviceSAS);
// assert
assertEquals(AuthenticationTypeParser.CERTIFICATE_AUTHORITY, parserCA.getAuthenticationFinal().getType());
assertEquals(AuthenticationTypeParser.SELF_SIGNED, parserSelf.getAuthenticationFinal().getType());
assertEquals(AuthenticationTypeParser.SAS, parserSAS.getAuthenticationFinal().getType());
assertEquals(ImportMode.CreateOrUpdate.toString(), parserCA.getImportMode());
assertEquals(DeviceStatus.Enabled.toString(), parserCA.getStatus());
}
use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportDeviceTest method toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutSymmetricKeySaved.
// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_060: [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
ExportImportDevice device = new ExportImportDevice();
device.setId("someDevice");
AuthenticationMechanism authentication = new AuthenticationMechanism(AuthenticationType.SAS);
Deencapsulation.setField(authentication, "symmetricKey", null);
device.setAuthentication(authentication);
// act
reflectivelyInvokeToExportImportDeviceParser(device);
}
Aggregations