2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 package org.onap.aaf.auth.dao.hl;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.mockito.MockitoAnnotations.initMocks;
27 import java.util.Properties;
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;
46 @RunWith(MockitoJUnitRunner.class)
47 public class JU_CassExecutor {
63 public void setUp() throws Exception {
66 Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf");
67 Mockito.doReturn(new Properties()).when(access).getProperties();
69 } catch (CadiException e) {
70 // TODO Auto-generated catch block
73 f =new Function(trans, q);
77 public void testHasPermission() {
79 CassExecutor cassExecutorObj =new CassExecutor(trans, f);
80 Mockito.doReturn(false).when(q).isGranted(trans, "","","","","");
81 boolean retVal = cassExecutorObj.hasPermission("", "", "", "", "");
82 // System.out.println(retVal);
87 public void testInRole() {
89 CassExecutor cassExecutorObj =new CassExecutor(trans, f);
90 Result<NsSplit> retVal1 = new Result<NsSplit>(null,1,"",new String[0]);
91 Mockito.doReturn(retVal1).when(q).deriveNsSplit(trans, "test");
93 boolean retVal = cassExecutorObj.inRole("test");
94 // System.out.println(retVal);
99 public void testNamespace() {
100 f =new Function(trans, q);
101 CassExecutor cassExecutorObj =new CassExecutor(trans, f);
102 Result<Data> retVal1 = new Result<Data>(null,1,"",new String[0]);
103 Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null);
107 retVal = cassExecutorObj.namespace();
108 } catch (Exception e) {
109 System.out.println(e.getMessage());
110 assertEquals("33", e.getMessage());
112 System.out.println(retVal);
113 // assertFalse(retVal);
117 public void testId() {
118 Mockito.doReturn("").when(trans).user();
119 CassExecutor cassExecutorObj =new CassExecutor(trans, f);
120 String retVal = cassExecutorObj.id();
121 assertEquals("", retVal);
125 public void testNamespaceSuccess() {
126 Mockito.doAnswer(new Answer() {
127 private int count = 0;
129 public Object answer(InvocationOnMock invocation) {
131 return "test@test.com";
135 }).when(trans).user();
136 f =new Function(trans, q);
137 CassExecutor cassExecutorObj =new CassExecutor(trans, f);
138 Result<Data> retVal1 = new Result<Data>(null,0,"",new String[0]);
139 Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null);
144 retVal = cassExecutorObj.namespace();
145 } catch (Exception e) {
147 System.out.println(e.getMessage());
148 // assertNull( e.getMessage());
150 // System.out.println(retVal);
151 // assertFalse(retVal);