Search in sources :

Example 1 with DeviceConnectionState

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

the class ModuleTest method conversionToDeviceParser.

// Tests_SRS_SERVICE_SDK_JAVA_MODULE_28_010: [This method shall return a new instance of a DeviceParser object that is populated using the properties of this.]
@Test
public void conversionToDeviceParser() {
    // arrange
    String expectedDeviceId = "deviceCA";
    String expectedModuleId = "moduleCA";
    int expectedCloudToDeviceMessageCount = 23;
    DeviceConnectionState expectedConnectionState = DeviceConnectionState.Connected;
    String expectedConnectionStateUpdatedTime = "2001-09-09T09:09:09";
    String expectedETag = "1234";
    String expectedGenerationId = "5678";
    String expectedLastActivityTime = "2001-09-09T09:09:09";
    String expectedManagedBy = "jkik";
    Module module = Module.createModule(expectedDeviceId, expectedModuleId, AuthenticationType.SAS);
    Deencapsulation.setField(module, "cloudToDeviceMessageCount", expectedCloudToDeviceMessageCount);
    Deencapsulation.setField(module, "connectionState", expectedConnectionState);
    Deencapsulation.setField(module, "connectionStateUpdatedTime", expectedConnectionStateUpdatedTime);
    Deencapsulation.setField(module, "eTag", expectedETag);
    Deencapsulation.setField(module, "generationId", expectedGenerationId);
    Deencapsulation.setField(module, "lastActivityTime", expectedLastActivityTime);
    Deencapsulation.setField(module, "managedBy", expectedManagedBy);
    // act
    DeviceParser parser = reflectivelyInvokeToDeviceParser(module);
    // assert
    assertEquals(AuthenticationTypeParser.SAS, parser.getAuthenticationParser().getType());
    assertEquals(expectedCloudToDeviceMessageCount, parser.getCloudToDeviceMessageCount());
    assertEquals(expectedConnectionState.toString(), parser.getConnectionState());
    assertEquals(ParserUtility.getDateTimeUtc(expectedConnectionStateUpdatedTime), parser.getConnectionStateUpdatedTime());
    assertEquals(expectedDeviceId, parser.getDeviceId());
    assertEquals(expectedModuleId, parser.getModuleId());
    assertEquals("\"" + expectedETag + "\"", parser.geteTag());
    assertEquals(expectedGenerationId, parser.getGenerationId());
    assertEquals(ParserUtility.getDateTimeUtc(expectedLastActivityTime), parser.getLastActivityTime());
    assertEquals(expectedManagedBy, parser.getManagedBy());
}
Also used : DeviceConnectionState(com.microsoft.azure.sdk.iot.service.DeviceConnectionState) Module(com.microsoft.azure.sdk.iot.service.Module) Test(org.junit.Test)

Example 2 with DeviceConnectionState

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

