f4bbd27743c9ad369092a9f8d013f21ad3366a29
[aaf/authz.git] / auth / auth-cass / src / test / java / org / onap / aaf / auth / direct / test / JU_DirectRegistrar.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.mockito.MockitoAnnotations.initMocks;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.runners.MockitoJUnitRunner;
31 import org.onap.aaf.auth.dao.cass.LocateDAO;
32 import org.onap.aaf.auth.dao.cass.LocateDAO.Data;
33 import org.onap.aaf.auth.direct.DirectRegistrar;
34 import org.onap.aaf.auth.env.AuthzEnv;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.auth.layer.Result;
37 import org.onap.aaf.cadi.Access;
38 import org.onap.aaf.cadi.CadiException;
39 import org.onap.aaf.cadi.config.Config;
40
41 @RunWith(MockitoJUnitRunner.class)
42 public class JU_DirectRegistrar {
43
44         @Mock
45         LocateDAO ldao;
46
47         // @Mock
48         // Data locate;
49
50         @Mock
51         Access access;
52
53         @Mock
54         AuthzEnv env;
55
56         // @Mock
57         AuthzTrans trans;
58
59         @Before
60         public void setUp() throws Exception {
61                 initMocks(this);
62         }
63
64         @Test
65         public void testUpdate() {
66                 DirectRegistrar registrarObj = null;
67                 org.onap.aaf.auth.layer.Result<Void> rs = null;
68                 try {
69                         Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE, null);
70                         Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE, null);
71                         Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER, "");
72                         Mockito.doReturn("20,test,test").when(access).getProperty(Config.AAF_LOCATOR_ENTRIES, "");
73                         rs = new org.onap.aaf.auth.layer.Result<Void>(null, 0, "test",  new Object[0]);
74                         Mockito.doReturn(rs).when(ldao).update(Mockito.any(), Mockito.any());
75                         registrarObj = new DirectRegistrar(access, ldao, 9080);
76
77                 
78                         org.onap.aaf.auth.layer.Result<Void> retVal1 = new Result<Void>(null, 0, "test", new Object[0]);
79                         Mockito.doReturn(trans).when(env).newTransNoAvg();
80                         // Mockito.doReturn(retVal1).when(ldao).update(trans,locate);
81                         registrarObj.update(env);
82         
83                         rs = new org.onap.aaf.auth.layer.Result<Void>(null, 1, "test", new Object[0]);
84                         Mockito.doReturn(rs).when(ldao).update(Mockito.any(), Mockito.any());
85                         registrarObj = new DirectRegistrar(access, ldao, 9080);
86                         registrarObj.update(env);
87                 } catch (CadiException e) {
88                         // TODO Auto-generated catch block
89                         e.printStackTrace();
90                 }
91                 // System.out.println(retVal1);
92         }
93
94         @Test
95         public void testCancel() {
96                 DirectRegistrar registrarObj = null;
97                 try {
98                         Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE, null);
99                         Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE, null);
100                         Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER, "");
101                         Mockito.doReturn("20,test,test").when(access).getProperty(Config.AAF_LOCATOR_ENTRIES, "");
102                         registrarObj = new DirectRegistrar(access, ldao, 9080);
103                         
104                         org.onap.aaf.auth.layer.Result<Void> rs = new org.onap.aaf.auth.layer.Result<Void>(null, 1, "test", new Object[0]);
105                         Mockito.doReturn(rs).when(ldao).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean());
106                 } catch (CadiException e) {
107                         // TODO Auto-generated catch block
108                         e.printStackTrace();
109                 }
110                  registrarObj.cancel(env);
111         }
112
113 }