2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.misc.env.util.test;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.assertFalse;
27 import org.junit.Test;
28 import org.onap.aaf.misc.env.util.IPValidator;
30 public class JU_IPValidator {
34 assertTrue(IPValidator.ipv4("10.10.10.10"));
35 assertTrue(IPValidator.ipv4("127.0.0.0"));
36 assertFalse(IPValidator.ipv4("10"));
37 assertFalse(IPValidator.ipv4("10.10.10"));
38 assertFalse(IPValidator.ipv4("10.10.10."));
39 assertFalse(IPValidator.ipv4("10.10.10.10."));
40 assertFalse(IPValidator.ipv4("10.10.10.10.10"));
41 assertFalse(IPValidator.ipv4("something10.10.10.10"));
42 assertTrue(IPValidator.ipv4("0.10.10.10"));
43 assertTrue(IPValidator.ipv4("0.0.0.0"));
44 assertTrue(IPValidator.ipv4("0.10.10.10"));
45 assertFalse(IPValidator.ipv4("011.255.255.255"));
46 assertFalse(IPValidator.ipv4("255.01.255.255"));
47 assertFalse(IPValidator.ipv4("255.255.255.256"));
48 assertFalse(IPValidator.ipv4("255.299.255.255"));
51 assertTrue(IPValidator.ipv6("0000:0000:0000:0000:0000:0000:0000:0000"));
52 assertTrue(IPValidator.ipv6("0:0:0:0:0:0:0:0"));
53 assertTrue(IPValidator.ipv6("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));
54 assertTrue(IPValidator.ipv6("2001:8DB:0:0:23:F422:FE3B:AC10"));
55 assertTrue(IPValidator.ipv6("2001:8DB::23:F422:FE3B:AC10"));
56 assertTrue(IPValidator.ipv6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));
57 assertTrue(IPValidator.ipv6("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"));
58 assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));
59 assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));
60 // more than one Double Colons
61 assertFalse(IPValidator.ipv6("0000:0000:0000::0000::0000"));
62 assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10:FFFF"));
66 assertTrue(IPValidator.ip("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));
67 assertTrue(IPValidator.ip("192.168.7.2"));