AlarmUtil { public static ModelNodeId toNodeIdUsingNodeElement(String dbId, Element element) { ModelNodeId modelNodeId = new ModelNodeId(); String moduleNamespace = null; LocationPath locationPath = AlarmUtil.buildLocationPath(dbId); Step[] steps = locationPath.getSteps(); for (Step stepNode : steps) { moduleNamespace = buildNodeIdUsingNodeElement(element, null, modelNodeId, stepNode, moduleNamespace); Expression[] predicates = stepNode.getPredicates(); if (predicates != null) { for (int predicateCount = 0; predicateCount < predicates.length; predicateCount++) { moduleNamespace = buildNodeIdUsingNodeElement(element, null, modelNodeId, predicates[predicateCount], moduleNamespace); } } } return modelNodeId; } private  AlarmUtil(); static Step[] splitXpathByJXPath(String xPath); static Map<String, Pair<String, SchemaRegistry>> getPrefixToNsMap(ModelNodeId modelNodeId, ModelNodeDataStoreManager dsm,
                                                                             SchemaRegistry schemaRegistry, String mountKey); static ModelNodeId toNodeIdUsingNodeElement(String dbId, Element element); static ModelNodeId toNodeIdUsingRegistry(String dbId, SchemaRegistry registry); static Alarm convertToAlarmEntity(AlarmInfo alarmInfo, String dbId); static List<AlarmInfo> convertAlarmToAlarmInfoList(List<Alarm> existingBaaAlarms, SchemaRegistry schemaRegistry,
                                                              ModelNodeDataStoreManager dsm); static String xPathAlarmString(Map<String, Pair<String, SchemaRegistry>> prefixToNsMap, ModelNodeId modelNodeId); static String toDbId(SchemaRegistry schemaRegistry, ModelNodeDataStoreManager dsm, ModelNodeId modelNodeId,
                                Map<String, Pair<String, SchemaRegistry>> prefixToNsMap); static QName getNodeName(Step stepNode); static ModelNodeId toNodeId(SchemaRegistry schemaRegistry, ModelNodeDataStoreManager dsm, String dbId,
                                       String mountRegistryKey); static ModelNodeId toNodeId(SchemaRegistry schemaRegistry, ModelNodeDataStoreManager dsm, String dbId); static String xPathString(Map<String, Pair<String, SchemaRegistry>> prefixToNsMap, NamespaceContext nsContext,
                                     ModelNodeId modelNodeId);  }
@Test public void testToNodeIdUsingNodeElement() throws NetconfMessageBuilderException { String alarmElement = "<alarms:alarm xmlns:alarms=\"urn:ietf:params:xml:ns:yang:ietf-alarms\">" + "<alarms:resource xmlns:if=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\" xmlns:baa=\"http: + "xmlns:adh=\"http: + "/adh:device[adh:ID='R1.S1.LT1.P1.ONT1']/adh:device-specific-data/if:interfaces/if:interface[if:name='xdsl-line:1/1/1/1']</alarms:resource>" + "</alarms:alarm>"; Element element = DocumentUtils.stringToDocument(alarmElement).getDocumentElement(); ModelNodeId actualNodeId = AlarmUtil.toNodeIdUsingNodeElement(DB_ID_WITH_INTF, (Element) element.getChildNodes().item(0)); assertEquals(INTF_MODEL_NODE_ID, actualNodeId); }
@Test public void testToNodeIdUsingNodeElementWhenNamespaceMissingException() throws NetconfMessageBuilderException { String alarmElement = "<alarms:alarm xmlns:alarms=\"urn:ietf:params:xml:ns:yang:ietf-alarms\">" + "<alarms:resource>/baa:device-manager/adh:device-holder[adh:name='OLT-2345']" + "/adh:device[adh:ID='R1.S1.LT1.P1.ONT1']/adh:device-specific-data/if:interfaces/if:interface[if:name='xdsl-line:1/1/1/1']</alarms:resource>" + "</alarms:alarm>"; Element element = DocumentUtils.stringToDocument(alarmElement).getDocumentElement(); m_expectedException.expect(AlarmProcessingException.class); m_expectedException.expectMessage("Namespace is missing for prefix 'baa' in resource"); AlarmUtil.toNodeIdUsingNodeElement(DB_ID_WITH_INTF, (Element) element.getChildNodes().item(0)); }