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;
48 import junit.framework.Assert;
51 @RunWith(MockitoJUnitRunner.class)
52 public class JU_DirectAAFLocator {
67 public void setUp() throws Exception {
72 public void testConstructorVersionExcpetion() {
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);
76 Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,"");
78 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","test");
79 } catch (LocatorException e) {
80 // System.out.println(e.getMessage());
81 assertEquals("Invalid Version String: test", e.getMessage());
84 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","20.test");
85 } catch (LocatorException e) {
86 // System.out.println(e.getMessage());
87 assertEquals("Invalid Version String: 20.test", e.getMessage());
89 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","20.20.test");
90 } catch (LocatorException e) {
91 // System.out.println(e.getMessage());
92 assertEquals("Invalid Version String: 20.20.test", e.getMessage());
94 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","20.20.20.test");
95 } catch (LocatorException e) {
96 // System.out.println(e.getMessage());
97 assertEquals("Invalid Version String: 20.20.20.test", e.getMessage());
102 public void testConstructorExcpetion() {
103 Mockito.doReturn(access).when(env).access();
104 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
105 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
106 Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,"");
107 Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,"");
108 Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_APP_NS,"AAF_NS");
110 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test",null);
111 } catch (LocatorException e) {
112 // System.out.println(e.getMessage());
116 // NOTE: These mocks to not well represent the DirectAAFLocator Class.
118 public void testConstructorUriExcpetion() {
119 Mockito.doReturn(access).when(env).access();
120 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
121 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
122 Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,"");
123 Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,"");
124 Mockito.doReturn("20 30").when(access).getProperty(Config.AAF_URL,null);
126 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","192.0.0.1");
127 } catch (LocatorException e) {
128 // System.out.println(e.getMessage());
129 assertTrue(e.getMessage().contains("Illegal character in path at index 2:"));
135 public void testRefresh() {
137 DirectAAFLocator aafLocatorObj=null;
138 PropAccess access = Mockito.mock(PropAccess.class);
139 Mockito.doReturn(access).when(env).access();
140 Mockito.doReturn(trans).when(env).newTransNoAvg();
141 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
142 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
143 Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,"");
144 Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,"");
145 Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null);
147 aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30");
148 } catch (LocatorException e) {
149 // TODO Auto-generated catch block
152 Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"",new Object[0]);
154 Data data= new Data();
159 retVal1.value = new ArrayList<Data>();
160 retVal1.value.add(data);
162 Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test");
163 boolean retVal = aafLocatorObj.refresh();
164 // System.out.println(retVal);
169 public void testRefreshNOK() {
171 DirectAAFLocator aafLocatorObj=null;
172 PropAccess access = Mockito.mock(PropAccess.class);
173 Mockito.doReturn(access).when(env).access();
174 Mockito.doReturn(trans).when(env).newTransNoAvg();
175 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
176 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
177 Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,"");
178 Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,"");
179 Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null);
181 aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30");
182 } catch (LocatorException e) {
183 // TODO Auto-generated catch block
186 Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"",new String[0]);
188 Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test");
189 boolean retVal = aafLocatorObj.refresh();
190 // System.out.println(retVal);