protected String getLastLogEntry() { return getP6TestLogger().getLastEntry(); }
private void validateNotSpyEnabled(DataSource ds) throws SQLException { assertNotNull("JNDI data source not found", ds); // get the connection Connection con = ds.getConnection(); if (con.getMetaData().getDatabaseProductName().contains("HSQL")) { con.createStatement().execute("set database sql syntax ora true"); } con.createStatement().execute("select current_date from dual"); assertNull(((P6TestLogger) P6LogQuery.getLogger()).getLastEntry()); } }
private void validateSpyEnabled(DataSource ds) throws SQLException { assertNotNull("JNDI data source not found", ds); // get the connection Connection con = ds.getConnection(); // verify that the connection class is a proxy assertTrue("Connection is not a proxy", AbstractWrapper.isProxy(con.getClass())); if (con.getMetaData().getDatabaseProductName().contains("HSQL")) { con.createStatement().execute("set database sql syntax ora true"); } con.createStatement().execute("select current_date from dual"); assertTrue(((P6TestLogger) P6LogQuery.getLogger()).getLastEntry().indexOf("select current_date") != -1); }
statement.executeQuery(sql); oldAppenderRef = (P6TestLogger) P6SpyOptions.getActiveInstance().getAppenderInstance(); assertNotNull(oldAppenderRef.getLastEntry()); assertTrue(oldAppenderRef.getLastEntry().contains(sql)); assertNull(oldAppenderRef.getLastEntry());
@Test public void testGenericDataSourceWithDriverManager() throws Exception { // Create and bind the real data source // Note: This will get the driver from the DriverManager realDs = new TestBasicDataSource(); realDs.setDriverClassName(driverClass); realDs.setUrl(url); realDs.setUsername(user); realDs.setPassword(password); realDs.setUseDriverManager(true); realDsResource = new Resource("jdbc/realDs", realDs); P6TestUtil.setupTestData(realDs); // get the data source from JNDI DataSource ds = new JndiDataSourceLookup().getDataSource("jdbc/spyDs"); assertNotNull("JNDI data source not found", ds); // get the connection con = ds.getConnection(); // verify that the connection class is a proxy assertTrue("Connection is not a proxy", AbstractWrapper.isProxy(con)); Statement stmt = con.createStatement(); stmt.execute("select 1 from customers"); stmt.close(); assertTrue(((P6TestLogger) P6LogQuery.getLogger()).getLastEntry().indexOf("select 1") != -1); assertEquals("Incorrect number of spy log messages", 1, ((P6TestLogger) P6LogQuery.getLogger()).getLogs().size()); }