use of org.onosproject.yang.model.ResourceId in project onos by opennetworkinglab.
the class ResourceIds method resourceId.
/**
* Builds the ResourceId of specified {@code node}.
*
* @param parent ResourceId of {@code node} parent
* @param node to create ResourceId.
* @return ResourceId of {@code node}
*/
public static ResourceId resourceId(ResourceId parent, DataNode node) {
final ResourceId.Builder builder;
if (parent == null) {
builder = ResourceId.builder();
} else {
try {
builder = parent.copyBuilder();
} catch (CloneNotSupportedException e) {
throw new IllegalArgumentException(e);
}
}
SchemaId sid = node.key().schemaId();
switch(node.type()) {
case MULTI_INSTANCE_LEAF_VALUE_NODE:
builder.addLeafListBranchPoint(sid.name(), sid.namespace(), ((LeafListKey) node.key()).asString());
break;
case MULTI_INSTANCE_NODE:
builder.addBranchPointSchema(sid.name(), sid.namespace());
for (KeyLeaf keyLeaf : ((ListKey) node.key()).keyLeafs()) {
builder.addKeyLeaf(keyLeaf.leafSchema().name(), keyLeaf.leafSchema().namespace(), keyLeaf.leafValAsString());
}
break;
case SINGLE_INSTANCE_LEAF_VALUE_NODE:
case SINGLE_INSTANCE_NODE:
builder.addBranchPointSchema(sid.name(), sid.namespace());
break;
default:
throw new IllegalArgumentException("Unknown type " + node);
}
return builder.build();
}
use of org.onosproject.yang.model.ResourceId in project onos by opennetworkinglab.
the class DeviceResourceIdsTest method testDeviceSubtreeEventTest.
@Test
public void testDeviceSubtreeEventTest() {
// root relative ResourceId used by DynamicConfigEvent
ResourceId evtDevice = ResourceId.builder().addBranchPointSchema(DEVICES_NAME, DCS_NAMESPACE).addBranchPointSchema(DEVICE_NAME, DCS_NAMESPACE).addKeyLeaf(DEVICE_ID_KL_NAME, DCS_NAMESPACE, DID_A.toString()).build();
NodeKey<?> deviceKey = evtDevice.nodeKeys().get(1);
assertThat(deviceKey, is(instanceOf(ListKey.class)));
assertThat(deviceKey.schemaId().namespace(), is(equalTo(DCS_NAMESPACE)));
assertThat(deviceKey.schemaId().name(), is(equalTo(DEVICE_NAME)));
assertTrue(DeviceResourceIds.isUnderDeviceRootNode(evtDevice));
}
use of org.onosproject.yang.model.ResourceId in project onos by opennetworkinglab.
the class DeviceResourceIdsTest method testToDeviceId.
@Test
public void testToDeviceId() throws CloneNotSupportedException {
ResourceId ridAchild = ridA.copyBuilder().addBranchPointSchema("some", "ns").addBranchPointSchema("random", "ns").addBranchPointSchema("child", "ns").build();
assertEquals(DID_A, DeviceResourceIds.toDeviceId(ridAchild));
NodeKey<?> nodeKey = ridA.nodeKeys().get(2);
assertThat(nodeKey, is(instanceOf(ListKey.class)));
assertThat(nodeKey.schemaId(), is(equalTo(new SchemaId(DEVICE_NAME, DCS_NAMESPACE))));
ListKey listKey = (ListKey) nodeKey;
assertThat(listKey.keyLeafs(), is(contains(new KeyLeaf(DEVICE_ID_KL_NAME, DCS_NAMESPACE, DID_A.toString()))));
}
use of org.onosproject.yang.model.ResourceId in project onos by opennetworkinglab.
the class DynamicDeviceConfigServiceViewTest method testListener.
// FIXME add test scenario where irrelevant event get discarded.
@Test
public void testListener() throws CloneNotSupportedException, InterruptedException {
ResourceId realIntf = ResourceId.builder().append(rid).addBranchPointSchema("intf", "test").build();
final CountDownLatch received = new CountDownLatch(1);
DynamicConfigListener lsnr = new DynamicConfigListener() {
@Override
public boolean isRelevant(DynamicConfigEvent event) {
viewRelevantEvent = event;
return true;
}
@Override
public void event(DynamicConfigEvent event) {
viewEvent = event;
received.countDown();
}
};
view.addListener(lsnr);
service.post(new DynamicConfigEvent(Type.NODE_ADDED, realIntf));
assertTrue(received.await(5, TimeUnit.SECONDS));
assertFalse("Expect relative path but was" + viewRelevantEvent.subject(), ResourceIds.isPrefix(rid, viewRelevantEvent.subject()));
assertFalse("Expect relative path but was" + viewEvent.subject(), ResourceIds.isPrefix(rid, viewEvent.subject()));
view.removeListener(lsnr);
}
use of org.onosproject.yang.model.ResourceId in project onos by opennetworkinglab.
the class ResourceIdsTest method testConcat.
@Test
public void testConcat() {
ResourceId devices = ResourceId.builder().addBranchPointSchema(DeviceResourceIds.DEVICES_NAME, DCS_NAMESPACE).build();
assertEquals(DEVICES, ResourceIds.concat(ResourceIds.ROOT_ID, devices));
}
Aggregations