public void testAfterPropertiesSet() { // Not replaying anything, but need to do it before verifyAll() happens m_mocks.replayAll(); createReportDefinition(); }
public void testCommit() throws Exception { EasyMock.expect(m_ds.getConnection()).andReturn(m_conn); EasyMock.expect(m_ds2.getConnection()).andReturn(m_conn2); m_conn.setAutoCommit(false); m_conn.commit(); m_conn.close(); m_conn2.setAutoCommit(false); m_conn2.commit(); m_conn2.close(); m_ezMock.replayAll(); Transaction.begin(); Transaction.getConnection("ds"); Transaction.getConnection("ds2"); Transaction.end(); m_ezMock.verifyAll(); }
public void testRollback() throws Exception { EasyMock.expect(m_ds.getConnection()).andReturn(m_conn); EasyMock.expect(m_ds2.getConnection()).andReturn(m_conn2); m_conn.setAutoCommit(false); m_conn.rollback(); m_conn.close(); m_conn2.setAutoCommit(false); m_conn2.rollback(); m_conn2.close(); m_ezMock.replayAll(); Transaction.begin(); Transaction.getConnection("ds"); Transaction.getConnection("ds2"); Transaction.rollbackOnly(); Transaction.end(); m_ezMock.verifyAll(); }
public void testReturnSameConnection() throws Exception { EasyMock.expect(m_ds.getConnection()).andReturn(m_conn); m_conn.setAutoCommit(false); m_conn.commit(); m_conn.close(); m_ezMock.replayAll(); Transaction.begin(); Connection c1 = Transaction.getConnection("ds"); Connection c2 = Transaction.getConnection("ds"); assertSame("Expected to get the same connection for both calls to getConnection", c1, c2); Transaction.end(); m_ezMock.verifyAll(); }
public void testCloseResources() throws Exception { EasyMock.expect(m_ds.getConnection()).andReturn(m_conn); m_conn.setAutoCommit(false); Statement stmt = m_ezMock.createMock(Statement.class); ResultSet rs = m_ezMock.createMock(ResultSet.class); rs.close(); stmt.close(); m_conn.close(); m_conn.commit(); m_ezMock.replayAll(); Transaction.begin(); Transaction.getConnection("ds"); Transaction.register(stmt); Transaction.register(rs); Transaction.end(); m_ezMock.verifyAll(); }
public void testReportWalking() throws Exception { EasyMock.expect(m_resourceDao.findTopLevelResources()).andReturn(new ArrayList<OnmsResource>(0)); ReportDefinition def = createReportDefinition(); def.setResourceAttributeKey("ifSpeed"); def.setResourceAttributeValueMatch("100000000"); ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao); m_mocks.replayAll(); report.walk(); assertEquals("results size", 0, report.getResults().size()); }
@SuppressWarnings("unchecked") public void testBogusReportClass() throws Exception { // Not replaying anything, but need to do it before verifyAll() happens m_mocks.replayAll(); ReportDefinition def = new ReportDefinition(); Class<? extends AttributeStatisticVisitorWithResults> clazz = (Class<? extends AttributeStatisticVisitorWithResults>) Class.forName("java.lang.String"); ThrowableAnticipator ta = new ThrowableAnticipator(); ta.anticipate(new IllegalArgumentException(ThrowableAnticipator.IGNORE_MESSAGE)); try { def.setReportClass(clazz); } catch (Throwable t) { ta.throwableReceived(t); } ta.verifyAnticipated(); }
public void testUnfilteredResourceAttributeFilteringWithNoMatch() throws Exception { MockResourceType resourceType = new MockResourceType(); resourceType.setName("interfaceSnmp"); OnmsAttribute attribute = new RrdGraphAttribute("IfInOctets", "something", "something else"); OnmsResource resource = new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")); EasyMock.expect(m_resourceDao.findTopLevelResources()).andReturn(Collections.singletonList(resource)); ReportDefinition def = createReportDefinition(); def.setResourceAttributeKey("ifSpeed"); def.setResourceAttributeValueMatch("100000000"); ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao); m_mocks.replayAll(); report.walk(); assertEquals("results size", 0, report.getResults().size()); }
expect(m_pollerConfig.getStep(pkg)).andReturn(step).anyTimes(); m_mocks.replayAll(); LatencyStoringServiceMonitorAdaptor adaptor = new LatencyStoringServiceMonitorAdaptor(m_pollerConfig, pkg, m_persisterFactory, m_resourceStorageDao);
/** * * @throws Exception */ @Test public void testNoMatchingSpecs() throws Exception { setupCollector("SNMP"); expect(m_ipIfDao.findByServiceType("SNMP")).andReturn(new ArrayList<OnmsIpInterface>(0)); setupTransactionManager(); m_easyMockUtils.replayAll(); m_collectd.afterPropertiesSet(); m_collectd.start(); m_scheduler.next(); assertEquals(0, m_scheduler.getEntryCount()); m_collectd.stop(); m_easyMockUtils.verifyAll(); }
public void testFilteredResourceAttributeFilteringWithNoMatch() throws Exception { final OnmsNode node = new OnmsNode(); node.setId(1); node.setLabel("Node One"); EasyMock.expect(m_nodeDao.load(1)).andReturn(node); MockResourceType resourceType = new MockResourceType(); resourceType.setName("interfaceSnmp"); OnmsAttribute attribute = new RrdGraphAttribute("IfInOctets", "something", "something else"); OnmsResource resource = new OnmsResource(node.getId().toString(), node.getLabel(), resourceType, Collections.singleton(attribute), ResourcePath.get("foo")); ReportDefinition def = createReportDefinition(); def.getReport().getPackage().setFilter(""); def.setResourceAttributeKey("ifSpeed"); def.setResourceAttributeValueMatch("100000000"); ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao); SortedMap<Integer,String> sortedNodeMap = new TreeMap<Integer, String>(); sortedNodeMap.put(node.getId(), node.getLabel()); EasyMock.expect(m_filterDao.getNodeMap("")).andReturn(sortedNodeMap); EasyMock.expect(m_resourceDao.getResourceForNode(node)).andReturn(resource); m_mocks.replayAll(); report.walk(); assertEquals("results size", 0, report.getResults().size()); }
@Test public void testOneMatchingSpec() throws Exception { OnmsIpInterface iface = getInterface(); setupCollector("SNMP"); setupInterface(iface); setupTransactionManager(); expect(m_collectdConfig.getPackages()).andReturn(Collections.singletonList(getCollectionPackageThatMatchesSNMP())); expect(m_collectdConfigFactory.interfaceInPackage(iface, getCollectionPackageThatMatchesSNMP())).andReturn(true); m_easyMockUtils.replayAll(); assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount()); m_collectd.afterPropertiesSet(); m_collectd.start(); m_scheduler.next(); assertEquals("scheduler entry count", 1, m_scheduler.getEntryCount()); m_scheduler.next(); m_collectd.stop(); m_easyMockUtils.verifyAll(); }
private SnmpAttribute buildStringAttribute() { EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes(); m_easyMockUtils.replayAll(); SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(m_intf.getId(), m_ifDao, m_transMgr); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); SnmpCollectionResource resource = new NodeInfo(resourceType, agent); MibObject mibObject = new MibObject(); mibObject.setOid(".1.1.1.1"); mibObject.setAlias("mibObjectAlias"); mibObject.setType("string"); mibObject.setInstance("0"); mibObject.setMaxval(null); mibObject.setMinval(null); SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); return new SnmpAttribute(resource, attributeType, SnmpUtils.getValueFactory().getOctetString("foo".getBytes())); }
protected void createAgent(int ifIndex, PrimaryType ifCollType) { m_node = new OnmsNode(); m_node.setSysObjectId(".1.2.3.4.5.6.7"); OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(m_node, ifIndex); m_iface = new OnmsIpInterface(); m_iface.setId(123); m_iface.setIpAddress(myLocalHost()); m_iface.setIsSnmpPrimary(ifCollType); m_iface.setSnmpInterface(snmpIface); m_node.addIpInterface(m_iface); EasyMock.expect(m_ifaceDao.load(m_iface.getId())).andReturn(m_iface).anyTimes(); m_easyMockUtils.replayAll(); m_agent = DefaultSnmpCollectionAgent.create(m_iface.getId(), m_ifaceDao, new MockPlatformTransactionManager()); }
m_mocks.replayAll();
/** * NMS-9413: Verifies that collectd does not schedule interfaces when the * {@link ServiceCollector} throws a {@link CollectionInitializationException} * while validating the agent. */ @SuppressWarnings("unchecked") @Test public void testInterfaceIsNotScheduledWhenValidationFails() throws Exception { ServiceCollector svcCollector = m_easyMockUtils.createMock(ServiceCollector.class); svcCollector.initialize(); svcCollector.validateAgent(isA(CollectionAgent.class), isA(Map.class)); expectLastCall().andThrow(new CollectionInitializationException("No!")).once(); setupCollector("SNMP", svcCollector); OnmsIpInterface iface = getInterface(); setupInterface(iface); setupTransactionManager(); expect(m_collectdConfig.getPackages()).andReturn(Collections.singletonList(getCollectionPackageThatMatchesSNMP())); expect(m_collectdConfigFactory.interfaceInPackage(iface, getCollectionPackageThatMatchesSNMP())).andReturn(true); m_easyMockUtils.replayAll(); assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount()); m_collectd.afterPropertiesSet(); m_collectd.start(); m_scheduler.next(); assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount()); m_collectd.stop(); m_easyMockUtils.verifyAll(); }
EasyMock.expect(m_ifaceDao.load(4)).andReturn(ip2).anyTimes(); m_mockUtils.replayAll();
m_rrdStrategy.closeFile(isA(Object.class)); m_mocks.replayAll();
@Test public void testCreate() throws Exception { setupCollector("SNMP"); setupTransactionManager(); // Use a mock scheduler to track calls to the Collectd scheduler Scheduler m_scheduler = m_easyMockUtils.createMock(Scheduler.class); m_collectd.setScheduler(m_scheduler); // Expect one task to be scheduled m_scheduler.schedule(eq(0L), isA(ReadyRunnable.class)); // Expect the scheduler to be started and stopped during Collectd // start() and stop() m_scheduler.start(); m_scheduler.stop(); m_easyMockUtils.replayAll(); // Initialize Collectd m_collectd.afterPropertiesSet(); // Start and stop collectd m_collectd.start(); m_collectd.stop(); m_easyMockUtils.verifyAll(); }