use of org.onosproject.net.key.DeviceKeyId in project onos by opennetworkinglab.
the class DeviceKeyManagerTest method testAddKey.
/**
* Tests adding a device key using the device key manager.
* This also tests the device key manager query methods.
*/
@Test
public void testAddKey() {
DeviceKeyId deviceKeyId = DeviceKeyId.deviceKeyId(deviceKeyIdValue);
DeviceKey deviceKey = DeviceKey.createDeviceKeyUsingCommunityName(deviceKeyId, deviceKeyLabel, deviceKeySnmpName);
// Test to make sure that the device key store is empty
Collection<DeviceKey> deviceKeys = manager.getDeviceKeys();
assertTrue("The device key set should be empty.", deviceKeys.isEmpty());
// Add the new device key using the device key manager.
manager.addKey(deviceKey);
// Test the getDeviceKeys method to make sure that the new device key exists
deviceKeys = manager.getDeviceKeys();
assertEquals("There should be one device key in the set.", deviceKeys.size(), 1);
// Test the getDeviceKey method using the device key unique identifier
deviceKey = manager.getDeviceKey(deviceKeyId);
assertEquals("There should be one device key in the set.", deviceKeys.size(), 1);
// Validate that only the DEVICE_KEY_ADDED event was received.
validateEvents(DeviceKeyEvent.Type.DEVICE_KEY_ADDED);
}
use of org.onosproject.net.key.DeviceKeyId in project onos by opennetworkinglab.
the class DeviceKeyManagerTest method testRemoveKey.
/**
* Tests removal of a device key from the store using the device key identifier.
*/
@Test
public void testRemoveKey() {
DeviceKeyId deviceKeyId = DeviceKeyId.deviceKeyId(deviceKeyIdValue);
DeviceKey deviceKey = DeviceKey.createDeviceKeyUsingCommunityName(deviceKeyId, deviceKeyLabel, deviceKeySnmpName);
// Add the new device key using the device key manager
manager.addKey(deviceKey);
// Remove the device key from the store
manager.removeKey(deviceKeyId);
// Validate that the device key was removed from the store by querying it.
deviceKey = manager.getDeviceKey(deviceKeyId);
assertNull("The device key set should be empty.", deviceKey);
// Validate that the following events were received in order,
// DEVICE_KEY_ADDED, DEVICE_KEY_REMOVED.
validateEvents(DeviceKeyEvent.Type.DEVICE_KEY_ADDED, DeviceKeyEvent.Type.DEVICE_KEY_REMOVED);
}
use of org.onosproject.net.key.DeviceKeyId in project onos by opennetworkinglab.
the class DeviceKeyManagerTest method testAddSameKey.
/**
* Tests re-adding the same device key to the store but with a different label.
*/
@Test
public void testAddSameKey() {
DeviceKeyId deviceKeyId = DeviceKeyId.deviceKeyId(deviceKeyIdValue);
DeviceKey deviceKey = DeviceKey.createDeviceKeyUsingCommunityName(deviceKeyId, deviceKeyLabel, deviceKeySnmpName);
// Add the first device key via the device key manager
manager.addKey(deviceKey);
// Test the getDeviceKeys method
Collection<DeviceKey> deviceKeys = manager.getDeviceKeys();
assertEquals("There should be one device key in the set.", deviceKeys.size(), 1);
// Now let's create a new device key with the same device key identifier as exists in the store.
DeviceKey deviceKey2 = DeviceKey.createDeviceKeyUsingCommunityName(deviceKeyId, deviceKeyLabel2, deviceKeySnmpName);
// Replace the new device key in the store
manager.addKey(deviceKey2);
// Test the getDeviceKeys method to ensure that only 1 device key exists in the store.
deviceKeys = manager.getDeviceKeys();
assertEquals("There should be one device key in the set.", deviceKeys.size(), 1);
// Test the getDeviceKey method using the device key unique identifier
deviceKey = manager.getDeviceKey(deviceKeyId);
assertNotNull("The device key should not be null.", deviceKey);
assertEquals("The device key label should match.", deviceKeyLabel2, deviceKey.label());
// Validate that the following events were received in order,
// DEVICE_KEY_ADDED, DEVICE_KEY_REMOVED, DEVICE_KEY_ADDED.
validateEvents(DeviceKeyEvent.Type.DEVICE_KEY_ADDED, DeviceKeyEvent.Type.DEVICE_KEY_UPDATED);
}
use of org.onosproject.net.key.DeviceKeyId in project onos by opennetworkinglab.
the class DeviceKeyCodec method decode.
@Override
public DeviceKey decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
DeviceKeyId id = DeviceKeyId.deviceKeyId(json.get(ID).asText());
DeviceKey.Type type = DeviceKey.Type.valueOf(json.get(TYPE).asText());
String label = extract(json, LABEL);
if (type.equals(DeviceKey.Type.COMMUNITY_NAME)) {
String communityName = extract(json, COMMUNITY_NAME);
return DeviceKey.createDeviceKeyUsingCommunityName(id, label, communityName);
} else if (type.equals(DeviceKey.Type.USERNAME_PASSWORD)) {
String username = extract(json, USERNAME);
String password = extract(json, PASSWORD);
return DeviceKey.createDeviceKeyUsingUsernamePassword(id, label, username, password);
} else {
log.error("Unknown device key type: ", type);
return null;
}
}
use of org.onosproject.net.key.DeviceKeyId in project onos by opennetworkinglab.
the class DistributedDeviceKeyStoreTest method testAddKey.
/**
* Tests adding a device key to the store. This also tests the device key store
* query methods.
*/
@Test
public void testAddKey() {
DeviceKeyId deviceKeyId = DeviceKeyId.deviceKeyId(deviceKeyIdValue);
DeviceKey deviceKey = DeviceKey.createDeviceKeyUsingCommunityName(deviceKeyId, deviceKeyLabel, deviceKeySnmpName);
// Test to make sure that the device key store is empty
Collection<DeviceKey> deviceKeys = deviceKeyStore.getDeviceKeys();
assertTrue("The device key set should be empty.", deviceKeys.isEmpty());
// Add the new device key to the store
deviceKeyStore.createOrUpdateDeviceKey(deviceKey);
// Test the getDeviceKeys method to make sure that the new device key exists
deviceKeys = deviceKeyStore.getDeviceKeys();
assertEquals("There should be one device key in the set.", deviceKeys.size(), 1);
// Test the getDeviceKey method using the device key unique identifier
deviceKey = deviceKeyStore.getDeviceKey(deviceKeyId);
assertEquals("There should be one device key in the set.", deviceKeys.size(), 1);
}
Aggregations