Source Code Cross Referenced for TestVirtualDNS.java in  » Net » customdns » CustomDNS » Tests » 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 » customdns » CustomDNS.Tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Missing test cases:
002:        //   Failed lookup returns *correct* error
003:        //   MX record glue
004:
005:        package CustomDNS.Tests;
006:
007:        import java.lang.RuntimeException;
008:        import java.net.*;
009:        import java.util.Hashtable;
010:
011:        import junit.framework.*;
012:        import junit.extensions.*;
013:
014:        import CustomDNS.Tests.CustomDNSTestCase;
015:        import CustomDNS.VirtualDNS.VirtualDNS;
016:
017:        // We need a good DNS client which can query our server effectively. Since
018:        // we're already using Brian Wellington's code, we can just use his.
019:        import org.xbill.DNS.*;
020:
021:        public class TestVirtualDNS extends CustomDNSTestCase {
022:
023:            // The port to run our test DNS servers on. This should be greater
024:            // than 1024 (to prevent us from needing root privs under Unix).
025:            static final short dnsPort = 5299;
026:
027:            // Our standard constructor.
028:            public TestVirtualDNS(String name) {
029:                super (name);
030:            }
031:
032:            // An overridable method which returns the DNS port we should use.
033:            protected short getDNSPort() {
034:                return this .dnsPort;
035:            }
036:
037:            // Before running each test, create a new resolver (pointed at the
038:            // right server, and with an empty cache).
039:            public void setUp() throws Exception {
040:                SimpleResolver resolver = new SimpleResolver("127.0.0.1");
041:                resolver.setPort(getDNSPort());
042:                dns.setResolver(resolver);
043:            }
044:
045:            // A local variety of test assertion--make sure that a given hostname
046:            // returns a particular address when we look it up.
047:            protected static void assertAddress(String host, String correctAddr) {
048:                try {
049:                    InetAddress addr = Address.getByName(host);
050:                    assertEquals(addr.getHostAddress(), correctAddr);
051:                } catch (UnknownHostException e) {
052:                    fail("Unknown host " + host + ", expected address "
053:                            + correctAddr);
054:                }
055:            }
056:
057:            public void testAddress() {
058:                assertAddress("sample.myzone.test", "10.0.1.2");
059:            }
060:
061:            public void testCNAME() {
062:                assertAddress("sample2.myzone.test", "10.0.1.2");
063:            }
064:
065:            public void testUnknownHost() {
066:                try {
067:                    Address.getByName("unknown.myzone.test");
068:                    fail("expected UnknownHostException");
069:                } catch (UnknownHostException e) {
070:                }
071:            }
072:
073:            public void testNS() {
074:                // Fetch back a set of records.
075:                Record[] records = dns.getAnyRecords("myzone.test", Type.NS);
076:                assertEquals(records.length, 3);
077:
078:                // Check to make sure the right names were present.
079:                Hashtable names = new Hashtable();
080:                for (int i = 0; i < records.length; i++) {
081:                    NSRecord nsr = (NSRecord) records[i];
082:                    names.put(nsr.getTarget().toString(), new Integer(0));
083:                }
084:                assert (names.get("dns1.otherzone.test.") != null);
085:                assert (names.get("dns2.otherzone.test.") != null);
086:                assert (names.get("dns3.otherzone.test.") != null);
087:            }
088:
089:            public void testUpperCaseQuery() {
090:                assertAddress("SAMPLE2.MYZONE.TEST.", "10.0.1.2");
091:            }
092:
093:            // Return our test suite object.
094:            public static Test suite() {
095:                // Build our test suite.
096:                TestSuite suite = new TestSuite(TestVirtualDNS.class);
097:
098:                // Wrap it with a TestSetup object that boots our DNS server.
099:                // (This only works once--we can't shut it down.)
100:                final String zonefile = CustomDNSTestCase
101:                        .fullPath("test.master");
102:                TestSetup wrapper = new TestSetup(suite) {
103:                    VirtualDNS mDNS = null;
104:
105:                    public void setUp() throws Exception {
106:                        if (mDNS == null) {
107:                            new VirtualDNS(zonefile, dnsPort);
108:                            // Wait for DNS server to load.
109:                            // XXX - We want real semaphores!
110:                            Thread.sleep(2000);
111:                        } else {
112:                            fail("Can only start DNS server once");
113:                        }
114:                    }
115:                };
116:                return wrapper;
117:            }
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.