Search in sources :

Example 1 with ExportImportDevice

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

Example 2 with ExportImportDevice

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

Example 3 with ExportImportDevice

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());
}
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 4 with ExportImportDevice

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());
}
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 ExportImportDevice

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

Aggregations

ExportImportDevice (com.microsoft.azure.sdk.iot.service.ExportImportDevice)18 Test (org.junit.Test)13 AuthenticationMechanism (com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism)8 ArrayList (java.util.ArrayList)3 BlobItem (com.azure.storage.blob.models.BlobItem)1 BlobInputStream (com.azure.storage.blob.specialized.BlobInputStream)1 ExportImportDeviceParser (com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser)1 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 JobProperties (com.microsoft.azure.sdk.iot.service.JobProperties)1 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)1 X509Thumbprint (com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint)1 IotHubTooManyDevicesException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubTooManyDevicesException)1 Scanner (java.util.Scanner)1 AfterClass (org.junit.AfterClass)1 Ignore (org.junit.Ignore)1 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)1 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)1