@Override protected void runTest() throws Throwable { super.runTest(); m_mocks.verifyAll(); }
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(); }
@After public void tearDown() { m_mocks.verifyAll(); m_fileAnticipator.deleteExpected(); m_fileAnticipator.tearDown(); }
m_mocks.verifyAll();
/** * * @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(); }
@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(); }
/** * Verify. * <p>The data collection should be performed for each node, no matter if they are using the same primary address.</p> * * @throws Exception the exception */ private void verify() throws Exception { Thread.sleep(10000); int successfulCollections = 5; // At least 5 collections must be performed for the above wait time. m_collectd.stop(); m_mockUtils.verifyAll(); MockLogAppender.assertNoWarningsOrGreater(); Assert.assertTrue(successfulCollections <= countMessages("collector.collect: begin:testPackage/1/192.168.1.1/SNMP")); Assert.assertTrue(successfulCollections <= countMessages("collector.collect: end:testPackage/1/192.168.1.1/SNMP")); Assert.assertTrue(successfulCollections <= countMessages("collector.collect: begin:testPackage/3/192.168.1.1/SNMP")); Assert.assertTrue(successfulCollections <= countMessages("collector.collect: end:testPackage/3/192.168.1.1/SNMP")); }
@Test public void testIt() throws InterruptedException { m_collectd.start(); EventBuilder bldr = new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Test"); bldr.setNodeid(1); bldr.setInterface(addr("192.168.1.1")); bldr.setService("SNMP"); m_collectd.onEvent(bldr.getEvent()); Thread.sleep(2000); assertNotNull(m_serviceCollector); assertEquals(1, m_serviceCollector.getCollectCount()); m_mockUtils.verifyAll(); }
m_mocks.verifyAll();
/** * 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(); }
@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(); }