Source Code Cross Referenced for KEYBaseTest.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.util.Arrays;
039:        import junit.framework.TestCase;
040:        import org.xbill.DNS.utils.base64;
041:
042:        public class KEYBaseTest extends TestCase {
043:            private static class TestClass extends KEYBase {
044:                public TestClass() {
045:                }
046:
047:                public TestClass(Name name, int type, int dclass, long ttl,
048:                        int flags, int proto, int alg, byte[] key) {
049:                    super (name, type, dclass, ttl, flags, proto, alg, key);
050:                }
051:
052:                public Record getObject() {
053:                    return null;
054:                }
055:
056:                void rdataFromString(Tokenizer st, Name origin)
057:                        throws IOException {
058:                }
059:            }
060:
061:            public void test_ctor() throws TextParseException {
062:                TestClass tc = new TestClass();
063:                assertEquals(0, tc.getFlags());
064:                assertEquals(0, tc.getProtocol());
065:                assertEquals(0, tc.getAlgorithm());
066:                assertNull(tc.getKey());
067:
068:                Name n = Name.fromString("my.name.");
069:                byte[] key = new byte[] { 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
070:                        0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
071:
072:                tc = new TestClass(n, Type.KEY, DClass.IN, 100L, 0xFF, 0xF,
073:                        0xE, key);
074:
075:                assertSame(n, tc.getName());
076:                assertEquals(Type.KEY, tc.getType());
077:                assertEquals(DClass.IN, tc.getDClass());
078:                assertEquals(100L, tc.getTTL());
079:                assertEquals(0xFF, tc.getFlags());
080:                assertEquals(0xF, tc.getProtocol());
081:                assertEquals(0xE, tc.getAlgorithm());
082:                assertTrue(Arrays.equals(key, tc.getKey()));
083:            }
084:
085:            public void test_rrFromWire() throws IOException {
086:                byte[] raw = new byte[] { (byte) 0xAB, (byte) 0xCD,
087:                        (byte) 0xEF, (byte) 0x19, 1, 2, 3, 4, 5 };
088:                DNSInput in = new DNSInput(raw);
089:
090:                TestClass tc = new TestClass();
091:                tc.rrFromWire(in);
092:
093:                assertEquals(0xABCD, tc.getFlags());
094:                assertEquals(0xEF, tc.getProtocol());
095:                assertEquals(0x19, tc.getAlgorithm());
096:                assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, tc
097:                        .getKey()));
098:
099:                raw = new byte[] { (byte) 0xBA, (byte) 0xDA, (byte) 0xFF,
100:                        (byte) 0x28 };
101:                in = new DNSInput(raw);
102:
103:                tc = new TestClass();
104:                tc.rrFromWire(in);
105:
106:                assertEquals(0xBADA, tc.getFlags());
107:                assertEquals(0xFF, tc.getProtocol());
108:                assertEquals(0x28, tc.getAlgorithm());
109:                assertNull(tc.getKey());
110:            }
111:
112:            public void test_rrToString() throws IOException,
113:                    TextParseException {
114:                Name n = Name.fromString("my.name.");
115:                byte[] key = new byte[] { 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
116:                        0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
117:
118:                TestClass tc = new TestClass(n, Type.KEY, DClass.IN, 100L,
119:                        0xFF, 0xF, 0xE, null);
120:
121:                String out = tc.rrToString();
122:
123:                assertEquals("255 15 14", out);
124:
125:                tc = new TestClass(n, Type.KEY, DClass.IN, 100L, 0xFF, 0xF,
126:                        0xE, key);
127:                out = tc.rrToString();
128:
129:                assertEquals("255 15 14 " + base64.toString(key), out);
130:
131:                Options.set("multiline");
132:                out = tc.rrToString();
133:                assertEquals("255 15 14 (\n\t" + base64.toString(key)
134:                        + " ) ; key_tag = 18509", out);
135:
136:                Options.unset("multiline");
137:            }
138:
139:            public void test_getFootprint() throws TextParseException {
140:                Name n = Name.fromString("my.name.");
141:                byte[] key = new byte[] { 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
142:                        0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
143:
144:                TestClass tc = new TestClass(n, Type.KEY, DClass.IN, 100L,
145:                        0xFF, 0xF, DNSSEC.Algorithm.RSAMD5, key);
146:
147:                int foot = tc.getFootprint();
148:                // second-to-last and third-to-last bytes of key for RSAMD5
149:                assertEquals(0xD0E, foot);
150:                assertEquals(foot, tc.getFootprint());
151:
152:                // key with an odd number of bytes
153:                tc = new TestClass(n, Type.KEY, DClass.IN, 100L, 0x89AB, 0xCD,
154:                        0xEF, new byte[] { 0x12, 0x34, 0x56 });
155:
156:                // rrToWire gives: { 0x89, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56 }
157:                // 89AB + CDEF + 1234 + 5600 = 1BCFE
158:                // 1BFCE + 1 = 1BFCF & FFFF = BFCF
159:                foot = tc.getFootprint();
160:                assertEquals(0xBFCF, foot);
161:                assertEquals(foot, tc.getFootprint());
162:
163:                // empty
164:                tc = new TestClass();
165:                assertEquals(0, tc.getFootprint());
166:            }
167:
168:            public void test_rrToWire() throws IOException, TextParseException {
169:                Name n = Name.fromString("my.name.");
170:                byte[] key = new byte[] { 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
171:                        0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
172:
173:                TestClass tc = new TestClass(n, Type.KEY, DClass.IN, 100L,
174:                        0x7689, 0xAB, 0xCD, key);
175:
176:                byte[] exp = new byte[] { (byte) 0x76, (byte) 0x89,
177:                        (byte) 0xAB, (byte) 0xCD, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
178:                        10, 11, 12, 13, 14, 15 };
179:
180:                DNSOutput o = new DNSOutput();
181:
182:                // canonical
183:                tc.rrToWire(o, null, true);
184:                assertTrue(Arrays.equals(exp, o.toByteArray()));
185:
186:                // not canonical
187:                o = new DNSOutput();
188:                tc.rrToWire(o, null, false);
189:                assertTrue(Arrays.equals(exp, o.toByteArray()));
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.