Search in sources :

Example 11 with ExportImportDevice

use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.

the class ExportImportDeviceTest method toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutThumbprintSaved.

// 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 toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutThumbprintSaved() {
    // arrange
    ExportImportDevice device = new ExportImportDevice();
    device.setId("someDevice");
    AuthenticationMechanism authentication = new AuthenticationMechanism(AuthenticationType.SELF_SIGNED);
    Deencapsulation.setField(authentication, "thumbprint", 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 12 with ExportImportDevice

use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.

the class ExportImportDeviceTest method constructorWithParserGeneratesMissingSecondaryThumbprintsWhenSelfSigned.

// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_059: [If the provided parser uses self signed authentication and is missing one or both thumbprints, two new thumbprints will be generated.]
@Test
public void constructorWithParserGeneratesMissingSecondaryThumbprintsWhenSelfSigned() {
    // arrange
    ExportImportDeviceParser parser = new ExportImportDeviceParser();
    parser.setId("someDevice");
    parser.setAuthentication(new AuthenticationParser());
    parser.getAuthenticationFinal().setType(AuthenticationTypeParser.SELF_SIGNED);
    parser.getAuthenticationFinal().setThumbprint(new X509ThumbprintParser());
    parser.getAuthenticationFinal().getThumbprint().setPrimaryThumbprint(SAMPLE_THUMBPRINT);
    // act
    ExportImportDevice device = reflectivelyInvokeExportImportDeviceParserConstructor(parser);
    // assert
    assertNotNull(device.getAuthenticationFinal());
    assertNotNull(device.getAuthenticationFinal().getPrimaryThumbprint());
    assertNotNull(device.getAuthenticationFinal().getSecondaryThumbprint());
    assertNotEquals(SAMPLE_THUMBPRINT, device.getAuthenticationFinal().getPrimaryThumbprint());
}
Also used : ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) Test(org.junit.Test)

Example 13 with ExportImportDevice

use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.

the class ExportImportDeviceTest method createTestDevice.

/**
 * Uses reflection to create an ExportImportDevice and sets the provided properties
 * @param authentication the authentication the device uses
 * @param importMode the import mode the device uses
 * @param status the status of the device
 * @return the created ExportImportDevice object
 */
private ExportImportDevice createTestDevice(AuthenticationMechanism authentication, ImportMode importMode, DeviceStatus status) {
    ExportImportDevice device = Deencapsulation.newInstance(ExportImportDevice.class);
    device.setAuthentication(authentication);
    device.setImportMode(importMode);
    device.setStatus(status);
    return device;
}
Also used : ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice)

Example 14 with ExportImportDevice

use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.

the class ExportImportDeviceTest method toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutPrimaryKeySaved.

// 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 toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutPrimaryKeySaved() {
    // arrange
    ExportImportDevice device = new ExportImportDevice();
    device.setId("someDevice");
    AuthenticationMechanism authentication = new AuthenticationMechanism(AuthenticationType.SAS);
    SymmetricKey symmetricKey = new SymmetricKey();
    Deencapsulation.setField(symmetricKey, "primaryKey", null);
    Deencapsulation.setField(authentication, "symmetricKey", symmetricKey);
    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) SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) Test(org.junit.Test)

Example 15 with ExportImportDevice

use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.

the class ExportImportDeviceTest method emptyConstructorGeneratesDeviceIdSymmetricKeyAndAuthType.

// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_050: [This constructor shall automatically set the authentication type of this object to be SAS, and shall generate a deviceId and symmetric key.]
@Test
public void emptyConstructorGeneratesDeviceIdSymmetricKeyAndAuthType() {
    // act
    ExportImportDevice device = new ExportImportDevice();
    // assert
    assertNotNull(device.getAuthenticationFinal());
    assertNotNull(device.getAuthenticationFinal().getSymmetricKey());
    assertEquals(AuthenticationType.SAS, device.getAuthenticationFinal().getAuthenticationType());
}
Also used : 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