View Javadoc
1   package org.kuali.ole.deliver.keyvalue.drools;
2   
3   import org.junit.Before;
4   import org.junit.Test;
5   import org.kuali.rice.core.api.criteria.Predicate;
6   import org.kuali.rice.core.api.criteria.QueryByCriteria;
7   import org.kuali.rice.core.api.util.KeyValue;
8   import org.kuali.rice.kim.api.permission.Permission;
9   import org.kuali.rice.kim.api.permission.PermissionQueryResults;
10  import org.kuali.rice.kim.api.permission.PermissionService;
11  import org.kuali.rice.kim.impl.permission.PermissionBo;
12  import org.mockito.Mock;
13  import org.mockito.Mockito;
14  import org.mockito.MockitoAnnotations;
15  
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import static junit.framework.TestCase.assertNotNull;
20  import static org.junit.Assert.assertTrue;
21  import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
22  import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
23  
24  /**
25   * Created by sheiksalahudeenm on 7/6/15.
26   */
27  public class OverridePermissionsKeyValues_UT {
28  
29      @Mock
30      PermissionService mockPermissionService;
31      @Mock
32      PermissionQueryResults mockPermissionQueryResults;
33  
34      @Before
35      public void setUp() throws Exception {
36          MockitoAnnotations.initMocks(this);
37      }
38  
39      @Test
40      public void testGetKeyValues() throws Exception {
41          PermissionBo mockPermissionBo1 = new PermissionBo();
42          mockPermissionBo1.setId("1");
43          mockPermissionBo1.setName("perm1");
44          mockPermissionBo1.setNamespaceCode("OLE-DLVR");
45          Permission.Builder builder = Permission.Builder.create(mockPermissionBo1);
46          Permission mockPermission1 = builder.build();
47  
48          PermissionBo mockPermissionBo2 = new PermissionBo();
49          mockPermissionBo2.setId("2");
50          mockPermissionBo2.setName("perm2");
51          mockPermissionBo2.setNamespaceCode("OLE-DLVR");
52          Permission.Builder builder1 = Permission.Builder.create(mockPermissionBo2);
53          Permission mockPermission2 = builder1.build();
54  
55          PermissionBo mockPermissionBo3 = new PermissionBo();
56          mockPermissionBo3.setId("3");
57          mockPermissionBo3.setName("perm3");
58          mockPermissionBo3.setNamespaceCode("OLE-DLVR");
59          Permission.Builder builder2 = Permission.Builder.create(mockPermissionBo3);
60          Permission mockPermission3 = builder2.build();
61  
62          List<Permission> permissionList = new ArrayList<>();
63          permissionList.add(mockPermission1);
64          permissionList.add(mockPermission2);
65          permissionList.add(mockPermission3);
66  
67          OverridePermissionsKeyValues overridePermissionsKeyValues = new OverridePermissionsKeyValues();
68  
69          Predicate p = and(
70                  equal("namespaceCode", "OLE-DLVR"));
71  
72          Mockito.when(mockPermissionQueryResults.getResults()).thenReturn(permissionList);
73  
74          Mockito.when(mockPermissionService.findPermissions(QueryByCriteria.Builder.fromPredicates(p))).thenReturn(mockPermissionQueryResults);
75  
76          overridePermissionsKeyValues.setPermissionService(mockPermissionService);
77  
78          List<KeyValue> keyValues = overridePermissionsKeyValues.getKeyValues();
79          assertNotNull(keyValues);
80          assertTrue(keyValues.size() > 0);
81      }
82  }