Example #1
0
 @Test(expected = SyntaxException.class)
 public void testTooManyArguments() throws SyntaxException {
   Prepend.getInstance(
       null,
       new ListResource(),
       StringProperty.getInstance("OK"),
       StringProperty.getInstance("OK"));
 }
Example #2
0
  @Test
  public void testPrependToProtectedList() throws SyntaxException, InvalidTermException {

    Context context = new CompileTimeContext();

    // Create a protected resource.
    ListResource list = new ListResource();
    list = (ListResource) list.protect();

    Element value = StringProperty.getInstance("OK");

    Operation dml = Prepend.getInstance(null, list, value);

    Element result = context.executeDmlBlock(dml);

    // Check that the list argument has NOT been updated.
    assertTrue(list.size() == 0);

    // Verify that a copy has been made.
    assertTrue(result != list);

    // It must also be a list.
    assertTrue(result instanceof ListResource);

    // Verify that the new list has the correct value.
    Element element = ((ListResource) result).get(TermFactory.create(0));
    assertTrue(value == element);
  }
Example #3
0
  /** Set the name of the object template. Define the necessary variables. */
  public void setObjectAndLoadpath() {

    StringProperty sname = StringProperty.getInstance(objectTemplate.name);

    setGlobalVariable("OBJECT", sname, true);
    setGlobalVariable("LOADPATH", new ListResource(), false);
  }
Example #4
0
  public Element executeDmlBlock(Operation dml) {
    Element result = null;

    // Store the old local variables and iterators. Needed because structure
    // templates need to keep the state across template.execute() calls.
    LocalVariableMap oldVariables = createLocalVariableMap(null);
    IteratorMap oldIterators = createIteratorMap();

    // If the TEMPLATE variable is already set, then don't set the value to
    // the current template. This can happen when executing structure
    // templates and we want to keep the outermost value.
    boolean setTemplate = (getGlobalVariable(TPL_VAR) == null);

    // Set the value of TEMPLATE to the current template. Be careful,
    // compile time execution doesn't set the current template. In this
    // case, don't set the global variable.
    if (setTemplate) {
      Template current = getCurrentTemplate();
      if (current != null) {
        StringProperty tname = StringProperty.getInstance(current.name);
        setGlobalVariable(TPL_VAR, tname, true);
      } else {
        setTemplate = false;
      }
    }

    // Run the DML block. Making sure to always restore the previous
    // variables and iterators.
    try {
      result = dml.execute(this);
    } catch (ReturnValueException rve) {
      result = rve.getElement();
    } finally {

      // Remove TEMPLATE variable if we set it above.
      if (setTemplate) {
        removeGlobalVariable(TPL_VAR);
      }

      // Restore the saved local variables and iterators.
      restoreLocalVariableMap(oldVariables);
      restoreIteratorMap(oldIterators);
    }

    return result;
  }
Example #5
0
  @Test
  public void testPrependToList() throws SyntaxException, InvalidTermException {

    Context context = new CompileTimeContext();
    ListResource list = new ListResource();
    Element value = StringProperty.getInstance("OK");

    Operation dml = Prepend.getInstance(null, list, value);

    Element result = context.executeDmlBlock(dml);

    // Check that the list argument has been updated.
    assertTrue(list.size() == 1);
    Element element = list.get(TermFactory.create(0));
    assertTrue(value == element);

    // Verify that the same list is given as the result.
    assertTrue(result == list);
  }
Example #6
0
 @Test(expected = SyntaxException.class)
 public void testInvalidFirstArg() throws SyntaxException {
   Prepend.getInstance(null, StringProperty.getInstance("BAD"), StringProperty.getInstance("OK"));
 }