Source Code Cross Referenced for APLRecordTest.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 java.util.ArrayList;
042:        import java.util.List;
043:        import junit.framework.Test;
044:        import junit.framework.TestCase;
045:        import junit.framework.TestSuite;
046:        import org.xbill.DNS.APLRecord.Element;
047:
048:        public class APLRecordTest {
049:            public static class Test_Element_init extends TestCase {
050:                InetAddress m_addr4;
051:                InetAddress m_addr6;
052:
053:                protected void setUp() throws TextParseException,
054:                        UnknownHostException {
055:                    m_addr4 = InetAddress.getByName("193.160.232.5");
056:                    m_addr6 = InetAddress
057:                            .getByName("2001:db8:85a3:8d3:1319:8a2e:370:7334");
058:                }
059:
060:                public void test_valid_IPv4() {
061:                    Element el = new Element(true, m_addr4, 16);
062:                    assertEquals(Address.IPv4, el.family);
063:                    assertEquals(true, el.negative);
064:                    assertEquals(m_addr4, el.address);
065:                    assertEquals(16, el.prefixLength);
066:                }
067:
068:                public void test_invalid_IPv4() {
069:                    try {
070:                        new Element(true, m_addr4, 33);
071:                        fail("IllegalArgumentException not thrown");
072:                    } catch (IllegalArgumentException e) {
073:                    }
074:                }
075:
076:                public void test_valid_IPv6() {
077:                    Element el = new Element(false, m_addr6, 74);
078:                    assertEquals(Address.IPv6, el.family);
079:                    assertEquals(false, el.negative);
080:                    assertEquals(m_addr6, el.address);
081:                    assertEquals(74, el.prefixLength);
082:                }
083:
084:                public void test_invalid_IPv6() {
085:                    try {
086:                        new Element(true, m_addr6, 129);
087:                        fail("IllegalArgumentException not thrown");
088:                    } catch (IllegalArgumentException e) {
089:                    }
090:                }
091:            }
092:
093:            public static class Test_init extends TestCase {
094:                Name m_an, m_rn;
095:                long m_ttl;
096:                ArrayList m_elements;
097:                InetAddress m_addr4;
098:                String m_addr4_string;
099:                byte[] m_addr4_bytes;
100:                InetAddress m_addr6;
101:                String m_addr6_string;
102:                byte[] m_addr6_bytes;
103:
104:                protected void setUp() throws TextParseException,
105:                        UnknownHostException {
106:                    m_an = Name.fromString("My.Absolute.Name.");
107:                    m_rn = Name.fromString("My.Relative.Name");
108:                    m_ttl = 0x13579;
109:                    m_addr4_string = "193.160.232.5";
110:                    m_addr4 = InetAddress.getByName(m_addr4_string);
111:                    m_addr4_bytes = m_addr4.getAddress();
112:
113:                    m_addr6_string = "2001:db8:85a3:8d3:1319:8a2e:370:7334";
114:                    m_addr6 = InetAddress.getByName(m_addr6_string);
115:                    m_addr6_bytes = m_addr6.getAddress();
116:
117:                    m_elements = new ArrayList(2);
118:                    Element e = new Element(true, m_addr4, 12);
119:                    m_elements.add(e);
120:
121:                    e = new Element(false, m_addr6, 64);
122:                    m_elements.add(e);
123:                }
124:
125:                public void test_0arg() throws UnknownHostException {
126:                    APLRecord ar = new APLRecord();
127:                    assertNull(ar.getName());
128:                    assertEquals(0, ar.getType());
129:                    assertEquals(0, ar.getDClass());
130:                    assertEquals(0, ar.getTTL());
131:                    assertNull(ar.getElements());
132:                }
133:
134:                public void test_getObject() {
135:                    APLRecord ar = new APLRecord();
136:                    Record r = ar.getObject();
137:                    assertTrue(r instanceof  APLRecord);
138:                }
139:
140:                public void test_4arg_basic() {
141:                    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl,
142:                            m_elements);
143:                    assertEquals(m_an, ar.getName());
144:                    assertEquals(Type.APL, ar.getType());
145:                    assertEquals(DClass.IN, ar.getDClass());
146:                    assertEquals(m_ttl, ar.getTTL());
147:                    assertEquals(m_elements, ar.getElements());
148:                }
149:
150:                public void test_4arg_empty_elements() {
151:                    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl,
152:                            new ArrayList());
153:                    assertEquals(new ArrayList(), ar.getElements());
154:                }
155:
156:                public void test_4arg_relative_name() {
157:                    try {
158:                        new APLRecord(m_rn, DClass.IN, m_ttl, m_elements);
159:                        fail("RelativeNameException not thrown");
160:                    } catch (RelativeNameException e) {
161:                    }
162:                }
163:
164:                public void test_4arg_invalid_elements() {
165:                    m_elements = new ArrayList();
166:                    m_elements.add(new Object());
167:                    try {
168:                        new APLRecord(m_an, DClass.IN, m_ttl, m_elements);
169:                        fail("IllegalArgumentException not thrown");
170:                    } catch (IllegalArgumentException e) {
171:                    }
172:                }
173:            }
174:
175:            public static class Test_rrFromWire extends TestCase {
176:                InetAddress m_addr4;
177:                byte[] m_addr4_bytes;
178:                InetAddress m_addr6;
179:                byte[] m_addr6_bytes;
180:
181:                protected void setUp() throws TextParseException,
182:                        UnknownHostException {
183:                    m_addr4 = InetAddress.getByName("193.160.232.5");
184:                    m_addr4_bytes = m_addr4.getAddress();
185:
186:                    m_addr6 = InetAddress
187:                            .getByName("2001:db8:85a3:8d3:1319:8a2e:370:7334");
188:                    m_addr6_bytes = m_addr6.getAddress();
189:                }
190:
191:                public void test_validIPv4() throws IOException {
192:                    byte[] raw = new byte[] { 0, 1, 8, (byte) 0x84,
193:                            m_addr4_bytes[0], m_addr4_bytes[1],
194:                            m_addr4_bytes[2], m_addr4_bytes[3] };
195:
196:                    DNSInput di = new DNSInput(raw);
197:                    APLRecord ar = new APLRecord();
198:                    ar.rrFromWire(di);
199:
200:                    ArrayList exp = new ArrayList();
201:                    exp.add(new Element(true, m_addr4, 8));
202:                    assertEquals(exp, ar.getElements());
203:                }
204:
205:                public void test_validIPv4_short_address() throws IOException {
206:                    byte[] raw = new byte[] { 0, 1, 20, (byte) 0x83,
207:                            m_addr4_bytes[0], m_addr4_bytes[1],
208:                            m_addr4_bytes[2] };
209:
210:                    DNSInput di = new DNSInput(raw);
211:                    APLRecord ar = new APLRecord();
212:                    ar.rrFromWire(di);
213:
214:                    InetAddress a = InetAddress.getByName("193.160.232.0");
215:
216:                    ArrayList exp = new ArrayList();
217:                    exp.add(new Element(true, a, 20));
218:                    assertEquals(exp, ar.getElements());
219:                }
220:
221:                public void test_invalid_IPv4_prefix() throws IOException {
222:                    byte[] raw = new byte[] { 0, 1, 33, (byte) 0x84,
223:                            m_addr4_bytes[0], m_addr4_bytes[1],
224:                            m_addr4_bytes[2], m_addr4_bytes[3] };
225:
226:                    DNSInput di = new DNSInput(raw);
227:                    APLRecord ar = new APLRecord();
228:                    try {
229:                        ar.rrFromWire(di);
230:                        fail("WireParseException not thrown");
231:                    } catch (WireParseException e) {
232:                    }
233:                }
234:
235:                public void test_invalid_IPv4_length() throws IOException {
236:                    byte[] raw = new byte[] { 0, 1, 8, (byte) 0x85,
237:                            m_addr4_bytes[0], m_addr4_bytes[1],
238:                            m_addr4_bytes[2], m_addr4_bytes[3], 10 };
239:
240:                    DNSInput di = new DNSInput(raw);
241:                    APLRecord ar = new APLRecord();
242:                    try {
243:                        ar.rrFromWire(di);
244:                        fail("WireParseException not thrown");
245:                    } catch (WireParseException e) {
246:                    }
247:                }
248:
249:                public void test_multiple_validIPv4() throws IOException {
250:                    byte[] raw = new byte[] { 0, 1, 8, (byte) 0x84,
251:                            m_addr4_bytes[0], m_addr4_bytes[1],
252:                            m_addr4_bytes[2], m_addr4_bytes[3], 0, 1, 30,
253:                            (byte) 0x4, m_addr4_bytes[0], m_addr4_bytes[1],
254:                            m_addr4_bytes[2], m_addr4_bytes[3], };
255:
256:                    DNSInput di = new DNSInput(raw);
257:                    APLRecord ar = new APLRecord();
258:                    ar.rrFromWire(di);
259:
260:                    ArrayList exp = new ArrayList();
261:                    exp.add(new Element(true, m_addr4, 8));
262:                    exp.add(new Element(false, m_addr4, 30));
263:                    assertEquals(exp, ar.getElements());
264:                }
265:
266:                public void test_validIPv6() throws IOException {
267:                    byte[] raw = new byte[] { 0, 2, (byte) 115, (byte) 0x10,
268:                            m_addr6_bytes[0], m_addr6_bytes[1],
269:                            m_addr6_bytes[2], m_addr6_bytes[3],
270:                            m_addr6_bytes[4], m_addr6_bytes[5],
271:                            m_addr6_bytes[6], m_addr6_bytes[7],
272:                            m_addr6_bytes[8], m_addr6_bytes[9],
273:                            m_addr6_bytes[10], m_addr6_bytes[11],
274:                            m_addr6_bytes[12], m_addr6_bytes[13],
275:                            m_addr6_bytes[14], m_addr6_bytes[15] };
276:
277:                    DNSInput di = new DNSInput(raw);
278:                    APLRecord ar = new APLRecord();
279:                    ar.rrFromWire(di);
280:
281:                    ArrayList exp = new ArrayList();
282:                    exp.add(new Element(false, m_addr6, 115));
283:                    assertEquals(exp, ar.getElements());
284:                }
285:
286:                public void test_valid_nonIP() throws IOException {
287:                    byte[] raw = new byte[] { 0, 3, (byte) 130, (byte) 0x85, 1,
288:                            2, 3, 4, 5 };
289:
290:                    DNSInput di = new DNSInput(raw);
291:                    APLRecord ar = new APLRecord();
292:                    ar.rrFromWire(di);
293:
294:                    List l = ar.getElements();
295:                    assertEquals(1, l.size());
296:
297:                    Element el = (Element) l.get(0);
298:                    assertEquals(3, el.family);
299:                    assertEquals(true, el.negative);
300:                    assertEquals(130, el.prefixLength);
301:                    assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 },
302:                            (byte[]) el.address));
303:                }
304:            }
305:
306:            public static class Test_rdataFromString extends TestCase {
307:                InetAddress m_addr4;
308:                String m_addr4_string;
309:                byte[] m_addr4_bytes;
310:                InetAddress m_addr6;
311:                String m_addr6_string;
312:                byte[] m_addr6_bytes;
313:
314:                protected void setUp() throws TextParseException,
315:                        UnknownHostException {
316:                    m_addr4_string = "193.160.232.5";
317:                    m_addr4 = InetAddress.getByName(m_addr4_string);
318:                    m_addr4_bytes = m_addr4.getAddress();
319:
320:                    m_addr6_string = "2001:db8:85a3:8d3:1319:8a2e:370:7334";
321:                    m_addr6 = InetAddress.getByName(m_addr6_string);
322:                    m_addr6_bytes = m_addr6.getAddress();
323:                }
324:
325:                public void test_validIPv4() throws IOException {
326:                    Tokenizer t = new Tokenizer("1:" + m_addr4_string + "/11\n");
327:                    APLRecord ar = new APLRecord();
328:                    ar.rdataFromString(t, null);
329:
330:                    ArrayList exp = new ArrayList();
331:                    exp.add(new Element(false, m_addr4, 11));
332:
333:                    assertEquals(exp, ar.getElements());
334:
335:                    // make sure extra token is put back
336:                    assertEquals(Tokenizer.EOL, t.get().type);
337:                }
338:
339:                public void test_valid_multi() throws IOException {
340:                    Tokenizer t = new Tokenizer("1:" + m_addr4_string
341:                            + "/11 !2:" + m_addr6_string + "/100");
342:                    APLRecord ar = new APLRecord();
343:                    ar.rdataFromString(t, null);
344:
345:                    ArrayList exp = new ArrayList();
346:                    exp.add(new Element(false, m_addr4, 11));
347:                    exp.add(new Element(true, m_addr6, 100));
348:
349:                    assertEquals(exp, ar.getElements());
350:                }
351:
352:                public void test_validIPv6() throws IOException {
353:                    Tokenizer t = new Tokenizer("!2:" + m_addr6_string
354:                            + "/36\n");
355:                    APLRecord ar = new APLRecord();
356:                    ar.rdataFromString(t, null);
357:
358:                    ArrayList exp = new ArrayList();
359:                    exp.add(new Element(true, m_addr6, 36));
360:
361:                    assertEquals(exp, ar.getElements());
362:
363:                    // make sure extra token is put back
364:                    assertEquals(Tokenizer.EOL, t.get().type);
365:                }
366:
367:                public void test_no_colon() throws IOException {
368:                    Tokenizer t = new Tokenizer("!1192.68.0.1/20");
369:                    APLRecord ar = new APLRecord();
370:                    try {
371:                        ar.rdataFromString(t, null);
372:                        fail("TextParseException not thrown");
373:                    } catch (TextParseException e) {
374:                    }
375:                }
376:
377:                public void test_colon_and_slash_swapped() throws IOException {
378:                    Tokenizer t = new Tokenizer("!1/192.68.0.1:20");
379:                    APLRecord ar = new APLRecord();
380:                    try {
381:                        ar.rdataFromString(t, null);
382:                        fail("TextParseException not thrown");
383:                    } catch (TextParseException e) {
384:                    }
385:                }
386:
387:                public void test_no_slash() throws IOException {
388:                    Tokenizer t = new Tokenizer("!1:192.68.0.1|20");
389:                    APLRecord ar = new APLRecord();
390:                    try {
391:                        ar.rdataFromString(t, null);
392:                        fail("TextParseException not thrown");
393:                    } catch (TextParseException e) {
394:                    }
395:                }
396:
397:                public void test_empty_family() throws IOException {
398:                    Tokenizer t = new Tokenizer("!:192.68.0.1/20");
399:                    APLRecord ar = new APLRecord();
400:                    try {
401:                        ar.rdataFromString(t, null);
402:                        fail("TextParseException not thrown");
403:                    } catch (TextParseException e) {
404:                    }
405:                }
406:
407:                public void test_malformed_family() throws IOException {
408:                    Tokenizer t = new Tokenizer("family:192.68.0.1/20");
409:                    APLRecord ar = new APLRecord();
410:                    try {
411:                        ar.rdataFromString(t, null);
412:                        fail("TextParseException not thrown");
413:                    } catch (TextParseException e) {
414:                    }
415:                }
416:
417:                public void test_invalid_family() throws IOException {
418:                    Tokenizer t = new Tokenizer("3:192.68.0.1/20");
419:                    APLRecord ar = new APLRecord();
420:                    try {
421:                        ar.rdataFromString(t, null);
422:                        fail("TextParseException not thrown");
423:                    } catch (TextParseException e) {
424:                    }
425:                }
426:
427:                public void test_empty_prefix() throws IOException {
428:                    Tokenizer t = new Tokenizer("1:192.68.0.1/");
429:                    APLRecord ar = new APLRecord();
430:                    try {
431:                        ar.rdataFromString(t, null);
432:                        fail("TextParseException not thrown");
433:                    } catch (TextParseException e) {
434:                    }
435:                }
436:
437:                public void test_malformed_prefix() throws IOException {
438:                    Tokenizer t = new Tokenizer("1:192.68.0.1/prefix");
439:                    APLRecord ar = new APLRecord();
440:                    try {
441:                        ar.rdataFromString(t, null);
442:                        fail("TextParseException not thrown");
443:                    } catch (TextParseException e) {
444:                    }
445:                }
446:
447:                public void test_invalid_prefix() throws IOException {
448:                    Tokenizer t = new Tokenizer("1:192.68.0.1/33");
449:                    APLRecord ar = new APLRecord();
450:                    try {
451:                        ar.rdataFromString(t, null);
452:                        fail("TextParseException not thrown");
453:                    } catch (TextParseException e) {
454:                    }
455:                }
456:
457:                public void test_empty_address() throws IOException {
458:                    Tokenizer t = new Tokenizer("1:/33");
459:                    APLRecord ar = new APLRecord();
460:                    try {
461:                        ar.rdataFromString(t, null);
462:                        fail("TextParseException not thrown");
463:                    } catch (TextParseException e) {
464:                    }
465:                }
466:
467:                public void test_malformed_address() throws IOException {
468:                    Tokenizer t = new Tokenizer("1:A.B.C.D/33");
469:                    APLRecord ar = new APLRecord();
470:                    try {
471:                        ar.rdataFromString(t, null);
472:                        fail("TextParseException not thrown");
473:                    } catch (TextParseException e) {
474:                    }
475:                }
476:            }
477:
478:            public static class Test_rrToString extends TestCase {
479:                Name m_an, m_rn;
480:                long m_ttl;
481:                ArrayList m_elements;
482:                InetAddress m_addr4;
483:                String m_addr4_string;
484:                byte[] m_addr4_bytes;
485:                InetAddress m_addr6;
486:                String m_addr6_string;
487:                byte[] m_addr6_bytes;
488:
489:                protected void setUp() throws TextParseException,
490:                        UnknownHostException {
491:                    m_an = Name.fromString("My.Absolute.Name.");
492:                    m_rn = Name.fromString("My.Relative.Name");
493:                    m_ttl = 0x13579;
494:                    m_addr4_string = "193.160.232.5";
495:                    m_addr4 = InetAddress.getByName(m_addr4_string);
496:                    m_addr4_bytes = m_addr4.getAddress();
497:
498:                    m_addr6_string = "2001:db8:85a3:8d3:1319:8a2e:370:7334";
499:                    m_addr6 = InetAddress.getByName(m_addr6_string);
500:                    m_addr6_bytes = m_addr6.getAddress();
501:
502:                    m_elements = new ArrayList(2);
503:                    Element e = new Element(true, m_addr4, 12);
504:                    m_elements.add(e);
505:
506:                    e = new Element(false, m_addr6, 64);
507:                    m_elements.add(e);
508:                }
509:
510:                public void test() {
511:                    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl,
512:                            m_elements);
513:                    assertEquals("!1:" + m_addr4_string + "/12 2:"
514:                            + m_addr6_string + "/64", ar.rrToString());
515:                }
516:            }
517:
518:            public static class Test_rrToWire extends TestCase {
519:                Name m_an, m_rn;
520:                long m_ttl;
521:                ArrayList m_elements;
522:                InetAddress m_addr4;
523:                String m_addr4_string;
524:                byte[] m_addr4_bytes;
525:                InetAddress m_addr6;
526:                String m_addr6_string;
527:                byte[] m_addr6_bytes;
528:
529:                protected void setUp() throws TextParseException,
530:                        UnknownHostException {
531:                    m_an = Name.fromString("My.Absolute.Name.");
532:                    m_rn = Name.fromString("My.Relative.Name");
533:                    m_ttl = 0x13579;
534:                    m_addr4_string = "193.160.232.5";
535:                    m_addr4 = InetAddress.getByName(m_addr4_string);
536:                    m_addr4_bytes = m_addr4.getAddress();
537:
538:                    m_addr6_string = "2001:db8:85a3:8d3:1319:8a2e:370:7334";
539:                    m_addr6 = InetAddress.getByName(m_addr6_string);
540:                    m_addr6_bytes = m_addr6.getAddress();
541:
542:                    m_elements = new ArrayList(2);
543:                    Element e = new Element(true, m_addr4, 12);
544:                    m_elements.add(e);
545:
546:                    e = new Element(false, m_addr6, 64);
547:                    m_elements.add(e);
548:                }
549:
550:                public void test_empty() {
551:                    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl,
552:                            new ArrayList());
553:                    DNSOutput dout = new DNSOutput();
554:
555:                    ar.rrToWire(dout, null, true);
556:                    assertTrue(Arrays.equals(new byte[0], dout.toByteArray()));
557:                }
558:
559:                public void test_basic() {
560:                    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl,
561:                            m_elements);
562:
563:                    byte[] exp = new byte[] { 0, 1, 12, (byte) 0x84,
564:                            m_addr4_bytes[0], m_addr4_bytes[1],
565:                            m_addr4_bytes[2], m_addr4_bytes[3], 0, 2, 64, 0x10,
566:                            m_addr6_bytes[0], m_addr6_bytes[1],
567:                            m_addr6_bytes[2], m_addr6_bytes[3],
568:                            m_addr6_bytes[4], m_addr6_bytes[5],
569:                            m_addr6_bytes[6], m_addr6_bytes[7],
570:                            m_addr6_bytes[8], m_addr6_bytes[9],
571:                            m_addr6_bytes[10], m_addr6_bytes[11],
572:                            m_addr6_bytes[12], m_addr6_bytes[13],
573:                            m_addr6_bytes[14], m_addr6_bytes[15] };
574:
575:                    DNSOutput dout = new DNSOutput();
576:
577:                    ar.rrToWire(dout, null, true);
578:                    assertTrue(Arrays.equals(exp, dout.toByteArray()));
579:                }
580:
581:                public void test_non_IP() throws IOException {
582:                    byte[] exp = new byte[] { 0, 3, (byte) 130, (byte) 0x85, 1,
583:                            2, 3, 4, 5 };
584:
585:                    DNSInput di = new DNSInput(exp);
586:                    APLRecord ar = new APLRecord();
587:                    ar.rrFromWire(di);
588:
589:                    DNSOutput dout = new DNSOutput();
590:
591:                    ar.rrToWire(dout, null, true);
592:                    assertTrue(Arrays.equals(exp, dout.toByteArray()));
593:                }
594:
595:                public void test_address_with_embedded_zero()
596:                        throws UnknownHostException {
597:                    InetAddress a = InetAddress.getByName("232.0.11.1");
598:                    ArrayList elements = new ArrayList();
599:                    elements.add(new Element(true, a, 31));
600:
601:                    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl,
602:                            elements);
603:
604:                    byte[] exp = new byte[] { 0, 1, 31, (byte) 0x84,
605:                            (byte) 232, 0, 11, 1 };
606:
607:                    DNSOutput dout = new DNSOutput();
608:
609:                    ar.rrToWire(dout, null, true);
610:                    assertTrue(Arrays.equals(exp, dout.toByteArray()));
611:                }
612:
613:                public void test_short_address() throws UnknownHostException {
614:                    InetAddress a = InetAddress.getByName("232.0.11.0");
615:                    ArrayList elements = new ArrayList();
616:                    elements.add(new Element(true, a, 31));
617:
618:                    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl,
619:                            elements);
620:
621:                    byte[] exp = new byte[] { 0, 1, 31, (byte) 0x83,
622:                            (byte) 232, 0, 11 };
623:
624:                    DNSOutput dout = new DNSOutput();
625:
626:                    ar.rrToWire(dout, null, true);
627:                    assertTrue(Arrays.equals(exp, dout.toByteArray()));
628:                }
629:
630:                public void test_wildcard_address() throws UnknownHostException {
631:                    InetAddress a = InetAddress.getByName("0.0.0.0");
632:                    ArrayList elements = new ArrayList();
633:                    elements.add(new Element(true, a, 31));
634:
635:                    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl,
636:                            elements);
637:
638:                    byte[] exp = new byte[] { 0, 1, 31, (byte) 0x80 };
639:
640:                    DNSOutput dout = new DNSOutput();
641:
642:                    ar.rrToWire(dout, null, true);
643:                    assertTrue(Arrays.equals(exp, dout.toByteArray()));
644:                }
645:            }
646:
647:            public static Test suite() {
648:                TestSuite s = new TestSuite();
649:                s.addTestSuite(Test_Element_init.class);
650:                s.addTestSuite(Test_init.class);
651:                s.addTestSuite(Test_rrFromWire.class);
652:                s.addTestSuite(Test_rdataFromString.class);
653:                s.addTestSuite(Test_rrToString.class);
654:                s.addTestSuite(Test_rrToWire.class);
655:                return s;
656:            }
657:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.