// Path: hbase0.98/hbase-table-stat-0.98/src/main/java/com/kakao/hbase/stat/load/Level.java
// public class Level implements Comparable<Level> {
//     private final Object level;
// 
//     public Level(Object level) {
//         this.level = level;
//     }
// 
//     @Override
//     public String toString() {
//         if (level instanceof RegionName) {
//             return ((RegionName) level).name();
//         } else if (level instanceof ServerName) {
//             return ((ServerName) level).getServerName();
//         } else if (level instanceof TableName) {
//             return ((TableName) level).getTableName();
//         } else {
//             return level.toString();
//         }
//     }
// 
//     @SuppressWarnings("NullableProblems")
//     @Override
//     public int compareTo(Level thatLevel) {
//         if (thatLevel == null) {
//             return 1;
//         }
//         if (level instanceof RegionName) {
//             return ((RegionName) level).compareTo((RegionName) thatLevel.level);
//         } else if (level instanceof ServerName) {
//             return ((ServerName) level).compareTo((ServerName) thatLevel.level);
//         } else if (level instanceof TableName) {
//             return ((TableName) level).compareTo((TableName) thatLevel.level);
//         } else if (level instanceof String) {
//             return ((String) level).compareTo((String) thatLevel.level);
//         } else
//             throw new RuntimeException("can not compareTo");
//     }
// 
//     public boolean equalsName(String name) {
//         if (name == null) return false;
// 
//         if (level instanceof RegionName) {
//             return ((RegionName) level).name().equals(name);
//         } else if (level instanceof ServerName) {
//             return ((ServerName) level).getServerName().equals(name);
//         } else if (level instanceof TableName) {
//             return ((TableName) level).getTableName().equals(name);
//         } else if (level instanceof String) {
//             return level.equals(name);
//         } else
//             throw new RuntimeException("can not equalsName");
//     }
// }


import com.kakao.hbase.stat.load.Level;
import org.junit.Assert;
import org.junit.Test;
import java.util.Set;
import static org.junit.Assert.assertEquals;
        String tableNameRegex = tableName + ".*";
        String[] args = {"zookeeper", tableNameRegex, "--interval=0", "--rs"};
        TableStat command = new TableStat(admin, new StatArgs(args));

        command.run();
        Assert.assertEquals("RegionServer", command.getLoad().getLevelClass().getLevelTypeString());
    }

    @Test
    public void testRegexTableNameWithRegion() throws Exception {
        String tableNameRegex = tableName + ".*";
        String[] args = {"zookeeper", tableNameRegex, "--interval=0", "--region"};
        TableStat command = new TableStat(admin, new StatArgs(args));

        command.run();
        Assert.assertEquals("Region (RS Index)", command.getLoad().getLevelClass().getLevelTypeString());
    }

    @Test
    public void testRegexTableName() throws Exception {
        String tableName2 = createAdditionalTable(tableName + "2");
        String tableName3 = createAdditionalTable(tableName + "22");

        String tableNameRegex = tableName + "2.*";
        String[] args = {"zookeeper", tableNameRegex, "--interval=0"};
        TableStat command = new TableStat(admin, new StatArgs(args));

        command.run();
        Assert.assertEquals("Table", command.getLoad().getLevelClass().getLevelTypeString());
        Assert.assertEquals(2, command.getLoad().getLoadMap().size());
// Path: hbase0.98/hbase-table-stat-0.98/src/main/java/com/kakao/hbase/stat/load/Level.java
// public class Level implements Comparable<Level> {
//     private final Object level;
// 
//     public Level(Object level) {
//         this.level = level;
//     }
// 
//     @Override
//     public String toString() {
//         if (level instanceof RegionName) {
//             return ((RegionName) level).name();
//         } else if (level instanceof ServerName) {
//             return ((ServerName) level).getServerName();
//         } else if (level instanceof TableName) {
//             return ((TableName) level).getTableName();
//         } else {
//             return level.toString();
//         }
//     }
// 
//     @SuppressWarnings("NullableProblems")
//     @Override
//     public int compareTo(Level thatLevel) {
//         if (thatLevel == null) {
//             return 1;
//         }
//         if (level instanceof RegionName) {
//             return ((RegionName) level).compareTo((RegionName) thatLevel.level);
//         } else if (level instanceof ServerName) {
//             return ((ServerName) level).compareTo((ServerName) thatLevel.level);
//         } else if (level instanceof TableName) {
//             return ((TableName) level).compareTo((TableName) thatLevel.level);
//         } else if (level instanceof String) {
//             return ((String) level).compareTo((String) thatLevel.level);
//         } else
//             throw new RuntimeException("can not compareTo");
//     }
// 
//     public boolean equalsName(String name) {
//         if (name == null) return false;
// 
//         if (level instanceof RegionName) {
//             return ((RegionName) level).name().equals(name);
//         } else if (level instanceof ServerName) {
//             return ((ServerName) level).getServerName().equals(name);
//         } else if (level instanceof TableName) {
//             return ((TableName) level).getTableName().equals(name);
//         } else if (level instanceof String) {
//             return level.equals(name);
//         } else
//             throw new RuntimeException("can not equalsName");
//     }
// }


// Path: hbase0.98/hbase-table-stat-0.98/src/test/java/com/kakao/hbase/stat/TableStatRegexTest.java
import com.kakao.hbase.stat.load.Level;
import org.junit.Assert;
import org.junit.Test;
import java.util.Set;
import static org.junit.Assert.assertEquals;

        String tableNameRegex = tableName + ".*";
        String[] args = {"zookeeper", tableNameRegex, "--interval=0", "--rs"};
        TableStat command = new TableStat(admin, new StatArgs(args));

        command.run();
        Assert.assertEquals("RegionServer", command.getLoad().getLevelClass().getLevelTypeString());
    }

    @Test
    public void testRegexTableNameWithRegion() throws Exception {
        String tableNameRegex = tableName + ".*";
        String[] args = {"zookeeper", tableNameRegex, "--interval=0", "--region"};
        TableStat command = new TableStat(admin, new StatArgs(args));

        command.run();
        Assert.assertEquals("Region (RS Index)", command.getLoad().getLevelClass().getLevelTypeString());
    }

    @Test
    public void testRegexTableName() throws Exception {
        String tableName2 = createAdditionalTable(tableName + "2");
        String tableName3 = createAdditionalTable(tableName + "22");

        String tableNameRegex = tableName + "2.*";
        String[] args = {"zookeeper", tableNameRegex, "--interval=0"};
        TableStat command = new TableStat(admin, new StatArgs(args));

        command.run();
        Assert.assertEquals("Table", command.getLoad().getLevelClass().getLevelTypeString());
        Assert.assertEquals(2, command.getLoad().getLoadMap().size());
        Set<Level> levelSet = command.getLoad().getLoadMap().keySet();