Search in sources :

Example 6 with DeviceKeyId

use of org.onosproject.net.key.DeviceKeyId in project onos by opennetworkinglab.

the class DistributedDeviceKeyStoreTest 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 to the store
    deviceKeyStore.createOrUpdateDeviceKey(deviceKey);
    // Remove the device key from the store
    deviceKeyStore.deleteDeviceKey(deviceKeyId);
    // Validate that the device key was removed from the store by querying it.
    deviceKey = deviceKeyStore.getDeviceKey(deviceKeyId);
    assertNull("The device key set should be empty.", deviceKey);
}
Also used : DeviceKeyId(org.onosproject.net.key.DeviceKeyId) DeviceKey(org.onosproject.net.key.DeviceKey) Test(org.junit.Test)

Example 7 with DeviceKeyId

use of org.onosproject.net.key.DeviceKeyId in project onos by opennetworkinglab.

the class DistributedDeviceKeyStoreTest 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 to the store
    deviceKeyStore.createOrUpdateDeviceKey(deviceKey);
    // Test the getDeviceKeys method
    Collection<DeviceKey> deviceKeys = deviceKeyStore.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
    deviceKeyStore.createOrUpdateDeviceKey(deviceKey2);
    // Test the getDeviceKeys method to ensure that only 1 device key exists in the store.
    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);
    assertNotNull("The device key should not be null.", deviceKey);
    assertEquals("The device key label should match.", deviceKeyLabel2, deviceKey.label());
}
Also used : DeviceKeyId(org.onosproject.net.key.DeviceKeyId) DeviceKey(org.onosproject.net.key.DeviceKey) Test(org.junit.Test)

Aggregations

DeviceKey (org.onosproject.net.key.DeviceKey)7 DeviceKeyId (org.onosproject.net.key.DeviceKeyId)7 Test (org.junit.Test)6