Source Code Cross Referenced for A6RecordTest.java in  » Net » dnsjava » org » xbill » DNS » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » dnsjava » org.xbill.DNS 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // -*- Java -*-
002:        //
003:        // Copyright (c) 2005, Matthew J. Rutherford <rutherfo@cs.colorado.edu>
004:        // Copyright (c) 2005, University of Colorado at Boulder
005:        // All rights reserved.
006:        // 
007:        // Redistribution and use in source and binary forms, with or without
008:        // modification, are permitted provided that the following conditions are
009:        // met:
010:        // 
011:        // * Redistributions of source code must retain the above copyright
012:        //   notice, this list of conditions and the following disclaimer.
013:        // 
014:        // * Redistributions in binary form must reproduce the above copyright
015:        //   notice, this list of conditions and the following disclaimer in the
016:        //   documentation and/or other materials provided with the distribution.
017:        // 
018:        // * Neither the name of the University of Colorado at Boulder nor the
019:        //   names of its contributors may be used to endorse or promote
020:        //   products derived from this software without specific prior written
021:        //   permission.
022:        // 
023:        // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
024:        // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
025:        // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
026:        // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
027:        // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
028:        // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
029:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
030:        // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
031:        // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
032:        // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
033:        // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
034:        //
035:        package org.xbill.DNS;
036:
037:        import java.io.IOException;
038:        import java.net.InetAddress;
039:        import java.net.UnknownHostException;
040:        import java.util.Arrays;
041:        import junit.framework.TestCase;
042:
043:        public class A6RecordTest extends TestCase {
044:            Name m_an, m_an2, m_rn;
045:            InetAddress m_addr;
046:            String m_addr_string, m_addr_string_canonical;
047:            byte[] m_addr_bytes;
048:            int m_prefix_bits;
049:            long m_ttl;
050:
051:            protected void setUp() throws TextParseException,
052:                    UnknownHostException {
053:                m_an = Name.fromString("My.Absolute.Name.");
054:                m_an2 = Name.fromString("My.Second.Absolute.Name.");
055:                m_rn = Name.fromString("My.Relative.Name");
056:                m_addr_string = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
057:                m_addr_string_canonical = "2001:db8:85a3:8d3:1319:8a2e:370:7334";
058:                m_addr = InetAddress.getByName(m_addr_string);
059:                m_addr_bytes = m_addr.getAddress();
060:                m_ttl = 0x13579;
061:                m_prefix_bits = 9;
062:            }
063:
064:            public void test_ctor_0arg() {
065:                A6Record ar = new A6Record();
066:                assertNull(ar.getName());
067:                assertEquals(0, ar.getType());
068:                assertEquals(0, ar.getDClass());
069:                assertEquals(0, ar.getTTL());
070:            }
071:
072:            public void test_getObject() {
073:                A6Record ar = new A6Record();
074:                Record r = ar.getObject();
075:                assertTrue(r instanceof  A6Record);
076:            }
077:
078:            public void test_ctor_6arg() {
079:                A6Record ar = new A6Record(m_an, DClass.IN, m_ttl,
080:                        m_prefix_bits, m_addr, null);
081:                assertEquals(m_an, ar.getName());
082:                assertEquals(Type.A6, ar.getType());
083:                assertEquals(DClass.IN, ar.getDClass());
084:                assertEquals(m_ttl, ar.getTTL());
085:                assertEquals(m_prefix_bits, ar.getPrefixBits());
086:                assertEquals(m_addr, ar.getSuffix());
087:                assertNull(ar.getPrefix());
088:
089:                // with the prefix name
090:                ar = new A6Record(m_an, DClass.IN, m_ttl, m_prefix_bits,
091:                        m_addr, m_an2);
092:                assertEquals(m_an, ar.getName());
093:                assertEquals(Type.A6, ar.getType());
094:                assertEquals(DClass.IN, ar.getDClass());
095:                assertEquals(m_ttl, ar.getTTL());
096:                assertEquals(m_prefix_bits, ar.getPrefixBits());
097:                assertEquals(m_addr, ar.getSuffix());
098:                assertEquals(m_an2, ar.getPrefix());
099:
100:                // a relative name
101:                try {
102:                    new A6Record(m_rn, DClass.IN, m_ttl, m_prefix_bits, m_addr,
103:                            null);
104:                    fail("RelativeNameException not thrown");
105:                } catch (RelativeNameException e) {
106:                }
107:
108:                // a relative prefix name
109:                try {
110:                    new A6Record(m_an, DClass.IN, m_ttl, m_prefix_bits, m_addr,
111:                            m_rn);
112:                    fail("RelativeNameException not thrown");
113:                } catch (RelativeNameException e) {
114:                }
115:
116:                // invalid prefix bits
117:                try {
118:                    new A6Record(m_rn, DClass.IN, m_ttl, 0x100, m_addr, null);
119:                    fail("IllegalArgumentException not thrown");
120:                } catch (RelativeNameException e) {
121:                }
122:
123:                // an IPv4 address
124:                try {
125:                    new A6Record(m_an, DClass.IN, m_ttl, m_prefix_bits,
126:                            InetAddress.getByName("192.168.0.1"), null);
127:                    fail("IllegalArgumentException not thrown");
128:                } catch (IllegalArgumentException e) {
129:                } catch (UnknownHostException e) {
130:                    fail(e.getMessage());
131:                }
132:            }
133:
134:            public void test_rrFromWire() throws CloneNotSupportedException,
135:                    IOException, UnknownHostException {
136:                // record with no prefix
137:                DNSOutput dout = new DNSOutput();
138:                dout.writeU8(0);
139:                dout.writeByteArray(m_addr_bytes);
140:
141:                DNSInput din = new DNSInput(dout.toByteArray());
142:                A6Record ar = new A6Record();
143:                ar.rrFromWire(din);
144:                assertEquals(0, ar.getPrefixBits());
145:                assertEquals(m_addr, ar.getSuffix());
146:                assertNull(ar.getPrefix());
147:
148:                // record with 9 bit prefix (should result in 15 bytes of the address)
149:                dout = new DNSOutput();
150:                dout.writeU8(9);
151:                dout.writeByteArray(m_addr_bytes, 1, 15);
152:                dout.writeByteArray(m_an2.toWire());
153:
154:                din = new DNSInput(dout.toByteArray());
155:                ar = new A6Record();
156:                ar.rrFromWire(din);
157:                assertEquals(9, ar.getPrefixBits());
158:
159:                byte[] addr_bytes = (byte[]) m_addr_bytes.clone();
160:                addr_bytes[0] = 0;
161:                InetAddress exp = InetAddress.getByAddress(addr_bytes);
162:                assertEquals(exp, ar.getSuffix());
163:                assertEquals(m_an2, ar.getPrefix());
164:            }
165:
166:            public void test_rdataFromString()
167:                    throws CloneNotSupportedException, IOException,
168:                    UnknownHostException {
169:                // record with no prefix
170:                Tokenizer t = new Tokenizer("0 " + m_addr_string);
171:                A6Record ar = new A6Record();
172:                ar.rdataFromString(t, null);
173:                assertEquals(0, ar.getPrefixBits());
174:                assertEquals(m_addr, ar.getSuffix());
175:                assertNull(ar.getPrefix());
176:
177:                // record with 9 bit prefix.  In contrast to the rrFromWire method,
178:                // rdataFromString expects the entire 128 bits to be represented
179:                // in the string
180:                t = new Tokenizer("9 " + m_addr_string + " " + m_an2);
181:                ar = new A6Record();
182:                ar.rdataFromString(t, null);
183:                assertEquals(9, ar.getPrefixBits());
184:                assertEquals(m_addr, ar.getSuffix());
185:                assertEquals(m_an2, ar.getPrefix());
186:
187:                // record with invalid prefixBits
188:                t = new Tokenizer("129");
189:                ar = new A6Record();
190:                try {
191:                    ar.rdataFromString(t, null);
192:                    fail("TextParseException not thrown");
193:                } catch (TextParseException e) {
194:                }
195:
196:                // record with invalid ipv6 address
197:                t = new Tokenizer("0 " + m_addr_string.substring(4));
198:                ar = new A6Record();
199:                try {
200:                    ar.rdataFromString(t, null);
201:                    fail("TextParseException not thrown");
202:                } catch (TextParseException e) {
203:                }
204:            }
205:
206:            public void test_rrToString() {
207:                A6Record ar = new A6Record(m_an, DClass.IN, m_ttl,
208:                        m_prefix_bits, m_addr, m_an2);
209:                String exp = "" + m_prefix_bits + " " + m_addr_string_canonical
210:                        + " " + m_an2;
211:                String out = ar.rrToString();
212:                assertEquals(exp, out);
213:            }
214:
215:            public void test_rrToWire() {
216:                // canonical form
217:                A6Record ar = new A6Record(m_an, DClass.IN, m_ttl,
218:                        m_prefix_bits, m_addr, m_an2);
219:                DNSOutput dout = new DNSOutput();
220:                dout.writeU8(m_prefix_bits);
221:                dout.writeByteArray(m_addr_bytes, 1, 15);
222:                dout.writeByteArray(m_an2.toWireCanonical());
223:
224:                byte[] exp = dout.toByteArray();
225:
226:                dout = new DNSOutput();
227:                ar.rrToWire(dout, null, true);
228:
229:                assertTrue(Arrays.equals(exp, dout.toByteArray()));
230:
231:                // case sensitiveform
232:                dout = new DNSOutput();
233:                dout.writeU8(m_prefix_bits);
234:                dout.writeByteArray(m_addr_bytes, 1, 15);
235:                dout.writeByteArray(m_an2.toWire());
236:
237:                exp = dout.toByteArray();
238:
239:                dout = new DNSOutput();
240:                ar.rrToWire(dout, null, false);
241:                assertTrue(Arrays.equals(exp, dout.toByteArray()));
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.