package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
-/**
- */
public class IpAddressNoZoneBuilder {
private static final Pattern IPV4_NO_ZONE_PATTERN =
private static final Pattern IPV6_NO_ZONE_PATTERN1 =
Pattern.compile("[0-9a-fA-F:\\.]*");
-
public static IpAddressNoZone getDefaultInstance(final String defaultValue) {
- final Matcher ipv4NoZoneMatcher = IPV4_NO_ZONE_PATTERN.matcher(defaultValue);
-
- if (ipv4NoZoneMatcher.matches()) {
- if (IPV6_NO_ZONE_PATTERN1.matcher(defaultValue).matches()) {
- throw new IllegalArgumentException(
- String.format("Cannot create IpNoZoneAddress from \"%s\", matches both %s and %s",
- defaultValue, Ipv4AddressNoZone.class.getSimpleName(), Ipv6AddressNoZone.class.getSimpleName()));
-
- }
+ if (IPV4_NO_ZONE_PATTERN.matcher(defaultValue).matches()) {
return new IpAddressNoZone((new Ipv4AddressNoZone(defaultValue)));
} else if (IPV6_NO_ZONE_PATTERN1.matcher(defaultValue).matches()) {
return new IpAddressNoZone((new Ipv6AddressNoZone(defaultValue)));
throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue);
}
}
-
-}
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZoneBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
+
+public class IpAddressNoZoneBuilderTest {
+
+ @Test
+ public void testGetDefaultInstance() throws Exception {
+ testIpv4("1.1.1.1");
+ testIpv4("192.168.155.100");
+ testIpv4("1.192.1.221");
+ testIpv6("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789");
+ testIpv6("2001:DB8:0:0:8:800:200C:417A");
+ testIpv6("0:0:0:0:0:0:0:0");
+ testIpv6("::1.2.3.4");
+ testIpv6("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789");
+ testIpv6("2001:DB8:0:0:8:800:200C:417A");
+ testIpv6("2001:DB8::8:800:200C:417A");
+ testIpv6("FF01:0:0:0:0:0:0:101");
+ testIpv6("FF01::101");
+ testIpv6("0:0:0:0:0:0:0:1");
+ testIpv6("::1");
+ testIpv6("::");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testIllegalArgumentException() {
+ IpAddressNoZoneBuilder.getDefaultInstance("2001:0DB8::CD3/60");
+ }
+
+ private static void testIpv4(final String ip) {
+ final IpAddressNoZone defaultInstance = IpAddressNoZoneBuilder.getDefaultInstance(ip);
+ assertEquals(new IpAddressNoZone(new Ipv4AddressNoZone(ip)), defaultInstance);
+ }
+
+ private static void testIpv6(final String ip) {
+ final IpAddressNoZone defaultInstance = IpAddressNoZoneBuilder.getDefaultInstance(ip);
+ assertEquals(new IpAddressNoZone(new Ipv6AddressNoZone(ip)), defaultInstance);
+ }
+}
\ No newline at end of file