Search in sources :

Example 36 with Device

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

the class DeviceTest method createFromId_success.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_003: [The constructor shall create a new instance of Device using the given deviceId and return with it]
@Test
public void createFromId_success() {
    // Arrange
    String deviceId = "xxx-device";
    new Expectations() {

        {
            Deencapsulation.newInstance(Device.class, new Class[] { String.class, DeviceStatus.class, SymmetricKey.class }, deviceId, null, null);
        }
    };
    // Act
    Device device = Device.createFromId(deviceId, null, null);
    // Assert
    assertNotEquals(device, null);
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Example 37 with Device

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

the class DeviceTest method constructor_create_initialize_properties.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_28_001: [The constructor shall set the deviceId, status and symmetricKey.]
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_006: [The constructor shall initialize all properties to default values]
@Test
public void constructor_create_initialize_properties() {
    // Arrange
    String deviceId = "xxx-device";
    DeviceStatus expectedDeviceStatus = DeviceStatus.Enabled;
    String utcTimeDefault = "0001-01-01T00:00:00";
    String offsetTimeDefault = "0001-01-01T00:00:00-00:00";
    // Act
    Device device = Deencapsulation.newInstance(Device.class, new Class[] { String.class, DeviceStatus.class, SymmetricKey.class }, deviceId, null, null);
    // Assert
    assertEquals(deviceId, device.getDeviceId());
    assertNotEquals(null, device.getSymmetricKey());
    assertEquals("", device.getGenerationId());
    assertEquals("", device.geteTag());
    assertEquals(DeviceStatus.Enabled, device.getStatus());
    assertEquals("", device.getStatusReason());
    assertEquals(utcTimeDefault, device.getStatusUpdatedTime());
    assertEquals(DeviceConnectionState.Disconnected, device.getConnectionState());
    assertEquals(utcTimeDefault, device.getConnectionStateUpdatedTime());
    assertEquals(offsetTimeDefault, device.getLastActivityTime());
    assertEquals(0, device.getCloudToDeviceMessageCount());
    assertNull(device.getCapabilities());
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) DeviceStatus(com.microsoft.azure.sdk.iot.service.DeviceStatus) Test(org.junit.Test)

Example 38 with Device

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

the class DeviceTest method setScopeSetsScope.

@Test
public void setScopeSetsScope() {
    // arrange
    String scope = "scope";
    Device device = Device.createDevice("device", AuthenticationType.SAS);
    // act
    device.setScope(scope);
    // assert
    String actualScope = Deencapsulation.getField(device, "scope");
    assertEquals(scope, actualScope);
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Example 39 with Device

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

the class DeviceTest method conversionFromDeviceParserWithSASAuthentication.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_34_014: [This constructor shall create a new Device object using the values within the provided parser.]
@Test
public void conversionFromDeviceParserWithSASAuthentication() {
    // arrange
    String scope = "scope";
    DeviceParser parserSAS = new DeviceParser();
    parserSAS.setAuthenticationParser(Deencapsulation.newInstance(AuthenticationParser.class));
    parserSAS.getAuthenticationParser().setType(AuthenticationTypeParser.SAS);
    parserSAS.getAuthenticationParser().setSymmetricKey(new SymmetricKeyParser(SAMPLE_KEY, SAMPLE_KEY));
    parserSAS.setDeviceId("deviceSAS");
    parserSAS.setScope(scope);
    // act
    Device deviceSAS = reflectivelyInvokeDeviceParserConstructor(parserSAS);
    // assert
    assertNull(deviceSAS.getPrimaryThumbprint());
    assertNull(deviceSAS.getSecondaryThumbprint());
    assertNotNull(deviceSAS.getSymmetricKey());
    assertEquals(AuthenticationType.SAS, deviceSAS.getAuthenticationType());
    assertEquals(scope, deviceSAS.getScope());
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Example 40 with Device

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

the class DeviceTest method constructor2_create_initialize_properties.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_28_002: [The constructor shall set the deviceId and symmetricKey.]
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_28_003: [The constructor shall initialize all properties to default values]
@Test
public void constructor2_create_initialize_properties() {
    // Arrange
    String deviceId = "xxx-device";
    String utcTimeDefault = "0001-01-01T00:00:00";
    String offsetTimeDefault = "0001-01-01T00:00:00-00:00";
    // Act
    Device device = Deencapsulation.newInstance(Device.class, new Class[] { String.class, AuthenticationType.class }, deviceId, AuthenticationType.SAS);
    // Assert
    assertEquals(deviceId, device.getDeviceId());
    assertNotNull(device.getSymmetricKey());
    assertEquals("", device.getGenerationId());
    assertEquals("", device.geteTag());
    assertEquals(DeviceStatus.Enabled, device.getStatus());
    assertEquals("", device.getStatusReason());
    assertEquals(utcTimeDefault, device.getStatusUpdatedTime());
    assertEquals(DeviceConnectionState.Disconnected, device.getConnectionState());
    assertEquals(utcTimeDefault, device.getConnectionStateUpdatedTime());
    assertEquals(offsetTimeDefault, device.getLastActivityTime());
    assertEquals(0, device.getCloudToDeviceMessageCount());
    assertNull(device.getCapabilities());
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Aggregations

Device (com.microsoft.azure.sdk.iot.service.Device)68 Test (org.junit.Test)46 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)21 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)19 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)17 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)15 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)13 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)12 IOException (java.io.IOException)11 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)11 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)11 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)10 ArrayList (java.util.ArrayList)10 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)7 RegistryManagerOptions (com.microsoft.azure.sdk.iot.service.RegistryManagerOptions)5 AzureSasCredential (com.azure.core.credential.AzureSasCredential)4 DeviceCapabilities (com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities)4 ClientOptions (com.microsoft.azure.sdk.iot.device.ClientOptions)4 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)4 Module (com.microsoft.azure.sdk.iot.service.Module)4