Search in sources :

Example 1 with AuthenticationMechanism

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);
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) Test(org.junit.Test)

Example 2 with AuthenticationMechanism

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());
}
Also used : ImportMode(com.microsoft.azure.sdk.iot.service.ImportMode) AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) DeviceStatus(com.microsoft.azure.sdk.iot.service.DeviceStatus) Test(org.junit.Test)

Example 3 with AuthenticationMechanism

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());
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) Test(org.junit.Test)

Example 4 with AuthenticationMechanism

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);
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) Test(org.junit.Test)

Example 5 with AuthenticationMechanism

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);
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) Test(org.junit.Test)

Aggregations

AuthenticationMechanism (com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism)29 Test (org.junit.Test)25 ExportImportDevice (com.microsoft.azure.sdk.iot.service.ExportImportDevice)8 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)5 BaseDevice (com.microsoft.azure.sdk.iot.service.BaseDevice)4 X509Thumbprint (com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint)3 TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)1 Device (com.microsoft.azure.sdk.iot.service.Device)1 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)1 ImportMode (com.microsoft.azure.sdk.iot.service.ImportMode)1 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1