/*
 * Copyright (c) 2013, OpenCloudDB/MyCAT and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software;Designed and Developed mainly by many Chinese 
 * opensource volunteers. you can redistribute it and/or modify it under the 
 * terms of the GNU General Public License version 2 only, as published by the
 * Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * Any questions about this component can be directed to it's project Web address 
 * https://code.google.com/p/opencloudb/.
 *
 */
package org.opencloudb.util;

import junit.framework.Assert;

import org.junit.Test;
import org.opencloudb.util.SplitUtil;

/**
 * @author mycat
 */
public class StringUtilTest {

    @Test
    public void test() {
        String oriSql = "insert into ssd  (id) values (s)";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("ssd", tableName);
    }

    @Test
    public void test1() {
    	String oriSql = "insert into    ssd(id) values (s)";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("ssd", tableName);
    }

    @Test
    public void test2() {
    	String oriSql = "  insert  into    ssd(id) values (s)";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("ssd", tableName);
    }

    @Test
    public void test3() {
    	String oriSql = "  insert  into    isd(id) values (s)";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("isd", tableName);
    }

    @Test
    public void test4() {
    	String oriSql = "INSERT INTO test_activity_input  (id,vip_no";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("test_activity_input", tableName);
    }
    
    @Test
    public void test5() {
    	String oriSql = " /* ApplicationName=DBeaver 3.3.1 - Main connection */ insert into employee(id,name,sharding_id) values(4, 'myhome', 10011)";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("employee", tableName);
    }
    
    @Test
    public void test6() {
    	String oriSql = " /* insert int a (id, name) value(1, 'ben') */ insert into employee(id,name,sharding_id) values(4, 'myhome', 10011)";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("employee", tableName);
    }
    
    @Test
    public void test7() {
    	String oriSql = " /**/ insert into employee(id,name,sharding_id) values(4, 'myhome', 10011)";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("employee", tableName);
    }
    
    @Test
    public void test8() {
    	String oriSql = " /*  */ insert into employee(id,name,sharding_id) values(4, 'myhome', 10011) /**/";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("employee", tableName);
    }
    
    @Test
    public void test9() {
    	String oriSql = " /* hint1 insert */ /**/ /* hint3 insert */ insert into employee(id,name,sharding_id) values(4, 'myhome', 10011) /**/";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("employee", tableName);
    }
    
    @Test
    public void test10() {
    	String oriSql = " /* hint1 insert */ /* // */ /* hint3 insert */ insert into employee(id,name,sharding_id) values(4, 'myhome', 10011) /**/";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("employee", tableName);
    }
    
    @Test
    public void test11() {
    	String oriSql = " /* hint1 insert */ /* // */ /* hint3 insert */ insert /*  */ into employee(id,name,sharding_id) values(4, 'myhome', 10011) /**/";
        String tableName = StringUtil.getTableName(oriSql);
        Assert.assertEquals("employee", tableName);
    }
}
@@ -1136,29 +1136,55 @@
 rt j
-unit.framework.Assert
+ava.io.PrintWriter;%0Aimport java.io.StringWriter
 ;%0A%0Ai
@@ -1193,24 +1193,33 @@
 ort 
-org.
 junit.
-Tes
+framework.Asser
 t;%0A
+%0A
 impo
@@ -1229,33 +1229,18 @@
 org.
-opencloudb.util.SplitUtil
+junit.Test
 ;%0A%0A/
@@ -4415,9 +4415,808 @@
 ;%0A    %7D%0A
+    @Test%0A    public void test12() %7B%0A    %09StringWriter sw=new StringWriter();%0A    %09PrintWriter pw=new PrintWriter(sw);%0A    %09pw.println(%22insert into%22);%0A    %09pw.println(%22 employee(id,name,sharding_id) values(4, 'myhome', 10011)%22);%0A    %09pw.flush();%0A    %09String oriSql = sw.toString();%0A        String tableName = StringUtil.getTableName(oriSql);%0A        Assert.assertEquals(%22employee%22, tableName);%0A    %7D%0A    @Test%0A    public void test13() %7B%0A    %09StringWriter sw=new StringWriter();%0A    %09PrintWriter pw=new PrintWriter(sw);%0A    %09pw.println(%22insert into%22);%0A    %09pw.println(%22employee(id,name,sharding_id) values(4, 'myhome', 10011)%22);%0A    %09pw.flush();%0A    %09String oriSql = sw.toString();%0A        String tableName = StringUtil.getTableName(oriSql);%0A        Assert.assertEquals(%22employee%22, tableName);%0A    %7D%0A
 %7D

add two test case for StringUtil.getTableName