--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.auth.locate.validation;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Answers;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+\r
+import locate.v1_0.Endpoint;\r
+import locate.v1_0.Endpoints;\r
+import locate.v1_0.MgmtEndpoint;\r
+import locate.v1_0.MgmtEndpoint.SpecialPorts;\r
+import locate.v1_0.MgmtEndpoints;\r
+\r
+public class JU_LocateValidatorTest {\r
+\r
+ @Mock\r
+ private Endpoint endpoint;\r
+\r
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)\r
+ private Endpoints endpoints;\r
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)\r
+ private MgmtEndpoints me;\r
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)\r
+ private MgmtEndpoint mgmtEndpoint;\r
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)\r
+ private SpecialPorts specialPort;\r
+\r
+ @Before\r
+ public void setup() {\r
+ MockitoAnnotations.initMocks(this);\r
+ }\r
+\r
+ @Test\r
+ public void testNullEndPoint() {\r
+ LocateValidator validator = new LocateValidator();\r
+\r
+ validator.endpoint(null);\r
+ assertEquals("Endpoint Data is null.\n", validator.errs());\r
+ }\r
+\r
+ @Test\r
+ public void testEndPoint() {\r
+ LocateValidator validator = new LocateValidator();\r
+\r
+ when(endpoint.getName()).thenReturn("Endpoint1");\r
+ when(endpoint.getHostname()).thenReturn("HOST1");\r
+ when(endpoint.getPort()).thenReturn(9090);\r
+ when(endpoint.getProtocol()).thenReturn("HTTP");\r
+\r
+ validator.endpoint(endpoint);\r
+\r
+ assertEquals("Endpoint Name must prefixed by Namespace\n", validator.errs());\r
+ }\r
+\r
+ @Test\r
+ public void testSubProtoCol() {\r
+ LocateValidator validator = new LocateValidator();\r
+\r
+ List<String> subProtocol = new ArrayList<String>();\r
+ subProtocol.add(null);\r
+\r
+ when(endpoint.getName()).thenReturn("EndPoint.Endpoint1");\r
+ when(endpoint.getHostname()).thenReturn("HOST1");\r
+ when(endpoint.getPort()).thenReturn(9090);\r
+ when(endpoint.getProtocol()).thenReturn("HTTP");\r
+ when(endpoint.getSubprotocol()).thenReturn(subProtocol);\r
+\r
+ validator.endpoint(endpoint);\r
+\r
+ assertEquals("Endpoint Subprotocol is null.\n", validator.errs());\r
+ }\r
+\r
+ @Test\r
+ public void testNullEndpoints() {\r
+ LocateValidator validator = new LocateValidator();\r
+\r
+ validator.endpoints(null, false);\r
+ validator.mgmt_endpoint_key(null);\r
+ validator.mgmt_endpoints(null, false);\r
+ assertEquals("Endpoints Data is null.\n" + "MgmtEndpoints Data is null.\n" + "MgmtEndpoints Data is null.\n",\r
+ validator.errs());\r
+ }\r
+\r
+ @Test\r
+ public void testEndpointsWithListContaingNull() {\r
+ LocateValidator validator = new LocateValidator();\r
+ when(endpoints.getEndpoint().size()).thenReturn(0);\r
+ when(me.getMgmtEndpoint().size()).thenReturn(0);\r
+\r
+ validator.endpoints(endpoints, true);\r
+ validator.mgmt_endpoints(me, false);\r
+ assertEquals("Endpoints contains no endpoints\n" + "MgmtEndpoints contains no data\n", validator.errs());\r
+ }\r
+\r
+ @Test\r
+ public void testEndpointsWithSpecialPortsNull() {\r
+ LocateValidator validator = new LocateValidator();\r
+\r
+ when(endpoint.getName()).thenReturn("EndPoint.Endpoint1");\r
+ when(endpoint.getHostname()).thenReturn("HOST1");\r
+ when(endpoint.getPort()).thenReturn(9090);\r
+ when(endpoint.getProtocol()).thenReturn("HTTP");\r
+ List<String> subprotocol = new ArrayList<String>();\r
+ when(endpoint.getSubprotocol()).thenReturn(subprotocol);\r
+\r
+ List<Endpoint> endpointList = new ArrayList<Endpoint>();\r
+ endpointList.add(endpoint);\r
+\r
+ when(mgmtEndpoint.getName()).thenReturn("EndPoint.Endpoint1");\r
+ when(mgmtEndpoint.getHostname()).thenReturn("HOST1");\r
+ when(mgmtEndpoint.getPort()).thenReturn(9090);\r
+ when(mgmtEndpoint.getProtocol()).thenReturn("HTTP");\r
+ List<SpecialPorts> specialPorts = new ArrayList<SpecialPorts>();\r
+ specialPorts.add(null);\r
+ when(mgmtEndpoint.getSpecialPorts()).thenReturn(specialPorts);\r
+ List<MgmtEndpoint> mgmtEndpoints = new ArrayList<MgmtEndpoint>();\r
+ mgmtEndpoints.add(mgmtEndpoint);\r
+\r
+ when(endpoints.getEndpoint()).thenReturn(endpointList);\r
+ when(me.getMgmtEndpoint()).thenReturn(mgmtEndpoints);\r
+\r
+ validator.endpoints(endpoints, false);\r
+ validator.mgmt_endpoints(me, true);\r
+ assertEquals("Special Ports is null.\n", validator.errs());\r
+ }\r
+\r
+ @Test\r
+ public void testEndpointsWithSpecialPorts() {\r
+ LocateValidator validator = new LocateValidator();\r
+\r
+ when(mgmtEndpoint.getName()).thenReturn("EndPoint.Endpoint1");\r
+ when(mgmtEndpoint.getHostname()).thenReturn("HOST1");\r
+ when(mgmtEndpoint.getPort()).thenReturn(9090);\r
+ when(mgmtEndpoint.getProtocol()).thenReturn("HTTP");\r
+\r
+ List<SpecialPorts> specialPorts = new ArrayList<SpecialPorts>();\r
+ specialPorts.add(specialPort);\r
+\r
+ when(specialPort.getName()).thenReturn("Port1");\r
+ when(specialPort.getProtocol()).thenReturn("HTTP");\r
+ when(specialPort.getPort()).thenReturn(9090);\r
+\r
+ List<String> versions = new ArrayList<String>();\r
+ versions.add("1");\r
+\r
+ when(specialPort.getProtocolVersions()).thenReturn(versions);\r
+\r
+ when(mgmtEndpoint.getSpecialPorts()).thenReturn(specialPorts);\r
+ List<MgmtEndpoint> mgmtEndpoints = new ArrayList<MgmtEndpoint>();\r
+ mgmtEndpoints.add(mgmtEndpoint);\r
+\r
+ when(me.getMgmtEndpoint()).thenReturn(mgmtEndpoints);\r
+\r
+ validator.endpoints(endpoints, false);\r
+ validator.mgmt_endpoints(me, true);\r
+ validator.mgmt_endpoint_key(me);\r
+ assertEquals(false, validator.err());\r
+\r
+ }\r
+}\r