use of com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism 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.auth.AuthenticationMechanism 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.auth.AuthenticationMechanism 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.auth.AuthenticationMechanism 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);
}
use of com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism in project azure-iot-sdk-java by Azure.
the class ExportImportDeviceTest method toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutPrimaryThumbprintSaved.
// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_061: [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
ExportImportDevice device = new ExportImportDevice();
device.setId("someDevice");
AuthenticationMechanism authentication = new AuthenticationMechanism(AuthenticationType.SELF_SIGNED);
X509Thumbprint thumbprint = Deencapsulation.newInstance(X509Thumbprint.class);
Deencapsulation.setField(thumbprint, "primaryThumbprint", null);
Deencapsulation.setField(authentication, "thumbprint", thumbprint);
device.setAuthentication(authentication);
// act
reflectivelyInvokeToExportImportDeviceParser(device);
}
Aggregations