2 * ============LICENSE_START====================================================
\r
4 * ===========================================================================
\r
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ===========================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END====================================================
\r
21 package org.onap.aaf.auth.locate.validation;
\r
23 import static org.junit.Assert.assertEquals;
\r
24 import static org.mockito.Mockito.when;
\r
26 import java.util.ArrayList;
\r
27 import java.util.List;
\r
29 import org.junit.Before;
\r
30 import org.junit.Test;
\r
31 import org.mockito.Answers;
\r
32 import org.mockito.Mock;
\r
33 import org.mockito.MockitoAnnotations;
\r
35 import locate.v1_0.Endpoint;
\r
36 import locate.v1_0.Endpoints;
\r
37 import locate.v1_0.MgmtEndpoint;
\r
38 import locate.v1_0.MgmtEndpoint.SpecialPorts;
\r
39 import locate.v1_0.MgmtEndpoints;
\r
41 public class JU_LocateValidatorTest {
\r
44 private Endpoint endpoint;
\r
46 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
\r
47 private Endpoints endpoints;
\r
48 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
\r
49 private MgmtEndpoints me;
\r
50 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
\r
51 private MgmtEndpoint mgmtEndpoint;
\r
52 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
\r
53 private SpecialPorts specialPort;
\r
56 public void setup() {
\r
57 MockitoAnnotations.initMocks(this);
\r
61 public void testNullEndPoint() {
\r
62 LocateValidator validator = new LocateValidator();
\r
64 validator.endpoint(null);
\r
65 assertEquals("Endpoint Data is null.\n", validator.errs());
\r
69 public void testEndPoint() {
\r
70 LocateValidator validator = new LocateValidator();
\r
72 when(endpoint.getName()).thenReturn("Endpoint1");
\r
73 when(endpoint.getHostname()).thenReturn("HOST1");
\r
74 when(endpoint.getPort()).thenReturn(9090);
\r
75 when(endpoint.getProtocol()).thenReturn("HTTP");
\r
77 validator.endpoint(endpoint);
\r
79 assertEquals("Endpoint Name (Endpoint1) must prefixed by Namespace\n", validator.errs());
\r
83 public void testSubProtoCol() {
\r
84 LocateValidator validator = new LocateValidator();
\r
86 List<String> subProtocol = new ArrayList<>();
\r
87 subProtocol.add(null);
\r
89 when(endpoint.getName()).thenReturn("EndPoint.Endpoint1");
\r
90 when(endpoint.getHostname()).thenReturn("HOST1");
\r
91 when(endpoint.getPort()).thenReturn(9090);
\r
92 when(endpoint.getProtocol()).thenReturn("HTTP");
\r
93 when(endpoint.getSubprotocol()).thenReturn(subProtocol);
\r
95 validator.endpoint(endpoint);
\r
97 assertEquals("Endpoint Subprotocol is null.\n", validator.errs());
\r
101 public void testNullEndpoints() {
\r
102 LocateValidator validator = new LocateValidator();
\r
104 validator.endpoints(null, false);
\r
105 validator.mgmt_endpoint_key(null);
\r
106 validator.mgmt_endpoints(null, false);
\r
107 assertEquals("Endpoints Data is null.\n" + "MgmtEndpoints Data is null.\n" + "MgmtEndpoints Data is null.\n",
\r
112 public void testEndpointsWithListContaingNull() {
\r
113 LocateValidator validator = new LocateValidator();
\r
114 when(endpoints.getEndpoint().size()).thenReturn(0);
\r
115 when(me.getMgmtEndpoint().size()).thenReturn(0);
\r
117 validator.endpoints(endpoints, true);
\r
118 validator.mgmt_endpoints(me, false);
\r
119 assertEquals("Endpoints contains no endpoints\n" + "MgmtEndpoints contains no data\n", validator.errs());
\r
123 public void testEndpointsWithSpecialPortsNull() {
\r
124 LocateValidator validator = new LocateValidator();
\r
126 when(endpoint.getName()).thenReturn("EndPoint.Endpoint1");
\r
127 when(endpoint.getHostname()).thenReturn("HOST1");
\r
128 when(endpoint.getPort()).thenReturn(9090);
\r
129 when(endpoint.getProtocol()).thenReturn("HTTP");
\r
130 List<String> subprotocol = new ArrayList<>();
\r
131 when(endpoint.getSubprotocol()).thenReturn(subprotocol);
\r
133 List<Endpoint> endpointList = new ArrayList<>();
\r
134 endpointList.add(endpoint);
\r
136 when(mgmtEndpoint.getName()).thenReturn("EndPoint.Endpoint1");
\r
137 when(mgmtEndpoint.getHostname()).thenReturn("HOST1");
\r
138 when(mgmtEndpoint.getPort()).thenReturn(9090);
\r
139 when(mgmtEndpoint.getProtocol()).thenReturn("HTTP");
\r
140 List<SpecialPorts> specialPorts = new ArrayList<>();
\r
141 specialPorts.add(null);
\r
142 when(mgmtEndpoint.getSpecialPorts()).thenReturn(specialPorts);
\r
143 List<MgmtEndpoint> mgmtEndpoints = new ArrayList<>();
\r
144 mgmtEndpoints.add(mgmtEndpoint);
\r
146 when(endpoints.getEndpoint()).thenReturn(endpointList);
\r
147 when(me.getMgmtEndpoint()).thenReturn(mgmtEndpoints);
\r
149 validator.endpoints(endpoints, false);
\r
150 validator.mgmt_endpoints(me, true);
\r
151 assertEquals("Special Ports is null.\n", validator.errs());
\r
155 public void testEndpointsWithSpecialPorts() {
\r
156 LocateValidator validator = new LocateValidator();
\r
158 when(mgmtEndpoint.getName()).thenReturn("EndPoint.Endpoint1");
\r
159 when(mgmtEndpoint.getHostname()).thenReturn("HOST1");
\r
160 when(mgmtEndpoint.getPort()).thenReturn(9090);
\r
161 when(mgmtEndpoint.getProtocol()).thenReturn("HTTP");
\r
163 List<SpecialPorts> specialPorts = new ArrayList<>();
\r
164 specialPorts.add(specialPort);
\r
166 when(specialPort.getName()).thenReturn("Port1");
\r
167 when(specialPort.getProtocol()).thenReturn("HTTP");
\r
168 when(specialPort.getPort()).thenReturn(9090);
\r
170 List<String> versions = new ArrayList<>();
\r
173 when(specialPort.getProtocolVersions()).thenReturn(versions);
\r
175 when(mgmtEndpoint.getSpecialPorts()).thenReturn(specialPorts);
\r
176 List<MgmtEndpoint> mgmtEndpoints = new ArrayList<>();
\r
177 mgmtEndpoints.add(mgmtEndpoint);
\r
179 when(me.getMgmtEndpoint()).thenReturn(mgmtEndpoints);
\r
181 validator.endpoints(endpoints, false);
\r
182 validator.mgmt_endpoints(me, true);
\r
183 validator.mgmt_endpoint_key(me);
\r
184 assertEquals(false, validator.err());
\r