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("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,"");
107 Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_APP_NS,"AAF_NS");
109 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test",null);
110 } catch (LocatorException e) {
111 // System.out.println(e.getMessage());
115 // NOTE: These mocks to not well represent the DirectAAFLocator Class.
117 public void testConstructorUriExcpetion() {
118 Mockito.doReturn(access).when(env).access();
119 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
120 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
121 Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,"");
122 Mockito.doReturn("20 30").when(access).getProperty(Config.AAF_URL,null);
124 DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","192.0.0.1");
125 } catch (LocatorException e) {
126 // System.out.println(e.getMessage());
127 assertTrue(e.getMessage().contains("Illegal character in path at index 2:"));
133 public void testRefresh() {
135 DirectAAFLocator aafLocatorObj=null;
136 PropAccess access = Mockito.mock(PropAccess.class);
137 Mockito.doReturn(access).when(env).access();
138 Mockito.doReturn(trans).when(env).newTransNoAvg();
139 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
140 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
141 Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,"");
142 Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null);
144 aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30");
145 } catch (LocatorException e) {
146 // TODO Auto-generated catch block
149 Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"",new Object[0]);
151 Data data= new Data();
156 retVal1.value = new ArrayList<Data>();
157 retVal1.value.add(data);
159 Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test");
160 boolean retVal = aafLocatorObj.refresh();
161 // System.out.println(retVal);
166 public void testRefreshNOK() {
168 DirectAAFLocator aafLocatorObj=null;
169 PropAccess access = Mockito.mock(PropAccess.class);
170 Mockito.doReturn(access).when(env).access();
171 Mockito.doReturn(trans).when(env).newTransNoAvg();
172 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
173 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
174 Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,"");
175 Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null);
177 aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30");
178 } catch (LocatorException e) {
179 // TODO Auto-generated catch block
182 Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"",new String[0]);
184 Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test");
185 boolean retVal = aafLocatorObj.refresh();
186 // System.out.println(retVal);