001 /*
002 * $Id: PrivateMemberTest.java 1104080 2011-05-17 09:22:09Z mcucchiara $
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020 package org.apache.commons.ognl.test;
021
022 import junit.framework.TestCase;
023 import junit.framework.TestSuite;
024 import org.apache.commons.ognl.DefaultMemberAccess;
025 import org.apache.commons.ognl.Ognl;
026 import org.apache.commons.ognl.OgnlContext;
027 import org.apache.commons.ognl.OgnlException;
028 import org.junit.Before;
029
030 /**
031 * This is a test program for private access in OGNL. shows the failures and a summary.
032 */
033 public class PrivateMemberTest
034 extends TestCase
035 {
036 private String _privateProperty = "private value";
037
038 protected OgnlContext context;
039
040 /*
041 * =================================================================== Public static methods
042 * ===================================================================
043 */
044 public static TestSuite suite()
045 {
046 return new TestSuite( PrivateMemberTest.class );
047 }
048
049 /*
050 * =================================================================== Constructors
051 * ===================================================================
052 */
053 public PrivateMemberTest( String name )
054 {
055 super( name );
056 }
057
058 /*
059 * =================================================================== Public methods
060 * ===================================================================
061 */
062 private String getPrivateProperty()
063 {
064 return _privateProperty;
065 }
066
067 public void testPrivateAccessor()
068 throws OgnlException
069 {
070 assertEquals( Ognl.getValue( "privateProperty", context, this ), getPrivateProperty() );
071 }
072
073 public void testPrivateField()
074 throws OgnlException
075 {
076 assertEquals( Ognl.getValue( "_privateProperty", context, this ), _privateProperty );
077 }
078
079 /*
080 * =================================================================== Overridden methods
081 * ===================================================================
082 */
083 @Before
084 @Override
085 public void setUp()
086 {
087 context = (OgnlContext) Ognl.createDefaultContext( null );
088 context.setMemberAccess( new DefaultMemberAccess( true ) );
089 }
090 }