\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
+ @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 (Endpoint1) 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<>();\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<>();\r
+ when(endpoint.getSubprotocol()).thenReturn(subprotocol);\r
+\r
+ List<Endpoint> endpointList = new ArrayList<>();\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<>();\r
+ specialPorts.add(null);\r
+ when(mgmtEndpoint.getSpecialPorts()).thenReturn(specialPorts);\r
+ List<MgmtEndpoint> mgmtEndpoints = new ArrayList<>();\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<>();\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<>();\r
+ versions.add("1");\r
+\r
+ when(specialPort.getProtocolVersions()).thenReturn(versions);\r
+\r
+ when(mgmtEndpoint.getSpecialPorts()).thenReturn(specialPorts);\r
+ List<MgmtEndpoint> mgmtEndpoints = new ArrayList<>();\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