MetaStatementMatcher { public ExtendedSqlStatement parse(final String fql) { if(fql.matches(DESC_STATEMENT_MATCH)) { final String parts[] = fql.split(DESC_STATEMENT_DELIMITER); if(parts.length != 2) { throw new RuntimeException("Could not decode table name from desc statement. Table name format is: [a-zA-Z-_]+"); } return new Describe(new Table(parts[1].toLowerCase())); } if(fql.matches(SHOWTABLES_STATEMENT_MATCH)) { return new ShowTables(); } return null; }  ExtendedSqlStatement parse(final String fql);  }
@Test public void testParseDescPositive1() throws Exception { ExtendedSqlStatement extendedSqlStatement = metaStatementMatcher.parse("desc europa"); Assert.assertNotNull(extendedSqlStatement); Assert.assertTrue(extendedSqlStatement instanceof Describe); Describe describe = (Describe)extendedSqlStatement; Assert.assertEquals("europa", describe.getTable().getName()); }
@Test public void testParseDescPositive2() throws Exception { ExtendedSqlStatement extendedSqlStatement = metaStatementMatcher.parse(" \tDeSc \tEuRopa"); Assert.assertNotNull(extendedSqlStatement); Assert.assertTrue(extendedSqlStatement instanceof Describe); Describe describe = (Describe)extendedSqlStatement; Assert.assertEquals("europa", describe.getTable().getName()); }
@Test public void testParseDescNegative1() throws Exception { ExtendedSqlStatement extendedSqlStatement = metaStatementMatcher.parse(" \tDeSc \tEuRopa aa"); Assert.assertNull(extendedSqlStatement); }
@Test public void testParseDescNegative2() throws Exception { ExtendedSqlStatement extendedSqlStatement = metaStatementMatcher.parse(" \tDeS \tEuRopa aa"); Assert.assertNull(extendedSqlStatement); }
@Test public void testParseShowTablesPositive1() throws Exception { ExtendedSqlStatement extendedSqlStatement = metaStatementMatcher.parse("show tables"); Assert.assertNotNull(extendedSqlStatement); Assert.assertTrue(extendedSqlStatement instanceof ShowTables); }
@Test public void testParseShowTablesPositive2() throws Exception { ExtendedSqlStatement extendedSqlStatement = metaStatementMatcher.parse("\tShow \t TaBLes"); Assert.assertNotNull(extendedSqlStatement); Assert.assertTrue(extendedSqlStatement instanceof ShowTables); }
@Test public void testParseShowTablesNegative1() throws Exception { ExtendedSqlStatement extendedSqlStatement = metaStatementMatcher.parse("\tSho \t TaBLes"); Assert.assertNull(extendedSqlStatement); }