View Javadoc

1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.mobility.security.authz.expression;
17  
18  import org.junit.Test;
19  import org.kuali.mobility.security.user.api.User;
20  import org.kuali.mobility.security.user.entity.UserImpl;
21  
22  import static org.junit.Assert.assertFalse;
23  import static org.junit.Assert.assertTrue;
24  
25  public class OrExpressionTest {
26  
27  	@Test
28  	public void testNone() throws Exception {
29  	    OrExpression expression = new OrExpression();
30          User user = new UserImpl();
31  	    
32  	    assertFalse(expression.evaluate(user));
33  	}
34  	
35  	@Test
36  	public void testOne() throws Exception {
37  		OrExpression expression = new OrExpression();
38  	    PersonAttributeExpression prsnAttExp = new PersonAttributeExpression("user.authenticated", "false");
39  	    
40  	    expression.addChild(prsnAttExp);
41  	    
42          User user = new UserImpl();
43  	    
44  	    assertFalse(expression.evaluate(user));
45  	    
46  	    user.addAttribute("user.authenticated", "false");
47  	    assertTrue(expression.evaluate(user));
48  	}
49  	
50  	@Test
51  	public void testTwo() throws Exception {
52  		OrExpression expression = new OrExpression();
53  	    PersonAttributeExpression prsnAttExp = new PersonAttributeExpression("user.authenticated", "false");
54  	    expression.addChild(prsnAttExp);
55  	    
56  	    prsnAttExp = new PersonAttributeExpression("user.iu.ou", "BL");
57  	    expression.addChild(prsnAttExp);
58  	    
59          User user = new UserImpl();
60  	    
61  	    assertFalse(expression.evaluate(user));
62  	    
63  	    user.addAttribute("user.authenticated", "false");
64  	    assertTrue(expression.evaluate(user));
65  	    
66  	    user.removeAttribute("user.authenticated");
67  	    user.addAttribute("user.iu.ou", "BL");
68  	    assertTrue(expression.evaluate(user));
69  	    
70  	    user.addAttribute("user.authenticated", "false");
71  	    assertTrue(expression.evaluate(user));
72  	}
73  
74  }