the class DeviceTest method conversionToDeviceParser.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_34_018: [This method shall return a new instance of a DeviceParser object that is populated using the properties of this.]
@Test
public void conversionToDeviceParser() {
    // arrange
    String expectedDeviceId = "deviceCA";
    DeviceStatus expectedDeviceStatus = DeviceStatus.Disabled;
    String expectedStatusReason = "no reason";
    String expectedStatusUpdatedTime = "2001-09-09T09:09:09";
    int expectedCloudToDeviceMessageCount = 23;
    DeviceConnectionState expectedConnectionState = DeviceConnectionState.Connected;
    String expectedConnectionStateUpdatedTime = "2001-09-09T09:09:09";
    String expectedETag = "1234";
    String expectedGenerationId = "5678";
    String expectedLastActivityTime = "2001-09-09T09:09:09";
    Boolean expectedCapabilities = false;
    String scope = "scope";
    Device device = Device.createDevice(expectedDeviceId, AuthenticationType.CERTIFICATE_AUTHORITY);
    device.setStatus(expectedDeviceStatus);
    Deencapsulation.setField(device, "statusReason", expectedStatusReason);
    Deencapsulation.setField(device, "statusUpdatedTime", expectedStatusUpdatedTime);
    Deencapsulation.setField(device, "cloudToDeviceMessageCount", expectedCloudToDeviceMessageCount);
    Deencapsulation.setField(device, "connectionState", expectedConnectionState);
    Deencapsulation.setField(device, "connectionStateUpdatedTime", expectedConnectionStateUpdatedTime);
    Deencapsulation.setField(device, "eTag", expectedETag);
    Deencapsulation.setField(device, "generationId", expectedGenerationId);
    Deencapsulation.setField(device, "lastActivityTime", expectedLastActivityTime);
    Deencapsulation.setField(device, "capabilities", new DeviceCapabilities());
    Deencapsulation.setField(device, "scope", scope);
    device.getCapabilities().setIotEdge(expectedCapabilities);
    // act
    DeviceParser parser = reflectivelyInvokeToDeviceParser(device);
    // assert
    assertEquals(AuthenticationTypeParser.CERTIFICATE_AUTHORITY, parser.getAuthenticationParser().getType());
    assertEquals(expectedDeviceStatus.toString(), parser.getStatus());
    assertEquals(expectedDeviceStatus.toString(), parser.getStatus());
    assertEquals(expectedStatusReason, parser.getStatusReason());
    assertEquals(ParserUtility.getDateTimeUtc(expectedStatusUpdatedTime), parser.getStatusUpdatedTime());
    assertEquals(expectedCloudToDeviceMessageCount, parser.getCloudToDeviceMessageCount());
    assertEquals(expectedConnectionState.toString(), parser.getConnectionState());
    assertEquals(ParserUtility.getDateTimeUtc(expectedConnectionStateUpdatedTime), parser.getConnectionStateUpdatedTime());
    assertEquals(expectedDeviceId, parser.getDeviceId());
    assertEquals("\"" + expectedETag + "\"", parser.geteTag());
    assertEquals(expectedGenerationId, parser.getGenerationId());
    assertEquals(ParserUtility.getDateTimeUtc(expectedLastActivityTime), parser.getLastActivityTime());
    assertEquals(expectedCapabilities, parser.getCapabilities().getIotEdge());
    assertEquals(parser.getScope(), scope);
}
Also used : DeviceConnectionState(com.microsoft.azure.sdk.iot.service.DeviceConnectionState) Device(com.microsoft.azure.sdk.iot.service.Device) DeviceStatus(com.microsoft.azure.sdk.iot.service.DeviceStatus) DeviceCapabilities(com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities) Test(org.junit.Test)

Example 3 with DeviceConnectionState

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

the class BaseDeviceTest method conversionToDeviceParser.

// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_018: [This method shall return a new instance of a DeviceParser object that is populated using the properties of this.]
@Test
public void conversionToDeviceParser() {
    // arrange
    String expectedDeviceId = "deviceCA";
    boolean expectedForceUpdate = false;
    int expectedCloudToDeviceMessageCount = 23;
    DeviceConnectionState expectedConnectionState = DeviceConnectionState.Connected;
    String expectedConnectionStateUpdatedTime = "2001-09-09T09:09:09";
    String expectedETag = "1234";
    String expectedGenerationId = "5678";
    String expectedLastActivityTime = "2001-09-09T09:09:09";
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, expectedDeviceId, AuthenticationType.CERTIFICATE_AUTHORITY);
    Deencapsulation.setField(device, "cloudToDeviceMessageCount", expectedCloudToDeviceMessageCount);
    Deencapsulation.setField(device, "connectionState", expectedConnectionState);
    Deencapsulation.setField(device, "connectionStateUpdatedTime", expectedConnectionStateUpdatedTime);
    Deencapsulation.setField(device, "eTag", expectedETag);
    Deencapsulation.setField(device, "generationId", expectedGenerationId);
    Deencapsulation.setField(device, "lastActivityTime", expectedLastActivityTime);
    // act
    DeviceParser parser = reflectivelyInvokeToDeviceParser(device);
    // assert
    assertEquals(AuthenticationTypeParser.CERTIFICATE_AUTHORITY, parser.getAuthenticationParser().getType());
    assertEquals(expectedCloudToDeviceMessageCount, parser.getCloudToDeviceMessageCount());
    assertEquals(expectedConnectionState.toString(), parser.getConnectionState());
    assertEquals(expectedDeviceId, parser.getDeviceId());
    assertEquals("\"" + expectedETag + "\"", parser.geteTag());
    assertEquals(expectedGenerationId, parser.getGenerationId());
    assertEquals(ParserUtility.getDateTimeUtc(expectedLastActivityTime), parser.getLastActivityTime());
}
Also used : DeviceConnectionState(com.microsoft.azure.sdk.iot.service.DeviceConnectionState) X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Aggregations

DeviceConnectionState (com.microsoft.azure.sdk.iot.service.DeviceConnectionState)3 Test (org.junit.Test)3 DeviceCapabilities (com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities)1 BaseDevice (com.microsoft.azure.sdk.iot.service.BaseDevice)1 Device (com.microsoft.azure.sdk.iot.service.Device)1 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)1 Module (com.microsoft.azure.sdk.iot.service.Module)1 X509Thumbprint (com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint)1