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 {
51 private static final Object NO_PARAM = new Object[0];
65 public void setUp() throws Exception {
68 Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf");
69 Mockito.doReturn(new Properties()).when(access).getProperties();
71 } catch (CadiException e) {
72 // TODO Auto-generated catch block
75 f =new Function(trans, q);
79 public void testHasPermission() {
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);
89 public void testInRole() {
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");
95 boolean retVal = cassExecutorObj.inRole("test");
96 // System.out.println(retVal);
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);
109 retVal = cassExecutorObj.namespace();
110 } catch (Exception e) {
111 System.out.println(e.getMessage());
112 assertEquals("33", e.getMessage());
114 System.out.println(retVal);
115 // assertFalse(retVal);
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);
127 public void testNamespaceSuccess() {
128 Mockito.doAnswer(new Answer<Object>() {
129 private int count = 0;
131 public Object answer(InvocationOnMock invocation) {
133 return "test@test.com";
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);
146 /*retVal =*/ cassExecutorObj.namespace();
147 } catch (Exception e) {
149 System.out.println(e.getMessage());
150 // assertNull( e.getMessage());
152 // System.out.println(retVal);
153 // assertFalse(retVal);