Search in sources :

Example 11 with BaseDevice

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

the class BaseDeviceTest method constructor_initialize_properties.

// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_12_006: [The constructor shall initialize all properties to default value]
@Test
public void constructor_initialize_properties() {
    // Arrange
    String utcTimeDefault = "0001-01-01T00:00:00";
    String offsetTimeDefault = "0001-01-01T00:00:00-00:00";
    String deviceId = "xxx-device";
    // Act
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, deviceId, SymmetricKey.class);
    // Assert
    assertNotEquals(null, device);
    assertNotEquals(device.getSymmetricKey(), null);
    assertEquals("xxx-device", device.getDeviceId());
    assertEquals("", device.getGenerationId());
    assertEquals("", device.geteTag());
    assertEquals(DeviceConnectionState.Disconnected, device.getConnectionState());
    assertEquals(utcTimeDefault, device.getConnectionStateUpdatedTime());
    assertEquals(offsetTimeDefault, device.getLastActivityTime());
    assertEquals(0, device.getCloudToDeviceMessageCount());
}
Also used : BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 12 with BaseDevice

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

the class BaseDeviceTest method conversionToDeviceParserWithSelfSignedAuthentication.

// 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 conversionToDeviceParserWithSelfSignedAuthentication() {
    // arrange
    BaseDevice deviceSelf = Deencapsulation.newInstance(BaseDevice.class, "deviceSelf", AuthenticationType.SELF_SIGNED);
    // act
    DeviceParser parserSelf = reflectivelyInvokeToDeviceParser(deviceSelf);
    // assert
    assertEquals(AuthenticationTypeParser.SELF_SIGNED, parserSelf.getAuthenticationParser().getType());
}
Also used : BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 13 with BaseDevice

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

the class BaseDeviceTest method conversionToDeviceParserWithSASAuthentication.

// 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 conversionToDeviceParserWithSASAuthentication() {
    // arrange
    BaseDevice deviceSAS = Deencapsulation.newInstance(BaseDevice.class, "deviceSAS", AuthenticationType.SAS);
    // act
    DeviceParser parserSAS = reflectivelyInvokeToDeviceParser(deviceSAS);
    // assert
    assertEquals(AuthenticationTypeParser.SAS, parserSAS.getAuthenticationParser().getType());
}
Also used : BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 14 with BaseDevice

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

the class BaseDeviceTest method conversionFromDeviceParserWithCertificateAuthorityAuthentication.

// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_014: [This constructor shall create a new Device object using the values within the provided parser.]
@Test
public void conversionFromDeviceParserWithCertificateAuthorityAuthentication() {
    // arrange
    DeviceParser parserCA = new DeviceParser();
    parserCA.setAuthenticationParser(Deencapsulation.newInstance(AuthenticationParser.class));
    parserCA.getAuthenticationParser().setType(AuthenticationTypeParser.CERTIFICATE_AUTHORITY);
    parserCA.setDeviceId("deviceCA");
    // act
    BaseDevice deviceCA = reflectivelyInvokeDeviceParserConstructor(parserCA);
    // assert
    assertNull(deviceCA.getPrimaryThumbprint());
    assertNull(deviceCA.getSecondaryThumbprint());
    assertNull(deviceCA.getSymmetricKey());
    assertEquals(AuthenticationType.CERTIFICATE_AUTHORITY, deviceCA.getAuthenticationType());
}
Also used : BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 15 with BaseDevice

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

the class BaseDeviceTest method toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutPrimaryThumbprintSaved.

// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_020: [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
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SELF_SIGNED);
    X509Thumbprint thumbprint = Deencapsulation.newInstance(X509Thumbprint.class);
    Deencapsulation.setField(thumbprint, "primaryThumbprint", null);
    AuthenticationMechanism authentication = new AuthenticationMechanism(SAMPLE_THUMBPRINT, SAMPLE_THUMBPRINT);
    Deencapsulation.setField(authentication, "thumbprint", thumbprint);
    Deencapsulation.setField(device, "authentication", authentication);
    // act
    reflectivelyInvokeToDeviceParser(device);
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Aggregations

BaseDevice (com.microsoft.azure.sdk.iot.service.BaseDevice)17 Test (org.junit.Test)17 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)5 AuthenticationMechanism (com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism)4 X509Thumbprint (com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint)3 DeviceConnectionState (com.microsoft.azure.sdk.iot.service.DeviceConnectionState)1 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)1 NonStrictExpectations (mockit.NonStrictExpectations)1