Remove Tabs, per Jococo
[aaf/authz.git] / auth / auth-cass / src / test / java / org / onap / aaf / auth / dao / hl / JU_CassExecutor.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * 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, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21 package org.onap.aaf.auth.dao.hl;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.mockito.MockitoAnnotations.initMocks;
26
27 import java.util.Properties;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.invocation.InvocationOnMock;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.mockito.stubbing.Answer;
37 import org.onap.aaf.auth.common.Define;
38 import org.onap.aaf.auth.dao.cass.NsSplit;
39 import org.onap.aaf.auth.dao.cass.UserRoleDAO.Data;
40 import org.onap.aaf.auth.env.AuthzTransImpl;
41 import org.onap.aaf.auth.layer.Result;
42 import org.onap.aaf.cadi.Access;
43 import org.onap.aaf.cadi.CadiException;
44
45
46 @RunWith(MockitoJUnitRunner.class) 
47 public class JU_CassExecutor {
48
49     
50     
51     private static final Object NO_PARAM = new Object[0];
52
53     @Mock
54     AuthzTransImpl trans;
55     
56     @Mock
57     Question q;
58     
59     @Mock
60     Access access;
61     
62     Function f;
63     
64     @Before
65     public void setUp() throws Exception {
66         initMocks(this);
67         try {
68             Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf");
69             Mockito.doReturn(new Properties()).when(access).getProperties();
70             Define.set(access);
71         } catch (CadiException e) {
72             // TODO Auto-generated catch block
73             e.printStackTrace();
74         }
75         f =new Function(trans, q);
76     }
77     
78     @Test
79     public void testHasPermission() {
80         
81         CassExecutor cassExecutorObj =new CassExecutor(trans, f);
82         Mockito.doReturn(false).when(q).isGranted(trans, "","","","","");
83         boolean retVal = cassExecutorObj.hasPermission("", "", "", "", "");
84 //        System.out.println(retVal);
85         assertFalse(retVal);
86     }    
87     
88     @Test
89     public void testInRole() {
90         
91         CassExecutor cassExecutorObj =new CassExecutor(trans, f);
92         Result<NsSplit> retVal1 = new Result<NsSplit>(null,1,"",NO_PARAM);
93         Mockito.doReturn(retVal1).when(q).deriveNsSplit(trans, "test");
94         
95         boolean retVal = cassExecutorObj.inRole("test");
96 //        System.out.println(retVal);
97         assertFalse(retVal);
98     }
99     
100     @Test
101     public void testNamespace() {
102         f =new Function(trans, q);
103         CassExecutor cassExecutorObj =new CassExecutor(trans, f);
104         Result<Data> retVal1 = new Result<Data>(null,1,"",NO_PARAM);
105         Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null);
106         
107         String retVal="";
108         try {
109             retVal = cassExecutorObj.namespace();
110         } catch (Exception e) {
111             System.out.println(e.getMessage());
112             assertEquals("33", e.getMessage());
113         }
114         System.out.println(retVal);
115 //        assertFalse(retVal);
116     }
117     
118     @Test
119     public void testId() {
120         Mockito.doReturn("").when(trans).user();
121         CassExecutor cassExecutorObj =new CassExecutor(trans, f);
122         String retVal = cassExecutorObj.id();
123         assertEquals("", retVal);
124     }
125     
126     @Test
127     public void testNamespaceSuccess() {
128         Mockito.doAnswer(new Answer<Object>() {
129             private int count = 0;
130
131             public Object answer(InvocationOnMock invocation) {
132                 if (count++ == 1)
133                     return "test@test.com";
134
135                 return null;
136             }
137         }).when(trans).user();
138         f =new Function(trans, q);
139         CassExecutor cassExecutorObj =new CassExecutor(trans, f);
140         Result<Data> retVal1 = new Result<Data>(null,0,"",NO_PARAM);
141         Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null);
142         
143         
144 //        String retVal="";
145         try {
146             /*retVal =*/ cassExecutorObj.namespace();
147         } catch (Exception e) {
148             e.printStackTrace();
149             System.out.println(e.getMessage());
150 //            assertNull( e.getMessage());
151         }
152 //        System.out.println(retVal);
153 //        assertFalse(retVal);
154     }
155     
156 }