Source Code Cross Referenced for SetResponseTest.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.net.InetAddress;
038:        import java.net.UnknownHostException;
039:        import java.util.Arrays;
040:        import junit.framework.TestCase;
041:
042:        public class SetResponseTest extends TestCase {
043:            public void test_ctor_1arg() {
044:                final int[] types = new int[] { SetResponse.UNKNOWN,
045:                        SetResponse.NXDOMAIN, SetResponse.NXRRSET,
046:                        SetResponse.DELEGATION, SetResponse.CNAME,
047:                        SetResponse.DNAME, SetResponse.SUCCESSFUL };
048:
049:                for (int i = 0; i < types.length; ++i) {
050:                    SetResponse sr = new SetResponse(types[i]);
051:                    assertNull(sr.getNS());
052:                    assertEquals(types[i] == SetResponse.UNKNOWN, sr
053:                            .isUnknown());
054:                    assertEquals(types[i] == SetResponse.NXDOMAIN, sr
055:                            .isNXDOMAIN());
056:                    assertEquals(types[i] == SetResponse.NXRRSET, sr
057:                            .isNXRRSET());
058:                    assertEquals(types[i] == SetResponse.DELEGATION, sr
059:                            .isDelegation());
060:                    assertEquals(types[i] == SetResponse.CNAME, sr.isCNAME());
061:                    assertEquals(types[i] == SetResponse.DNAME, sr.isDNAME());
062:                    assertEquals(types[i] == SetResponse.SUCCESSFUL, sr
063:                            .isSuccessful());
064:                }
065:            }
066:
067:            public void test_ctor_1arg_toosmall() {
068:                try {
069:                    new SetResponse(-1);
070:                    fail("IllegalArgumentException not thrown");
071:                } catch (IllegalArgumentException a) {
072:                }
073:            }
074:
075:            public void test_ctor_1arg_toobig() {
076:                try {
077:                    new SetResponse(7);
078:                    fail("IllegalArgumentException not thrown");
079:                } catch (IllegalArgumentException a) {
080:                }
081:            }
082:
083:            public void test_ctor_2arg() {
084:                final int[] types = new int[] { SetResponse.UNKNOWN,
085:                        SetResponse.NXDOMAIN, SetResponse.NXRRSET,
086:                        SetResponse.DELEGATION, SetResponse.CNAME,
087:                        SetResponse.DNAME, SetResponse.SUCCESSFUL };
088:
089:                for (int i = 0; i < types.length; ++i) {
090:                    RRset rs = new RRset();
091:                    SetResponse sr = new SetResponse(types[i], rs);
092:                    assertSame(rs, sr.getNS());
093:                    assertEquals(types[i] == SetResponse.UNKNOWN, sr
094:                            .isUnknown());
095:                    assertEquals(types[i] == SetResponse.NXDOMAIN, sr
096:                            .isNXDOMAIN());
097:                    assertEquals(types[i] == SetResponse.NXRRSET, sr
098:                            .isNXRRSET());
099:                    assertEquals(types[i] == SetResponse.DELEGATION, sr
100:                            .isDelegation());
101:                    assertEquals(types[i] == SetResponse.CNAME, sr.isCNAME());
102:                    assertEquals(types[i] == SetResponse.DNAME, sr.isDNAME());
103:                    assertEquals(types[i] == SetResponse.SUCCESSFUL, sr
104:                            .isSuccessful());
105:                }
106:            }
107:
108:            public void test_ctor_2arg_toosmall() {
109:                try {
110:                    new SetResponse(-1, new RRset());
111:                    fail("IllegalArgumentException not thrown");
112:                } catch (IllegalArgumentException a) {
113:                }
114:            }
115:
116:            public void test_ctor_2arg_toobig() {
117:                try {
118:                    new SetResponse(7, new RRset());
119:                    fail("IllegalArgumentException not thrown");
120:                } catch (IllegalArgumentException a) {
121:                }
122:            }
123:
124:            public void test_ofType_basic() {
125:                final int[] types = new int[] { SetResponse.DELEGATION,
126:                        SetResponse.CNAME, SetResponse.DNAME,
127:                        SetResponse.SUCCESSFUL };
128:
129:                for (int i = 0; i < types.length; ++i) {
130:                    SetResponse sr = SetResponse.ofType(types[i]);
131:                    assertNull(sr.getNS());
132:                    assertEquals(types[i] == SetResponse.UNKNOWN, sr
133:                            .isUnknown());
134:                    assertEquals(types[i] == SetResponse.NXDOMAIN, sr
135:                            .isNXDOMAIN());
136:                    assertEquals(types[i] == SetResponse.NXRRSET, sr
137:                            .isNXRRSET());
138:                    assertEquals(types[i] == SetResponse.DELEGATION, sr
139:                            .isDelegation());
140:                    assertEquals(types[i] == SetResponse.CNAME, sr.isCNAME());
141:                    assertEquals(types[i] == SetResponse.DNAME, sr.isDNAME());
142:                    assertEquals(types[i] == SetResponse.SUCCESSFUL, sr
143:                            .isSuccessful());
144:
145:                    SetResponse sr2 = SetResponse.ofType(types[i]);
146:                    assertNotSame(sr, sr2);
147:                }
148:            }
149:
150:            public void test_ofType_singleton() {
151:                final int[] types = new int[] { SetResponse.UNKNOWN,
152:                        SetResponse.NXDOMAIN, SetResponse.NXRRSET };
153:
154:                for (int i = 0; i < types.length; ++i) {
155:                    SetResponse sr = SetResponse.ofType(types[i]);
156:                    assertNull(sr.getNS());
157:                    assertEquals(types[i] == SetResponse.UNKNOWN, sr
158:                            .isUnknown());
159:                    assertEquals(types[i] == SetResponse.NXDOMAIN, sr
160:                            .isNXDOMAIN());
161:                    assertEquals(types[i] == SetResponse.NXRRSET, sr
162:                            .isNXRRSET());
163:                    assertEquals(types[i] == SetResponse.DELEGATION, sr
164:                            .isDelegation());
165:                    assertEquals(types[i] == SetResponse.CNAME, sr.isCNAME());
166:                    assertEquals(types[i] == SetResponse.DNAME, sr.isDNAME());
167:                    assertEquals(types[i] == SetResponse.SUCCESSFUL, sr
168:                            .isSuccessful());
169:
170:                    SetResponse sr2 = SetResponse.ofType(types[i]);
171:                    assertSame(sr, sr2);
172:                }
173:            }
174:
175:            public void test_ofType_toosmall() {
176:                try {
177:                    SetResponse.ofType(-1);
178:                    fail("IllegalArgumentException not thrown");
179:                } catch (IllegalArgumentException e) {
180:                }
181:            }
182:
183:            public void test_ofType_toobig() {
184:                try {
185:                    SetResponse.ofType(7);
186:                    fail("IllegalArgumentException not thrown");
187:                } catch (IllegalArgumentException e) {
188:                }
189:            }
190:
191:            public void test_addRRset() throws TextParseException,
192:                    UnknownHostException {
193:                RRset rrs = new RRset();
194:                rrs.addRR(new ARecord(Name.fromString("The.Name."), DClass.IN,
195:                        0xABCD, InetAddress.getByName("192.168.0.1")));
196:                rrs.addRR(new ARecord(Name.fromString("The.Name."), DClass.IN,
197:                        0xABCD, InetAddress.getByName("192.168.0.2")));
198:                SetResponse sr = new SetResponse(SetResponse.SUCCESSFUL);
199:                sr.addRRset(rrs);
200:
201:                RRset[] exp = new RRset[] { rrs };
202:                assertTrue(Arrays.equals(exp, sr.answers()));
203:            }
204:
205:            public void test_addRRset_multiple() throws TextParseException,
206:                    UnknownHostException {
207:                RRset rrs = new RRset();
208:                rrs.addRR(new ARecord(Name.fromString("The.Name."), DClass.IN,
209:                        0xABCD, InetAddress.getByName("192.168.0.1")));
210:                rrs.addRR(new ARecord(Name.fromString("The.Name."), DClass.IN,
211:                        0xABCD, InetAddress.getByName("192.168.0.2")));
212:
213:                RRset rrs2 = new RRset();
214:                rrs2
215:                        .addRR(new ARecord(Name.fromString("The.Other.Name."),
216:                                DClass.IN, 0xABCE, InetAddress
217:                                        .getByName("192.168.1.1")));
218:                rrs2
219:                        .addRR(new ARecord(Name.fromString("The.Other.Name."),
220:                                DClass.IN, 0xABCE, InetAddress
221:                                        .getByName("192.168.1.2")));
222:
223:                SetResponse sr = new SetResponse(SetResponse.SUCCESSFUL);
224:                sr.addRRset(rrs);
225:                sr.addRRset(rrs2);
226:
227:                RRset[] exp = new RRset[] { rrs, rrs2 };
228:                assertTrue(Arrays.equals(exp, sr.answers()));
229:            }
230:
231:            public void test_answers_nonSUCCESSFUL() {
232:                SetResponse sr = new SetResponse(SetResponse.UNKNOWN,
233:                        new RRset());
234:                assertNull(sr.answers());
235:            }
236:
237:            public void test_getCNAME() throws TextParseException,
238:                    UnknownHostException {
239:                RRset rrs = new RRset();
240:                CNAMERecord cr = new CNAMERecord(Name.fromString("The.Name."),
241:                        DClass.IN, 0xABCD, Name.fromString("The.Alias."));
242:                rrs.addRR(cr);
243:                SetResponse sr = new SetResponse(SetResponse.CNAME, rrs);
244:                assertEquals(cr, sr.getCNAME());
245:            }
246:
247:            public void test_getDNAME() throws TextParseException,
248:                    UnknownHostException {
249:                RRset rrs = new RRset();
250:                DNAMERecord dr = new DNAMERecord(Name.fromString("The.Name."),
251:                        DClass.IN, 0xABCD, Name.fromString("The.Alias."));
252:                rrs.addRR(dr);
253:                SetResponse sr = new SetResponse(SetResponse.DNAME, rrs);
254:                assertEquals(dr, sr.getDNAME());
255:            }
256:
257:            public void test_toString() throws TextParseException,
258:                    UnknownHostException {
259:                final int[] types = new int[] { SetResponse.UNKNOWN,
260:                        SetResponse.NXDOMAIN, SetResponse.NXRRSET,
261:                        SetResponse.DELEGATION, SetResponse.CNAME,
262:                        SetResponse.DNAME, SetResponse.SUCCESSFUL };
263:                RRset rrs = new RRset();
264:                rrs.addRR(new ARecord(Name.fromString("The.Name."), DClass.IN,
265:                        0xABCD, InetAddress.getByName("192.168.0.1")));
266:
267:                final String[] labels = new String[] { "unknown", "NXDOMAIN",
268:                        "NXRRSET", "delegation: " + rrs, "CNAME: " + rrs,
269:                        "DNAME: " + rrs, "successful" };
270:
271:                for (int i = 0; i < types.length; ++i) {
272:                    SetResponse sr = new SetResponse(types[i], rrs);
273:                    assertEquals(labels[i], sr.toString());
274:                }
275:            }
276:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.