コード例 #1
0
  @Test
  public void testDictionaryAccess() throws Exception {
    StandardEvaluationContext societyContext = new StandardEvaluationContext();
    societyContext.setRootObject(new IEEE());
    // Officer's Dictionary
    Inventor pupin =
        parser.parseExpression("officers['president']").getValue(societyContext, Inventor.class);
    assertNotNull(pupin);

    // evaluates to "Idvor"
    String city =
        parser
            .parseExpression("officers['president'].PlaceOfBirth.city")
            .getValue(societyContext, String.class);
    assertNotNull(city);

    // setting values
    Inventor i =
        parser.parseExpression("officers['advisors'][0]").getValue(societyContext, Inventor.class);
    assertEquals("Nikola Tesla", i.getName());

    parser
        .parseExpression("officers['advisors'][0].PlaceOfBirth.Country")
        .setValue(societyContext, "Croatia");

    Inventor i2 =
        parser
            .parseExpression("reverse[0]['advisors'][0]")
            .getValue(societyContext, Inventor.class);
    assertEquals("Nikola Tesla", i2.getName());
  }
コード例 #2
0
  @Test
  public void testVariables() throws Exception {
    Inventor tesla = new Inventor("Nikola Tesla", "Serbian");
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setVariable("newName", "Mike Tesla");

    context.setRootObject(tesla);

    parser.parseExpression("foo = #newName").getValue(context);

    assertEquals("Mike Tesla", tesla.getFoo());
  }
コード例 #3
0
 @Test
 public void testConstructors() throws Exception {
   StandardEvaluationContext societyContext = new StandardEvaluationContext();
   societyContext.setRootObject(new IEEE());
   Inventor einstein =
       parser
           .parseExpression(
               "new org.springframework.expression.spel.testresources.Inventor('Albert Einstein',new java.util.Date(), 'German')")
           .getValue(Inventor.class);
   assertEquals("Albert Einstein", einstein.getName());
   // create new inventor instance within add method of List
   parser
       .parseExpression(
           "Members2.add(new org.springframework.expression.spel.testresources.Inventor('Albert Einstein', 'German'))")
       .getValue(societyContext);
 }
コード例 #4
0
 /**
  * Create the root context object, an Inventor instance. Non-qualified property and method
  * references will be resolved against this context object.
  *
  * @param testContext the evaluation context in which to set the root object
  */
 private static void setupRootContextObject(StandardEvaluationContext testContext) {
   GregorianCalendar c = new GregorianCalendar();
   c.set(1856, 7, 9);
   Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");
   tesla.setPlaceOfBirth(new PlaceOfBirth("SmilJan"));
   tesla.setInventions(
       new String[] {
         "Telephone repeater",
         "Rotating magnetic field principle",
         "Polyphase alternating-current system",
         "Induction motor",
         "Alternating-current power transmission",
         "Tesla coil transformer",
         "Wireless communication",
         "Radio",
         "Fluorescent lights"
       });
   testContext.setRootObject(tesla);
 }
コード例 #5
0
  static {
    GregorianCalendar c = new GregorianCalendar();
    c.set(1856, 7, 9);
    tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");
    tesla.setPlaceOfBirth(new PlaceOfBirth("SmilJan"));
    tesla.setInventions(
        new String[] {
          "Telephone repeater",
          "Rotating magnetic field principle",
          "Polyphase alternating-current system",
          "Induction motor",
          "Alternating-current power transmission",
          "Tesla coil transformer",
          "Wireless communication",
          "Radio",
          "Fluorescent lights"
        });

    pupin = new Inventor("Pupin", c.getTime(), "Idvor");
    pupin.setPlaceOfBirth(new PlaceOfBirth("Idvor"));
  }