public void testMetaData() throws ReportDataFactoryException { final KettleDataFactory kettleDataFactory = new KettleDataFactory(); kettleDataFactory.initialize(new DesignTimeDataFactoryContext()); kettleDataFactory.setQuery( "default", new KettleTransFromFileProducer(QUERY, STEP, new String[0], new ParameterMapping[0])); final DataFactoryMetaData metaData = kettleDataFactory.getMetaData(); final Object queryHash = metaData.getQueryHash(kettleDataFactory, "default", new StaticDataRow()); assertNotNull(queryHash); final KettleDataFactory kettleDataFactory2 = new KettleDataFactory(); kettleDataFactory2.initialize(new DesignTimeDataFactoryContext()); kettleDataFactory2.setQuery( "default", new KettleTransFromFileProducer(QUERY + "2", STEP, new String[0], new ParameterMapping[0])); kettleDataFactory2.setQuery( "default2", new KettleTransFromFileProducer(QUERY, STEP, new String[0], new ParameterMapping[0])); assertNotEquals( "Physical Query is not the same", queryHash, metaData.getQueryHash(kettleDataFactory2, "default", new StaticDataRow())); assertEquals( "Physical Query is the same", queryHash, metaData.getQueryHash(kettleDataFactory2, "default2", new StaticDataRow())); }
public void testMetaDataDrc() { final DriverConnectionProvider drc = new DriverConnectionProvider(); drc.setDriver("org.hsqldb.jdbcDriver"); drc.setUrl("jdbc:hsqldb:mem:SampleData"); drc.setProperty("user", "sa"); drc.setProperty("password", ""); final SQLReportDataFactory sqlReportDataFactory = new SQLReportDataFactory(drc); final DataFactoryMetaData metaData = sqlReportDataFactory.getMetaData(); assertNull( "No name property set, so display-name must be null", metaData.getDisplayConnectionName(sqlReportDataFactory)); drc.setProperty("::pentaho-reporting::name", "test"); assertEquals( "Name property set, so display name must be test", "test", metaData.getDisplayConnectionName(sqlReportDataFactory)); sqlReportDataFactory.setQuery("test", "SELECT * FROM TABLE"); assertNotNull( "QueryHash must exist", metaData.getQueryHash(sqlReportDataFactory, "test", new StaticDataRow())); final SQLReportDataFactory sqlReportDataFactory2 = new SQLReportDataFactory(drc); sqlReportDataFactory2.setQuery("test", "SELECT * FROM TABLE2"); assertNotEquals( "Physical Queries do not match, so query hash must be different", metaData.getQueryHash(sqlReportDataFactory, "test", new StaticDataRow()), (metaData.getQueryHash(sqlReportDataFactory2, "test", new StaticDataRow()))); sqlReportDataFactory2.setQuery("test2", "SELECT * FROM TABLE"); final Object qh1 = metaData.getQueryHash(sqlReportDataFactory, "test", new StaticDataRow()); final Object qh2 = metaData.getQueryHash(sqlReportDataFactory2, "test2", new StaticDataRow()); assertEquals("Physical Queries match, so queries are considered the same", qh1, qh2); final DriverConnectionProvider drc2 = new DriverConnectionProvider(); drc.setDriver("org.hsqldb.jdbcDriver"); drc.setUrl("jdbc:hsqldb:mem:SampleData2"); drc.setProperty("user", "sa"); drc.setProperty("password", ""); final SQLReportDataFactory sqlReportDataFactory3 = new SQLReportDataFactory(drc2); sqlReportDataFactory3.setQuery("test", "SELECT * FROM TABLE2"); assertNotEquals( "Connections do not match, so query hash must be different", metaData.getQueryHash(sqlReportDataFactory, "test", new StaticDataRow()), (metaData.getQueryHash(sqlReportDataFactory3, "test", new StaticDataRow()))); sqlReportDataFactory3.setQuery("test2", "SELECT * FROM TABLE"); assertNotEquals( "Connections do not match, so queries are considered the same", metaData.getQueryHash(sqlReportDataFactory, "test", new StaticDataRow()), metaData.getQueryHash(sqlReportDataFactory3, "test2", new StaticDataRow())); }