AlarmsDocumentTransformer extends PojoToDocumentTransformer { public Element getAlarmRpcOutputElement(String namespace, String offsetValue, List<AlarmParameters> alarmParameters) throws NetconfMessageBuilderException { String prefix = null; if (m_schemaRegistry != null) { prefix = getPrefix(namespace, null); } try { m_doc = DocumentUtils.getNewDocument(); } catch (ParserConfigurationException e) { throw new NetconfMessageBuilderException(ERROR_WHILE_BUILDING_DOCUMENT, e); } Element alarmRpcOutputElement = m_doc.createElementNS(namespace, buildLocalName(prefix, AlarmConstants.ACTIVE_ALARMS)); if (offsetValue != null) { appendChild(alarmRpcOutputElement, namespace, buildLocalName(prefix, AlarmConstants.OFFSET), offsetValue); } for (AlarmParameters alarmParameter : alarmParameters) { Element alarmElement = buildAlarmParameters(namespace, prefix, alarmParameter); alarmRpcOutputElement.appendChild(alarmElement); } return alarmRpcOutputElement; } AlarmsDocumentTransformer(SchemaRegistry schemaRegistry, ModelNodeDataStoreManager dsm); Element buildAlarmParameters(String namespace, String prefix, AlarmParameters alarmParameters); Element getAlarmNotificationElement(AlarmNotification alarmNotif); Element buildAlarmNotification(AlarmNotification alarmNotif, String alarmNS); Element getAlarmRpcOutputElement(String namespace, String offsetValue, List<AlarmParameters> alarmParameters);  }
@Test public void testAlarmRpcOutputElement() throws Exception { long timeInMillis = 1465967097648L; Timestamp now = new Timestamp(timeInMillis); AlarmParameters parameter = new AlarmParameters( "{baa-network-manager}(http: TEST_RESOURCE, now, AlarmSeverity.CRITICAL, "Test"); Element expectedAlarmRpcElement = loadAsXml(EXPECTED_ALARM_RPC_OUTPUT_DEVICE_HOLDER); Element alarmRpcOutputElement = new AlarmsDocumentTransformer(m_schemaRegistry, null) .getAlarmRpcOutputElement(AlarmTestConstants.NETWORK_MANAGER_NAMESPACE, "1", Arrays.asList(parameter)); assertXMLEquals(expectedAlarmRpcElement, alarmRpcOutputElement, m_ignoreElements); expectedAlarmRpcElement = loadAsXml(EXPECTED_ALARM_RPC_OUTPUT); alarmRpcOutputElement = new AlarmsDocumentTransformer(m_schemaRegistry, null).getAlarmRpcOutputElement(AlarmConstants.ALARM_NAMESPACE, "1", Arrays.asList(parameter)); assertXMLEquals(expectedAlarmRpcElement, alarmRpcOutputElement, m_ignoreElements); }
@Test public void testGetActiveAlarmRpcOutputElementWithNonYangResourceString() throws Exception { long timeInMillis = 1465967097648L; Timestamp now = new Timestamp(timeInMillis); AlarmParameters parameter = new AlarmParameters( "{baa-network-manager}(http: "", null, now, AlarmSeverity.CRITICAL, "Test", null, NON_YANG_RESOURCE_STRING); Element expectedAlarmRpcElement = loadAsXml(EXPECTED_GET_ALARM_RPC_OUTPUT_WITH_NON_YANG_RESOURCE); Element alarmRpcOutputElement = new AlarmsDocumentTransformer(m_schemaRegistry, null) .getAlarmRpcOutputElement(AlarmTestConstants.NETWORK_MANAGER_NAMESPACE, "1", Arrays.asList(parameter)); assertXMLEquals(expectedAlarmRpcElement, alarmRpcOutputElement, m_ignoreElements); }
@Test public void testAlarmRpcOutputElementWithNoSchemaRegistry() throws Exception { long timeInMillis = 1465967097648L; Timestamp now = new Timestamp(timeInMillis); AlarmParameters parameter = new AlarmParameters( "(http: TEST_RESOURCE, now, AlarmSeverity.CRITICAL, "Test"); Element alarmRpcOutputElement = new AlarmsDocumentTransformer(null, null) .getAlarmRpcOutputElement(AlarmTestConstants.NETWORK_MANAGER_NAMESPACE, "1", Arrays.asList(parameter)); NodeList nodes = alarmRpcOutputElement.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { assertFalse(nodes.item(i).getNodeName().contains("baa-network-manager:")); } alarmRpcOutputElement = new AlarmsDocumentTransformer(null, null).getAlarmRpcOutputElement(AlarmConstants.ALARM_NAMESPACE, "1", Arrays.asList(parameter)); nodes = alarmRpcOutputElement.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { assertFalse(nodes.item(i).getNodeName().contains("alarms:")); } }