1 /*
2 * $Id: SimplePropertyTreeTest.java 1104080 2011-05-17 09:22:09Z mcucchiara $
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 */
20 package org.apache.commons.ognl.test;
21
22 import static junit.framework.Assert.assertTrue;
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26
27 import org.apache.commons.ognl.Ognl;
28 import org.junit.Before;
29 import org.junit.runner.RunWith;
30 import org.junit.runners.Parameterized;
31 import org.junit.runners.Parameterized.Parameters;
32
33 @RunWith(value = Parameterized.class)
34 public class SimplePropertyTreeTest
35 extends OgnlTestCase
36 {
37 private static Object[][] TESTS = { { "name", Boolean.TRUE }, { "foo", Boolean.TRUE },
38 { "name[i]", Boolean.FALSE }, { "name + foo", Boolean.FALSE }, { "name.foo", Boolean.FALSE },
39 { "name.foo.bar", Boolean.FALSE }, { "name.{? foo }", Boolean.FALSE }, { "name.( foo )", Boolean.FALSE } };
40
41 /*
42 * =================================================================== Public static methods
43 * ===================================================================
44 */
45 @Parameters
46 public static Collection<Object[]> data()
47 {
48 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
49 for ( int i = 0; i < TESTS.length; i++ )
50 {
51 Object[] tmp = new Object[6];
52 tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
53 tmp[1] = null;
54 tmp[2] = TESTS[i][0];
55 tmp[3] = TESTS[i][1];
56
57 data.add( tmp );
58 }
59 return data;
60 }
61
62 /*
63 * =================================================================== Constructors
64 * ===================================================================
65 */
66 public SimplePropertyTreeTest( String name, Object root, String expressionString, Object expectedResult,
67 Object setValue, Object expectedAfterSetResult )
68 {
69 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
70 }
71
72 /*
73 * =================================================================== Overridden methods
74 * ===================================================================
75 */
76 @Before
77 @Override
78 public void runTest()
79 throws Exception
80 {
81 assertTrue( Ognl.isSimpleProperty( getExpression(), _context ) == ( (Boolean) getExpectedResult() ).booleanValue() );
82 }
83 }