@Test public void testGetResourceByNodeSourceAndIndexGetLabelStringAttribute() throws IOException { try { System.setProperty("org.opennms.rrd.storeByForeignSource", "true"); GenericIndexResourceType rt = new GenericIndexResourceType( m_resourceStorageDao, "foo", "Foo Resource", "${stringAttribute}", m_storageStrategy); File rrd = touch("snmp", "fs", "source1", "123", "foo", "1", RRD_FILE_NAME); m_fileAnticipator.tempFile( rrd.getParentFile(), RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME, "stringAttribute=hello!!!!"); m_mocks.replayAll(); OnmsResource resource = rt.getChildByName(getNodeResource("source1", "123"), "1"); m_mocks.verifyAll(); assertNotNull("resource", resource); assertEquals("resource label", "hello!!!!", resource.getLabel()); } finally { System.setProperty("org.opennms.rrd.storeByForeignSource", "false"); } }
@Test public void testGetResourceByNodeAndIndexGetLabelIndex() { GenericIndexResourceType rt = new GenericIndexResourceType( m_resourceStorageDao, "foo", "Foo Resource", "${index}", m_storageStrategy); touch("snmp", "1", "foo", "1", RRD_FILE_NAME); m_mocks.replayAll(); OnmsResource resource = rt.getChildByName(getNodeResource(1), "1"); m_mocks.verifyAll(); assertNotNull("resource", resource); assertEquals("resource label", "1", resource.getLabel()); }
@Test public void testGetResourceByNodeAndIndexGetLabelIndexWithHexConversion() { GenericIndexResourceType rt = new GenericIndexResourceType( m_resourceStorageDao, "foo", "Foo Resource", "${hex(index)}", m_storageStrategy); touch("snmp", "1", "foo", "1.2.3.4.14.15", RRD_FILE_NAME); m_mocks.replayAll(); OnmsResource resource = rt.getChildByName(getNodeResource(1), "1.2.3.4.14.15"); m_mocks.verifyAll(); assertNotNull("resource", resource); assertEquals("resource label", "01:02:03:04:0E:0F", resource.getLabel()); }
@Test public void testGetResourceByNodeAndIndexGetLabelIndexWithBogusUseOfNforStartOfFirstSubIndex() { GenericIndexResourceType rt = new GenericIndexResourceType( m_resourceStorageDao, "foo", "Foo Resource", "Easy as ${subIndex(n, 3)}", m_storageStrategy); touch("snmp", "1", "foo", "3.1.2.3", RRD_FILE_NAME); m_mocks.replayAll(); OnmsResource resource = rt.getChildByName(getNodeResource(1), "3.1.2.3"); m_mocks.verifyAll(); assertNotNull("resource", resource); assertEquals("resource label", "Easy as ${subIndex(n, 3)}", resource.getLabel()); }
@Test public void testGetResourceByNodeAndIndexGetLabelIndexWithDisplaySubStringOfDynamicLength() { GenericIndexResourceType rt = new GenericIndexResourceType( m_resourceStorageDao, "foo", "Foo Resource", "Easy as ${string(subIndex(0, n))}", m_storageStrategy); touch("snmp", "1", "foo", "3.112.105.101", RRD_FILE_NAME); m_mocks.replayAll(); OnmsResource resource = rt.getChildByName(getNodeResource(1), "3.112.105.101"); m_mocks.verifyAll(); assertNotNull("resource", resource); assertEquals("resource label", "Easy as pie", resource.getLabel()); }
@Test public void testGetResourceByNodeAndIndexGetLabelIndexWithSubStringAndDynSubStringAndDynSubStringAndSubStringToEnd() { GenericIndexResourceType rt = new GenericIndexResourceType( m_resourceStorageDao, "foo", "Foo Resource", "Easy as ${subIndex(0, 1)} and ${subIndex(1, n)} and ${subIndex(n, n)} and ${subIndex(n)}", m_storageStrategy); touch("snmp", "1", "foo", "3.3.1.2.3.3.4.5.6.0", RRD_FILE_NAME); m_mocks.replayAll(); OnmsResource resource = rt.getChildByName(getNodeResource(1), "3.3.1.2.3.3.4.5.6.0"); m_mocks.verifyAll(); assertNotNull("resource", resource); assertEquals("resource label", "Easy as 3 and 1.2.3 and 4.5.6 and 0", resource.getLabel()); }
/** Test for enhancement in bug #2467. */ @Test public void testGetResourceByNodeAndIndexGetLabelIndexWithSubStringAndHexConversion() { GenericIndexResourceType rt = new GenericIndexResourceType( m_resourceStorageDao, "foo", "Foo Resource", "MAC Address ${hex(subIndex(0, 6))} on interface ${subIndex(6, 1)}", m_storageStrategy); touch("snmp", "1", "foo", "0.21.109.80.9.66.4", RRD_FILE_NAME); m_mocks.replayAll(); OnmsResource resource = rt.getChildByName(getNodeResource(1), "0.21.109.80.9.66.4"); m_mocks.verifyAll(); assertNotNull("resource", resource); assertEquals( "resource label", "MAC Address 00:15:6D:50:09:42 on interface 4", resource.getLabel()); }
@Test public void testGetResourceByNodeAndIndexGetLabelIndexWithSubStringAndTwoDisplaySubStringsOfDynamicLengthAndSubStringToEnd() { GenericIndexResourceType rt = new GenericIndexResourceType( m_resourceStorageDao, "foo", "Foo Resource", "Easy as ${subIndex(0, 1)} piece of ${string(subIndex(1, n))} or just under ${string(subIndex(n, n))} pieces of ${subIndex(n)}", m_storageStrategy); touch("snmp", "1", "foo", "1.3.112.105.101.2.80.105.3.1.4.1.5.9", RRD_FILE_NAME); m_mocks.replayAll(); OnmsResource resource = rt.getChildByName(getNodeResource(1), "1.3.112.105.101.2.80.105.3.1.4.1.5.9"); m_mocks.verifyAll(); assertNotNull("resource", resource); assertEquals( "resource label", "Easy as 1 piece of pie or just under Pi pieces of 3.1.4.1.5.9", resource.getLabel()); }