public static File anticipatePath(FileAnticipator fa, File rootDir, String... pathElements) { File parent = rootDir; assertTrue(pathElements.length > 0); for (String pathElement : pathElements) { parent = fa.expecting(parent, pathElement); } return parent; }
public static File anticipatePath(FileAnticipator fa, File rootDir, String... pathElements) { File parent = rootDir; assertTrue(pathElements.length > 0); for (String pathElement : pathElements) { parent = fa.expecting(parent, pathElement); } return parent; }
@Test public void testPersistStringAttributeWithNoParentDirectory() throws Exception { initPersister(); File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString()); m_fileAnticipator.expecting(nodeDir, RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME); CollectionAttribute attribute = buildStringAttribute(); m_persister.persistStringAttribute(attribute); }
@Test public void generateSchema() throws Exception { File schemaFile = fa.expecting("foreign-sources.xsd"); c.generateSchema(new TestOutputResolver(schemaFile)); if (fa.isInitialized()) { fa.deleteExpected(); } }
@Test public void testPersistStringAttributeWithParentDirectory() throws Exception { initPersister(); File nodeDir = m_fileAnticipator.tempDir(getSnmpRrdDirectory(), m_node.getId().toString()); m_fileAnticipator.expecting(nodeDir, RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME); CollectionAttribute attribute = buildStringAttribute(); m_persister.persistStringAttribute(attribute); }
/** * Test for bug #1817 where a string attribute will get persisted to * both strings.properties and an RRD file if it is a numeric value. */ @Test public void testPersistStringAttributeUsingBuilder() throws Exception { initPersister(); File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString()); m_fileAnticipator.expecting(nodeDir, RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME); CollectionAttribute attribute = buildStringAttribute(); m_persister.pushShouldPersist(attribute.getResource()); m_persister.pushShouldPersist(attribute); m_persister.setBuilder(m_persister.createBuilder(attribute.getResource(), attribute.getName(), Sets.newHashSet(attribute.getAttributeType()))); // This will end up calling m_persister.persistStringAttribute(attribute); m_persister.storeAttribute(attribute); m_persister.commitBuilder(); m_persister.popShouldPersist(); }
@Test public void testCommitWithDeclaredAttribute() throws Exception { File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString()); m_fileAnticipator.expecting(nodeDir, "rrdName" + m_rrdStrategy.getDefaultFileExtension()); m_fileAnticipator.expecting(nodeDir, "rrdName" + ".meta"); RrdRepository repository = createRrdRepository(); SnmpCollectionAgent agent = getCollectionAgent(); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); CollectionResource resource = new NodeInfo(resourceType, agent); MibObject mibObject = new MibObject(); mibObject.setOid(".1.1.1.1"); mibObject.setAlias("mibObjectAlias"); mibObject.setType("counter"); mibObject.setInstance("0"); mibObject.setMaxval(null); mibObject.setMinval(null); SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient); SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes()))); RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false); builder.declareAttribute(attributeType); builder.commit(); }
@Test public void testCommitWithDeclaredAttributeAndValue() throws Exception { File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString()); m_fileAnticipator.expecting(nodeDir, "rrdName" + m_rrdStrategy.getDefaultFileExtension()); m_fileAnticipator.expecting(nodeDir, "rrdName" + ".meta"); RrdRepository repository = createRrdRepository(); SnmpCollectionAgent agent = getCollectionAgent(); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); CollectionResource resource = new NodeInfo(resourceType, agent); MibObject mibObject = new MibObject(); mibObject.setOid(".1.1.1.1"); mibObject.setAlias("mibObjectAlias"); mibObject.setType("counter"); mibObject.setInstance("0"); mibObject.setMaxval(null); mibObject.setMinval(null); SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient); SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes()))); RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false); builder.declareAttribute(attributeType); builder.setAttributeValue(attributeType, 6.022E23d); builder.commit(); }