Ejemplo n.º 1
0
  @Test
  public void testEqualsInQuotedAssignment2() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("Set $equals=\"=\"");

    parser.parse(wrapper.toString());
  }
Ejemplo n.º 2
0
  @Test
  public void testEqualsInQuotedString() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("Echo \"pageId = $pageId\"");

    parser.parse(wrapper.toString());
  }
Ejemplo n.º 3
0
  @Test
  public void testUnknownCommandFailsParsing_3() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("");
    wrapper.addLine("Meh 1");
    wrapper.addLine("Echo \"hello\"");
    wrapper.addLine("If true");
    wrapper.addLine("   Meh 2");
    wrapper.addLine("   Meh 3");

    try {
      parser.parse(wrapper.toString());
      // System.out.println(parserResult.getContent());
      Assert.fail("unknown command should result in ParserException");
    } catch (HulaParserException e) {
      // expected behaviour
      System.out.println(e.getErrors());
      Assert.assertEquals("wrong number of errors", 4, e.getErrors().size());

      assertError(e, 0, 2, "Meh 1", "unknown.command");
      assertError(e, 1, 5, "Meh 2", "unknown.command");
      assertError(e, 2, 6, "Meh 3", "unknown.command");
      assertError(e, 3, 4, "If true", "missing.end.statement");
    }
  }
Ejemplo n.º 4
0
  @Test
  public void testAddJsonMapValue() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("AddJsonMapValue $json, key=k2, value=v2");

    // parse
    HulaExecutable parserResult = parseAndAssert(wrapper.toString());

    Map<String, String> values = new HashMap<String, String>();
    values.put("k1", "v1");

    // run
    HulaContext hctx = new HulaContext();
    hctx.setParameter("json", new Gson().toJson(values));
    evaluateBeanShell(parserResult, hctx);

    Assert.assertEquals("invalid json", "{\"k1\":\"v1\",\"k2\":\"v2\"}", hctx.getParameter("json"));
  }
Ejemplo n.º 5
0
  @Test
  public void testUnknownCommandFailsParsing_2() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("Meh 1");
    wrapper.addLine("Echo \"hello\"");
    wrapper.addLine("Meh 2");
    wrapper.addLine("Meh 3");

    try {
      HulaExecutable parserResult = parser.parse(wrapper.toString());
      System.out.println(parserResult.getContent());
      Assert.fail("unknown command should result in ParserException");
    } catch (HulaParserException e) {
      // expected behaviour
      Assert.assertEquals("wrong number of errors", 3, e.getErrors().size());
      assertError(e, 0, 1, "Meh 1", "unknown.command");
      assertError(e, 1, 3, "Meh 2", "unknown.command");
      assertError(e, 2, 4, "Meh 3", "unknown.command");
    }
  }
Ejemplo n.º 6
0
  @Test
  public void testUnhandledFailuresThrowCorrectException() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("Echo test");
    wrapper.addLine("ProduceError");

    // parse
    HulaExecutable parserResult = parseAndAssert(wrapper.toString());

    // run
    HulaContext hctx = new HulaContext();

    try {
      evaluateBeanShell(parserResult, hctx);
      Assert.fail("expected validate to fail");
    } catch (HulaPlayerException e) {
      // expected behaviour
      Assert.assertEquals("incorrect line number", 2, e.getLineNumber());
    }
  }
Ejemplo n.º 7
0
  @Test
  public void testParserValidatesGeneratedCode() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("Echo hello");
    wrapper.addLine("ProduceJunkCode");
    wrapper.addLine("Echo goodbye");

    try {
      parser.parse(wrapper.toString());
      Assert.fail("unknown command should result in ParserException");
    } catch (HulaParserException e) {
      List<ParseError> errors = e.getErrors();
      ParseError error = errors.get(0);

      // expected behaviour
      Assert.assertEquals("missing line number", -1, error.getLineNumber());
      Assert.assertEquals("missing command line", null, error.getCommandLine());
      Assert.assertEquals("missing error code", "unknown.parse.error", error.getErrorCode());
    }
  }
Ejemplo n.º 8
0
  @Test
  public void testUnknownCommandFailsParsing() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("Meh");

    // parse

    try {
      parser.parse(wrapper.toString());
      Assert.fail("unknown command should result in ParserException");
    } catch (HulaParserException e) {
      List<ParseError> errors = e.getErrors();
      ParseError error = errors.get(0);

      // expected behaviour
      Assert.assertEquals("missing line number", 1, error.getLineNumber());
      Assert.assertEquals("missing command line", "Meh", error.getCommandLine());
      Assert.assertEquals("missing error code", "unknown.command", error.getErrorCode());
    }
  }
Ejemplo n.º 9
0
  @Test
  public void testSuperfluousEndFailsParsing_2() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("End");

    // parse

    try {
      HulaExecutable parserResult = parser.parse(wrapper.toString());
      System.out.println(parserResult.getContent());
      Assert.fail("additional end statement should result in ParserException");
    } catch (HulaParserException e) {
      List<ParseError> errors = e.getErrors();
      ParseError error = errors.get(0);

      // expected behaviour
      Assert.assertEquals("missing line number", 1, error.getLineNumber());
      Assert.assertEquals("missing command line", "End", error.getCommandLine());
      Assert.assertEquals("missing error code", "unnecessary.end.statement", error.getErrorCode());
    }
  }
Ejemplo n.º 10
0
  @Test
  public void testMissingEndFailsParsing_2() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("Loop $names as name");
    wrapper.addLine("	Set value=$name");

    // parse

    try {
      parser.parse(wrapper.toString());
      Assert.fail("missing end statement should result in ParserException");
    } catch (HulaParserException e) {
      List<ParseError> errors = e.getErrors();
      ParseError error = errors.get(0);

      // expected behaviour
      Assert.assertEquals("missing line number", 1, error.getLineNumber());
      Assert.assertEquals("missing command line", "Loop $names as name", error.getCommandLine());
      Assert.assertEquals("missing error code", "missing.end.statement", error.getErrorCode());
    }
  }
Ejemplo n.º 11
0
  /**
   * This test was introduced to fix a parser bug which resulted in a command model like this:
   *
   * <p>Try, Echo, OnFail, Try, Try, Echo, OnFail, Echo, OnFail
   *
   * <p>What should have been produced is:
   *
   * <p>Try, Echo, OnFail, Try, Echo, OnFail, Try, Echo, OnFail
   *
   * <p>The bug was that the CommandModel.lastIndexOf() was not reversing through the list of
   * commands so it was returning the first index, not the last, hence the bunched-up Try's at
   * positions 4 and 5
   *
   * @throws Exception
   */
  @Test
  public void testParseWorksForMultipleSiblingOnFails() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("Echo hello");
    wrapper.addLine("OnFail");
    wrapper.addLine("End");

    wrapper.addLine("Echo hello");
    wrapper.addLine("OnFail");
    wrapper.addLine("End");

    wrapper.addLine("Echo hello");
    wrapper.addLine("OnFail");
    wrapper.addLine("End");

    parser.parse(wrapper.toString());
  }