Ejemplo n.º 1
0
  public void testTranslateVariablesNoRecursive() {
    ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(
        new HashMap<String, Object>() {
          {
            put("foo", "${1+1}");
          }
        });

    Object s = TextParseUtil.translateVariables('$', "foo: ${foo}", stack, String.class, null, 1);
    assertEquals("foo: ${1+1}", s);
  }
Ejemplo n.º 2
0
 public void testNestedExpression() throws Exception {
   ValueStack stack = ActionContext.getContext().getValueStack();
   stack.push(
       new HashMap<String, Object>() {
         {
           put("foo", "${%{1+1}}");
         }
       });
   String s = TextParseUtil.translateVariables("${foo}", stack);
   assertEquals("${%{1+1}}", s);
   stack.pop();
 }
Ejemplo n.º 3
0
 public void testMixedOpenChars() throws Exception {
   ValueStack stack = ActionContext.getContext().getValueStack();
   stack.push(
       new HashMap<String, Object>() {
         {
           put("foo", "bar");
         }
       });
   String s = TextParseUtil.translateVariables("${foo}-%{foo}", stack);
   assertEquals("bar-bar", s);
   s = TextParseUtil.translateVariables("%{foo}-${foo}", stack);
   assertEquals(
       "%{foo}-bar",
       s); // this is bad, but it is the only way not to double evaluate passed expression
   stack.pop();
 }
Ejemplo n.º 4
0
  public void testTranslateVariablesWithEvaluator() throws Exception {
    ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(
        new Object() {
          public String getMyVariable() {
            return "My Variable ";
          }
        });

    TextParseUtil.ParsedValueEvaluator evaluator =
        new TextParseUtil.ParsedValueEvaluator() {
          public Object evaluate(String parsedValue) {
            return parsedValue.toString() + "Something";
          }
        };

    String result = TextParseUtil.translateVariables("Hello ${myVariable}", stack, evaluator);

    assertEquals(result, "Hello My Variable Something");
  }
Ejemplo n.º 5
0
  /** Test that type conversion is performed on indexed collection properties. */
  public void testSetIndexedValue() {
    ValueStack stack = ActionContext.getContext().getValueStack();
    Map<String, Object> stackContext = stack.getContext();
    stackContext.put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
    stackContext.put(ReflectionContextState.DENY_METHOD_EXECUTION, Boolean.TRUE);
    stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);

    User user = new User();
    stack.push(user);

    // indexed string w/ existing array
    user.setList(new ArrayList<String>());
    user.getList().add("");

    String[] foo = new String[] {"asdf"};
    stack.setValue("list[0]", foo);
    assertNotNull(user.getList());
    assertEquals(1, user.getList().size());
    assertEquals(String.class, user.getList().get(0).getClass());
    assertEquals("asdf", user.getList().get(0));
  }
Ejemplo n.º 6
0
  public void testTranslateVariablesWithNull() {
    // given
    ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(
        new HashMap<String, Object>() {
          {
            put("foo", null);
          }
        });

    TextParseUtil.ParsedValueEvaluator evaluator =
        new TextParseUtil.ParsedValueEvaluator() {
          public Object evaluate(String parsedValue) {
            return parsedValue;
          }
        };

    // when
    Object s =
        TextParseUtil.translateVariables('$', "foo: ${foo}", stack, String.class, evaluator, 2);

    // then
    assertEquals("foo: ", s);
  }
Ejemplo n.º 7
0
  /** XW-281 */
  public void testSetBigIndexedValue() {
    ValueStack stack = ActionContext.getContext().getValueStack();
    Map stackContext = stack.getContext();
    stackContext.put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.FALSE);
    stackContext.put(ReflectionContextState.DENY_METHOD_EXECUTION, Boolean.TRUE);
    stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);

    User user = new User();
    stack.push(user);

    // indexed string w/ existing array
    user.setList(new ArrayList());

    String[] foo = new String[] {"asdf"};
    ((OgnlValueStack) stack).setDevMode("true");
    try {
      stack.setValue("list.1114778947765", foo);
      fail("non-valid expression: list.1114778947765");
    } catch (RuntimeException ex) {; // it's oke
    }

    try {
      stack.setValue("1114778947765", foo);
      fail("non-valid expression: 1114778947765");
    } catch (RuntimeException ex) {;
    }

    try {
      stack.setValue("1234", foo);
      fail("non-valid expression: 1114778947765");
    } catch (RuntimeException ex) {;
    }

    ((OgnlValueStack) stack).setDevMode("false");
    stack.setValue("list.1114778947765", foo);
    stack.setValue("1114778947765", foo);
    stack.setValue("1234", foo);
  }
Ejemplo n.º 8
0
 final synchronized void restoreValue(int mark) throws ReteException {
   while (m_usedV.size() > mark) {
     m_newV.push(m_usedV.pop());
   }
 }
Ejemplo n.º 9
0
 final int markValue() {
   return m_usedV.size();
 }
Ejemplo n.º 10
0
 final synchronized Value getValue() throws ReteException {
   return m_usedV.push(m_newV.pop());
 }