d026500c00d897ef6b9f51da8ebee32506c0880b
[aaf/authz.git] / auth / auth-cass / src / test / java / org / onap / aaf / auth / direct / test / JU_DirectLocatorCreateor.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21 package org.onap.aaf.auth.direct.test;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.MockitoAnnotations.initMocks;
25
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.runners.MockitoJUnitRunner;
32 import org.onap.aaf.auth.dao.cass.LocateDAO;
33 import org.onap.aaf.auth.direct.DirectLocatorCreator;
34 import org.onap.aaf.auth.env.AuthzEnv;
35 import org.onap.aaf.cadi.LocatorException;
36 import org.onap.aaf.cadi.PropAccess;
37 import org.onap.aaf.cadi.config.Config;
38
39
40 @RunWith(MockitoJUnitRunner.class) 
41 public class JU_DirectLocatorCreateor {
42
43         @Mock
44         LocateDAO ldao;
45         
46         @Mock
47         AuthzEnv env;
48         
49         @Before
50         public void setUp() throws Exception {
51                 initMocks(this);
52         }
53         
54         @Test
55         public void testCreate() {
56                 PropAccess access = Mockito.mock(PropAccess.class);
57                 Mockito.doReturn(access).when(env).access();
58                 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
59                 Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
60                 DirectLocatorCreator aafLocatorObj=new DirectLocatorCreator(env, ldao);
61                 try {
62                         aafLocatorObj.setSelf("test", 9080);
63                         aafLocatorObj.create("test","30.20.30.30");
64                 } catch (LocatorException e) {
65                         // TODO Auto-generated catch block
66                         e.printStackTrace();
67                 }
68         }
69         
70         @Test
71         public void testCreateHostnameNull() {
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);
76                 DirectLocatorCreator aafLocatorObj=new DirectLocatorCreator(env, ldao);
77                 try {
78                         aafLocatorObj.create("test","30.20.30.30");
79                 } catch (LocatorException e) {
80                         // TODO Auto-generated catch block
81                         e.printStackTrace();
82                 }
83         }
84         
85         
86 }