Search in sources :

Example 6 with BaseDevice

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

the class BaseDeviceTest method constructor_sets_status_and_symmetrickey.

// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_15_007: [The constructor shall store
// the input device status and symmetric key into a member variable]
@Test
public void constructor_sets_status_and_symmetrickey() throws NoSuchAlgorithmException {
    // Arrange
    String deviceId = "xxx-device";
    DeviceStatus expectedDeviceStatus = DeviceStatus.Disabled;
    SymmetricKey expectedSymmetricKey = new SymmetricKey();
    // Act
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, deviceId, expectedSymmetricKey);
    // Assert
    assertEquals(expectedSymmetricKey, device.getSymmetricKey());
}
Also used : SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) DeviceStatus(com.microsoft.azure.sdk.iot.service.DeviceStatus) BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 7 with BaseDevice

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

the class BaseDeviceTest method deviceConstructorWithSharedAccessSignatureGeneratesKeysCorrectly.

// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_012: [If the provided authenticationType is SAS, a symmetric key shall be generated but no thumbprint shall be generated]
@Test
public void deviceConstructorWithSharedAccessSignatureGeneratesKeysCorrectly() {
    // act
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SAS);
    // assert
    assertNull(device.getPrimaryThumbprint());
    assertNull(device.getSecondaryThumbprint());
    assertNotNull(device.getSymmetricKey());
    assertNotNull(device.getPrimaryKey());
    assertNotNull(device.getSecondaryKey());
}
Also used : BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 8 with BaseDevice

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

the class BaseDeviceTest method toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutSymmetricKeySaved.

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

Example 9 with BaseDevice

use of com.microsoft.azure.sdk.iot.service.BaseDevice 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)

Example 10 with BaseDevice

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

the class BaseDeviceTest method conversionFromDeviceParserWithSASAuthentication.

// 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 conversionFromDeviceParserWithSASAuthentication() {
    // arrange
    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");
    // act
    BaseDevice deviceSAS = reflectivelyInvokeDeviceParserConstructor(parserSAS);
    // assert
    assertNull(deviceSAS.getPrimaryThumbprint());
    assertNull(deviceSAS.getSecondaryThumbprint());
    assertNotNull(deviceSAS.getSymmetricKey());
    assertEquals(AuthenticationType.SAS, deviceSAS.getAuthenticationType());
}
Also used : 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