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.direct.test;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.MockitoAnnotations.initMocks;
28 import java.util.ArrayList;
29 import java.util.List;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import org.mockito.runners.MockitoJUnitRunner;
37 import org.onap.aaf.auth.dao.cass.LocateDAO;
38 import org.onap.aaf.auth.dao.cass.LocateDAO.Data;
39 import org.onap.aaf.auth.direct.DirectAAFLocator;
40 import org.onap.aaf.auth.env.AuthzEnv;
41 import org.onap.aaf.auth.env.AuthzTrans;
42 import org.onap.aaf.auth.layer.Result;
43 import org.onap.aaf.cadi.Access;
44 import org.onap.aaf.cadi.LocatorException;
45 import org.onap.aaf.cadi.PropAccess;
46 import org.onap.aaf.cadi.config.Config;
49 @RunWith(MockitoJUnitRunner.class)
50 public class JU_DirectAAFLocator {
65 public void setUp() throws Exception {
70 public void testConstructorExcpetion() {
72 PropAccess access = Mockito.mock(PropAccess.class);
73 Mockito.doReturn(access).when(env).access();
74 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
75 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
77 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","test");
78 } catch (LocatorException e) {
79 // System.out.println(e.getMessage());
80 assertEquals("Invalid Version String: test", e.getMessage());
85 public void testConstructorUriExcpetion() {
87 PropAccess access = Mockito.mock(PropAccess.class);
88 Mockito.doReturn(access).when(env).access();
89 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
90 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
92 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao," test","3.2");
93 } catch (LocatorException e) {
94 // System.out.println(e.getMessage());
95 assertTrue(e.getMessage().contains("Illegal character in path at index"));
99 public void testRefresh() {
101 DirectAAFLocator aafLocatorObj=null;
102 PropAccess access = Mockito.mock(PropAccess.class);
103 Mockito.doReturn(access).when(env).access();
104 Mockito.doReturn(trans).when(env).newTransNoAvg();
105 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
106 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
108 aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30");
109 } catch (LocatorException e) {
110 // TODO Auto-generated catch block
113 Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"",new String[0]);
115 Data data= new Data();
120 retVal1.value = new ArrayList<Data>();
121 retVal1.value.add(data);
123 Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test");
124 boolean retVal = aafLocatorObj.refresh();
125 // System.out.println(retVal);
130 public void testRefreshNOK() {
132 DirectAAFLocator aafLocatorObj=null;
133 PropAccess access = Mockito.mock(PropAccess.class);
134 Mockito.doReturn(access).when(env).access();
135 Mockito.doReturn(trans).when(env).newTransNoAvg();
136 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
137 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
139 aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30");
140 } catch (LocatorException e) {
141 // TODO Auto-generated catch block
144 Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"",new String[0]);
146 Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test");
147 boolean retVal = aafLocatorObj.refresh();
148 // System.out.println(retVal);