View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.view;
17  
18  import org.junit.Test;
19  
20  import java.util.Arrays;
21  import java.util.List;
22  import java.util.regex.Matcher;
23  
24  import static org.junit.Assert.assertFalse;
25  import static org.junit.Assert.assertTrue;
26  
27  public class DefaultExpressionEvaluatorTest {
28      @Test
29      public void testServerEvaluationPattern() {
30          List<String> shouldMatch = Arrays.asList(
31                  "(getSomething() || isSomething())",
32                  "(getThis())", "(#getService('test'))");
33  
34          for (String input: shouldMatch) {
35              Matcher matcher = DefaultExpressionEvaluator.SERVER_EVALUATION_PATTERN.matcher(input);
36              assertTrue("Should match server evaluation pattern. input: " + input, matcher.find());
37          }
38  
39          // The first four items in the list contain the characters is or get
40          List<String> shouldNotMatch = Arrays.asList(
41                  "(newCollectionLines['listOfItems'].id == null) or (newCollectionLines['listOfItems'].id == '')",
42                  "(newCollectionLines['budgetItems'].id == null) or (newCollectionLines['budgetItems'].id == '')",
43                  "(listOfItems.id == null)",
44                  "(budgetItems.id == null)",
45                  "(setThis())");
46          for (String input: shouldNotMatch) {
47              Matcher matcher = DefaultExpressionEvaluator.SERVER_EVALUATION_PATTERN.matcher(input);
48              assertFalse("Should not match server evaluation pattern. input: " + input, matcher.find());
49          }
50      }
51  }
52