Package org.yaac.server.egql

Source Code of org.yaac.server.egql.InsertStatementTest

package org.yaac.server.egql;

import junit.framework.Assert;

import org.antlr.runtime.RecognitionException;
import org.junit.Test;
import org.yaac.server.egql.evaluator.DecimalEvaluator;
import org.yaac.server.egql.evaluator.FunctionEvaluator;
import org.yaac.server.egql.evaluator.StringEvaluator;

/**
* @author Max Zhu (thebbsky@gmail.com)
*
*/
public class InsertStatementTest {

  /**
   * normal case
   *
   * @throws RecognitionException
   */
  @Test
  public void test1() throws RecognitionException {
    String inputStr = "insert into kind_a values ( prop_1 = 'a' )";
   
    InsertStatement actual = TestUtil.parser(inputStr).insert_statement().stmt;
   
    InsertStatement expected = new InsertStatement().withKind("kind_a").withItem(new InsertItem("prop_1", new StringEvaluator("'a'"), true));
   
    Assert.assertEquals(expected, actual);
  }

  /**
   * multiple insert items
   *
   * @throws RecognitionException
   */
  @Test
  public void test2() throws RecognitionException {
    String inputStr = "insert into kind_a values (prop_1 = 'a', prop_2 = 10)";
   
    InsertStatement actual = TestUtil.parser(inputStr).insert_statement().stmt;
   
    InsertStatement expected = new InsertStatement().withKind("kind_a").withItem(
        new InsertItem("prop_1", new StringEvaluator("'a'"), true)
        ).withItem(new InsertItem("prop_2", new DecimalEvaluator("10"), true));
   
    Assert.assertEquals(expected, actual);
  }
 
  /**
   * with index option
   *
   * @throws RecognitionException
   */
  @Test
  public void test3() throws RecognitionException {
    String inputStr = "insert into kind_a values (prop_1 = 'a', prop_2 = 10 (indexed=false))";
   
    InsertStatement actual = TestUtil.parser(inputStr).insert_statement().stmt;
   
    InsertStatement expected = new InsertStatement().withKind("kind_a").withItem(
        new InsertItem("prop_1", new StringEvaluator("'a'"), true)
        ).withItem(new InsertItem("prop_2", new DecimalEvaluator("10"), false));
   
    Assert.assertEquals(expected, actual);
  }

  /**
   * without item
   *
   * @throws RecognitionException
   */
  @Test
  public void test4() throws RecognitionException {
    String inputStr = "insert into kind_a";
   
    InsertStatement actual = TestUtil.parser(inputStr).insert_statement().stmt;
   
    InsertStatement expected = new InsertStatement().withKind("kind_a");
   
    Assert.assertEquals(expected, actual);
  }
 
  /**
   * without kind
   *
   * @throws RecognitionException
   */
  @Test
  public void test5() throws RecognitionException {
    String inputStr = "insert values (__key__=key('kind_a', 'b') )";
   
    InsertStatement actual = TestUtil.parser(inputStr).insert_statement().stmt;
   
    InsertStatement expected = new InsertStatement().withItem(new InsertItem("__key__",
        new FunctionEvaluator("key").add(new StringEvaluator("'kind_a'")).add(new StringEvaluator("'b'")),
        true));
   
    Assert.assertEquals(expected, actual);
  }
 
  /**
   * with select statement
   *
   * @throws RecognitionException
   */
  @Test
  public void test6() throws RecognitionException {
    SelectStatement selectStmt = TestUtil.parser("select a from b").select_statement().stmt;
   
    String inputStr = "insert into kind_a from (select a from b)";
   
    InsertStatement actual = TestUtil.parser(inputStr).insert_statement().stmt;
   
    InsertStatement expected = new InsertStatement().withKind("kind_a").withSelectStatement(selectStmt);
   
    Assert.assertEquals(expected, actual);
  }
}
TOP

Related Classes of org.yaac.server.egql.InsertStatementTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.