1 /* 2 * $Id: PrivateMemberTest.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 junit.framework.TestCase; 23 import junit.framework.TestSuite; 24 import org.apache.commons.ognl.DefaultMemberAccess; 25 import org.apache.commons.ognl.Ognl; 26 import org.apache.commons.ognl.OgnlContext; 27 import org.apache.commons.ognl.OgnlException; 28 import org.junit.Before; 29 30 /** 31 * This is a test program for private access in OGNL. shows the failures and a summary. 32 */ 33 public class PrivateMemberTest 34 extends TestCase 35 { 36 private String _privateProperty = "private value"; 37 38 protected OgnlContext context; 39 40 /* 41 * =================================================================== Public static methods 42 * =================================================================== 43 */ 44 public static TestSuite suite() 45 { 46 return new TestSuite( PrivateMemberTest.class ); 47 } 48 49 /* 50 * =================================================================== Constructors 51 * =================================================================== 52 */ 53 public PrivateMemberTest( String name ) 54 { 55 super( name ); 56 } 57 58 /* 59 * =================================================================== Public methods 60 * =================================================================== 61 */ 62 private String getPrivateProperty() 63 { 64 return _privateProperty; 65 } 66 67 public void testPrivateAccessor() 68 throws OgnlException 69 { 70 assertEquals( Ognl.getValue( "privateProperty", context, this ), getPrivateProperty() ); 71 } 72 73 public void testPrivateField() 74 throws OgnlException 75 { 76 assertEquals( Ognl.getValue( "_privateProperty", context, this ), _privateProperty ); 77 } 78 79 /* 80 * =================================================================== Overridden methods 81 * =================================================================== 82 */ 83 @Before 84 @Override 85 public void setUp() 86 { 87 context = (OgnlContext) Ognl.createDefaultContext( null ); 88 context.setMemberAccess( new DefaultMemberAccess( true ) ); 89 } 90 }