1
2
3
4
5
6
7
8
9
10
11
12
13
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 NotExpressionTest {
26
27 @Test
28 public void testNone() throws Exception {
29 NotExpression expression = new NotExpression();
30 User user = new UserImpl();
31
32 assertTrue(expression.evaluate(user));
33 }
34
35 @Test
36 public void testOne() throws Exception {
37 NotExpression expression = new NotExpression();
38 PersonAttributeExpression prsnAttExp = new PersonAttributeExpression("user.authenticated", "false");
39
40 expression.addChild(prsnAttExp);
41
42 User user = new UserImpl();
43
44 assertTrue(expression.evaluate(user));
45
46 user.addAttribute("user.authenticated", "false");
47 assertFalse(expression.evaluate(user));
48 }
49
50 @Test
51 public void testTwo() throws Exception {
52 NotExpression expression = new NotExpression();
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 assertTrue(expression.evaluate(user));
62
63 user.addAttribute("user.authenticated", "false");
64 assertFalse(expression.evaluate(user));
65
66 user.removeAttribute("user.authenticated");
67 user.addAttribute("user.iu.ou", "BL");
68 assertFalse(expression.evaluate(user));
69
70 user.addAttribute("user.authenticated", "false");
71 assertFalse(expression.evaluate(user));
72 }
73
74 }