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====================================================
22 package org.onap.aaf.auth.service.test;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
26 import java.util.ArrayList;
27 import java.util.GregorianCalendar;
28 import java.util.List;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.Spy;
33 import org.mockito.runners.MockitoJUnitRunner;
34 import org.onap.aaf.auth.common.Define;
35 import org.onap.aaf.auth.dao.cached.CachedCertDAO;
36 import org.onap.aaf.auth.dao.cached.CachedCredDAO;
37 import org.onap.aaf.auth.dao.cached.CachedNSDAO;
38 import org.onap.aaf.auth.dao.cached.CachedPermDAO;
39 import org.onap.aaf.auth.dao.cached.CachedRoleDAO;
40 import org.onap.aaf.auth.dao.cached.CachedUserRoleDAO;
41 import org.onap.aaf.auth.dao.cass.ApprovalDAO;
42 import org.onap.aaf.auth.dao.cass.CacheInfoDAO;
43 import org.onap.aaf.auth.dao.cass.DelegateDAO;
44 import org.onap.aaf.auth.dao.cass.FutureDAO;
45 import org.onap.aaf.auth.dao.cass.HistoryDAO;
46 import org.onap.aaf.auth.dao.cass.LocateDAO;
47 import org.onap.aaf.auth.dao.cass.NsDAO;
48 import org.onap.aaf.auth.dao.cass.UserRoleDAO;
49 import org.onap.aaf.auth.dao.hl.Question;
50 import org.onap.aaf.auth.env.AuthzEnv;
51 import org.onap.aaf.auth.env.AuthzTrans;
52 import org.onap.aaf.auth.service.AuthzCassServiceImpl;
53 import org.onap.aaf.auth.service.mapper.Mapper_2_0;
54 import org.onap.aaf.cadi.PropAccess;
55 import org.onap.aaf.cadi.config.Config;
56 import org.onap.aaf.org.DefaultOrg;
57 import org.onap.aaf.org.DefaultOrgIdentity;
59 import aaf.v2_0.Approvals;
60 import aaf.v2_0.Certs;
61 import aaf.v2_0.Delgs;
62 import aaf.v2_0.Error;
63 import aaf.v2_0.History;
66 import aaf.v2_0.Perms;
68 import aaf.v2_0.Request;
69 import aaf.v2_0.Roles;
70 import aaf.v2_0.UserRoles;
71 import aaf.v2_0.Users;
73 @RunWith(MockitoJUnitRunner.class)
74 public abstract class JU_BaseServiceImpl {
75 protected AuthzCassServiceImpl<Nss, Perms, Pkey, Roles, Users, UserRoles, Delgs, Certs, Keys, Request, History, Error, Approvals>
77 protected Mapper_2_0 mapper;
80 protected DefaultOrg org;
82 protected DefaultOrgIdentity orgIdentity;
84 protected HistoryDAO historyDAO = mock(HistoryDAO.class);
85 protected CacheInfoDAO cacheInfoDAO = mock(CacheInfoDAO.class);
86 protected CachedNSDAO nsDAO = mock(CachedNSDAO.class);
87 protected CachedPermDAO permDAO = mock(CachedPermDAO.class);
88 protected CachedRoleDAO roleDAO = mock(CachedRoleDAO.class);
89 protected CachedUserRoleDAO userRoleDAO = mock(CachedUserRoleDAO.class);
90 protected CachedCredDAO credDAO = mock(CachedCredDAO.class);
91 protected CachedCertDAO certDAO = mock(CachedCertDAO.class);
92 protected LocateDAO locateDAO = mock(LocateDAO.class);
93 protected FutureDAO futureDAO = mock(FutureDAO.class);
94 protected DelegateDAO delegateDAO = mock(DelegateDAO.class);
95 protected ApprovalDAO approvalDAO = mock(ApprovalDAO.class);
98 protected static PropAccess access = new PropAccess();
101 protected static AuthzEnv env = new AuthzEnv(access);
104 protected static AuthzTrans trans = env.newTransNoAvg();
108 protected Question question = new Question(trans,historyDAO,cacheInfoDAO,nsDAO,permDAO,roleDAO,userRoleDAO,
109 credDAO,certDAO,locateDAO,futureDAO,delegateDAO,approvalDAO);
111 public void setUp() throws Exception {
112 when(trans.org()).thenReturn(org);
113 when(org.getDomain()).thenReturn("org.onap");
115 access.setProperty(Config.CADI_LATITUDE, "38.0");
116 access.setProperty(Config.CADI_LONGITUDE, "-72.0");
118 mapper = new Mapper_2_0(question);
119 acsi = new AuthzCassServiceImpl<>(trans, mapper, question);
123 // Common Data Objects
125 protected List<NsDAO.Data> nsData(String name) {
126 NsDAO.Data ndd = new NsDAO.Data();
128 int dot = name.lastIndexOf('.');
132 ndd.parent=name.substring(0,dot);
134 List<NsDAO.Data> rv = new ArrayList<NsDAO.Data>();
139 protected UserRoleDAO.Data urData(String user, String ns, String rname, int days) {
140 UserRoleDAO.Data urdd = new UserRoleDAO.Data();
144 urdd.role = ns + '.' + rname;
145 GregorianCalendar gc = new GregorianCalendar();
146 gc.add(GregorianCalendar.DAY_OF_YEAR, days);
147 urdd.expires = gc.getTime();
152 protected <T> List<T> listOf(T t) {
153 List<T> list = new ArrayList<>();
158 protected <T> List<T> emptyList(Class<T> cls) {
159 return new ArrayList<>();