001/** 002 * Copyright 2011-2013 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016package org.kuali.mobility.security.authz.expression; 017 018import org.junit.Test; 019import org.kuali.mobility.security.user.api.User; 020import org.kuali.mobility.security.user.entity.UserImpl; 021 022import static org.junit.Assert.assertFalse; 023import static org.junit.Assert.assertTrue; 024 025public class NotExpressionTest { 026 027 @Test 028 public void testNone() throws Exception { 029 NotExpression expression = new NotExpression(); 030 User user = new UserImpl(); 031 032 assertTrue(expression.evaluate(user)); 033 } 034 035 @Test 036 public void testOne() throws Exception { 037 NotExpression expression = new NotExpression(); 038 PersonAttributeExpression prsnAttExp = new PersonAttributeExpression("user.authenticated", "false"); 039 040 expression.addChild(prsnAttExp); 041 042 User user = new UserImpl(); 043 044 assertTrue(expression.evaluate(user)); 045 046 user.addAttribute("user.authenticated", "false"); 047 assertFalse(expression.evaluate(user)); 048 } 049 050 @Test 051 public void testTwo() throws Exception { 052 NotExpression expression = new NotExpression(); 053 PersonAttributeExpression prsnAttExp = new PersonAttributeExpression("user.authenticated", "false"); 054 expression.addChild(prsnAttExp); 055 056 prsnAttExp = new PersonAttributeExpression("user.iu.ou", "BL"); 057 expression.addChild(prsnAttExp); 058 059 User user = new UserImpl(); 060 061 assertTrue(expression.evaluate(user)); 062 063 user.addAttribute("user.authenticated", "false"); 064 assertFalse(expression.evaluate(user)); 065 066 user.removeAttribute("user.authenticated"); 067 user.addAttribute("user.iu.ou", "BL"); 068 assertFalse(expression.evaluate(user)); 069 070 user.addAttribute("user.authenticated", "false"); 071 assertFalse(expression.evaluate(user)); 072 } 073 074}