488c2857fb3ff34d901be74301ac2cd8ed7ee531
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / aaf / v2_0 / JU_AAFSingleLocator.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.cadi.aaf.v2_0;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.MockitoAnnotations.initMocks;
28
29 import java.net.URI;
30 import java.net.URISyntaxException;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import org.onap.aaf.cadi.AbsUserCache;
37 import org.onap.aaf.cadi.Locator;
38 import org.onap.aaf.cadi.LocatorException;
39 import org.onap.aaf.cadi.PropAccess;
40 import org.onap.aaf.cadi.aaf.AAFPermission;
41
42
43 public class JU_AAFSingleLocator {
44
45         @Mock
46         AAFCon con;
47         
48         @Mock
49         AbsUserCache<AAFPermission> cache;
50         
51         @Mock
52         PropAccess propaccess;
53         
54
55         AAFSingleLocator authnObj;
56         
57         @Before
58         public void setUp() {
59                 initMocks(this);
60                 try {
61                         authnObj = new AAFSingleLocator("http://www.google.com");
62                 } catch (URISyntaxException e) {
63                         // TODO Auto-generated catch block
64                         e.printStackTrace();
65                 } 
66         }
67
68         @Test
69         public void testGetRealm() {
70                 try {
71                         URI retVal = authnObj.get(Mockito.mock( Locator.Item.class));
72                         assertEquals("www.google.com",retVal.getHost());
73                 } catch (LocatorException e) {
74                         // TODO Auto-generated catch block
75                         e.printStackTrace();
76                 }
77         }
78         
79         @Test
80         public void testHasItem() {
81                         boolean retVal = authnObj.hasItems();
82                         assertTrue(retVal);
83         }
84         
85         @Test
86         public void testInvalidate() {
87                 try {
88                          authnObj.invalidate(Mockito.mock( Locator.Item.class));
89                 } catch (LocatorException e) {
90                         // TODO Auto-generated catch block
91                         e.printStackTrace();
92                 }
93         }
94         
95         @Test
96         public void testBest() {
97                 try {
98                         Locator.Item retVal = authnObj.best();
99                         assertTrue(retVal.toString().contains("org.onap.aaf.cadi.aaf.v2_0.AAFSingleLocator$SingleItem"));
100                 } catch (LocatorException e) {
101                         // TODO Auto-generated catch block
102                         e.printStackTrace();
103                 }
104         }
105         @Test
106         public void testFirst() {
107                 try {
108                         Locator.Item retVal = authnObj.first();
109                         assertTrue(retVal.toString().contains("org.onap.aaf.cadi.aaf.v2_0.AAFSingleLocator$SingleItem"));
110                 } catch (LocatorException e) {
111                         // TODO Auto-generated catch block
112                         e.printStackTrace();
113                 }
114         }
115         @Test
116         public void testNext() {
117                 try {
118                         Locator.Item retVal = authnObj.next(Mockito.mock( Locator.Item.class));
119                         assertNull(retVal);
120                 } catch (LocatorException e) {
121                         // TODO Auto-generated catch block
122                         e.printStackTrace();
123                 }
124         }
125         
126         @Test
127         public void testRefres() {
128                         boolean retVal = authnObj.refresh();
129                         assertFalse(retVal);
130         }
131         
132         @Test
133         public void testdestroy() {
134                 authnObj.destroy();
135         }
136         
137         
138 }