use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.
the class SymmetricKeyParserTest method testGettersAndSetters.
// Tests_SRS_SymmetricKeyParser_34_001: [This method shall return the value of primaryKey]
// Tests_SRS_SymmetricKeyParser_34_003: [This method shall set the value of primaryKey to the provided value.]
// Tests_SRS_SymmetricKeyParser_34_004: [This method shall return the value of secondaryKey]
// Tests_SRS_SymmetricKeyParser_34_006: [This method shall set the value of secondaryKey to the provided value.]
@Test
public void testGettersAndSetters() {
// arrange
SymmetricKeyParser parser = new SymmetricKeyParser(TEST_KEY1, TEST_KEY2);
// act
parser.setPrimaryKey(TEST_KEY2);
parser.setSecondaryKey(TEST_KEY1);
// assert
assertEquals(TEST_KEY2, parser.getPrimaryKeyFinal());
assertEquals(TEST_KEY1, parser.getSecondaryKeyFinal());
}
use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.
the class SymmetricKeyParserTest method testToJson.
// Tests_SRS_SymmetricKeyParser_34_007: [The parser shall return a json representation of the provided SymmetricKeyParser.]
@Test
public void testToJson() {
// arrange
SymmetricKeyParser parser = new SymmetricKeyParser(TEST_KEY1, TEST_KEY2);
String expectedJson = "{\"primaryKey\":\"" + TEST_KEY1 + "\",\"secondaryKey\":\"" + TEST_KEY2 + "\"}";
// act
String actualJson = parser.toJson();
// assert
assertEquals(expectedJson, actualJson);
}
use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.
the class Tools method addModules.
private static void addModules(Iterable<Module> modules, String connectionString) throws IOException, IotHubException {
if (modules == null) {
throw new IllegalArgumentException("modules cannot be null");
}
IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
URL url = getBulkDeviceAddUrl(iotHubConnectionString);
List<ExportImportDeviceParser> parsers = new ArrayList<>();
for (Module module : modules) {
ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
exportImportDevice.setId(module.getDeviceId());
exportImportDevice.setModuleId(module.getId());
AuthenticationParser authenticationParser = new AuthenticationParser();
if (module.getAuthenticationType() == AuthenticationType.SAS) {
authenticationParser.setType(AuthenticationTypeParser.SAS);
authenticationParser.setSymmetricKey(new SymmetricKeyParser(module.getSymmetricKey().getPrimaryKey(), module.getSymmetricKey().getSecondaryKey()));
} else {
authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
authenticationParser.setThumbprint(new X509ThumbprintParser(module.getPrimaryThumbprint(), module.getSecondaryThumbprint()));
}
exportImportDevice.setAuthentication(authenticationParser);
exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
parsers.add(exportImportDevice);
}
ExportImportDevicesParser body = new ExportImportDevicesParser();
body.setExportImportDevices(parsers);
bulkRegistryOperation(body.toJson(), url, connectionString);
}
use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.
the class Tools method addDevices.
private static void addDevices(Iterable<Device> devices, String connectionString) throws IOException, IotHubException {
if (devices == null) {
throw new IllegalArgumentException("devices cannot be null");
}
IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
URL url = getBulkDeviceAddUrl(iotHubConnectionString);
List<ExportImportDeviceParser> parsers = new ArrayList<>();
for (Device device : devices) {
ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
exportImportDevice.setId(device.getDeviceId());
AuthenticationParser authenticationParser = new AuthenticationParser();
if (device.getAuthenticationType() == AuthenticationType.SAS) {
authenticationParser.setType(AuthenticationTypeParser.SAS);
authenticationParser.setSymmetricKey(new SymmetricKeyParser(device.getSymmetricKey().getPrimaryKey(), device.getSymmetricKey().getSecondaryKey()));
} else {
authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
authenticationParser.setThumbprint(new X509ThumbprintParser(device.getPrimaryThumbprint(), device.getSecondaryThumbprint()));
}
exportImportDevice.setAuthentication(authenticationParser);
exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
parsers.add(exportImportDevice);
}
ExportImportDevicesParser body = new ExportImportDevicesParser();
body.setExportImportDevices(parsers);
bulkRegistryOperation(body.toJson(), url, connectionString);
}
use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.
the class SymmetricKeyParserTest method setSecondaryKeyNullValueThrowsIllegalArgumentException.
// Tests_SRS_SymmetricKeyParser_34_005: [If the provided secondaryKey value is null, an IllegalArgumentException shall be thrown.]
@Test(expected = IllegalArgumentException.class)
public void setSecondaryKeyNullValueThrowsIllegalArgumentException() {
// arrange
SymmetricKeyParser parser = new SymmetricKeyParser("", "");
// act
parser.setSecondaryKey(null);
}
Aggregations