01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: *
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: /**
20: * @author Alexei Y. Zakharov
21: * @version $Revision: 1.1.2.5 $
22: */package org.apache.harmony.jndi.provider.dns;
23:
24: import junit.framework.TestCase;
25:
26: /**
27: * <code>org.apache.harmony.jndi.provider.dns.DNSPseudoURL</code> unit test.
28: * @author Alexei Zakharov
29: * @version $Revision: 1.1.2.5 $
30: */
31: public class DNSPseudoURLTest extends TestCase {
32:
33: public void testConstructor() {
34: DNSPseudoURL url = null;
35:
36: url = new DNSPseudoURL(
37: "dns://super.puper.server.ru:54/sub.domain.com");
38: assertEquals("super.puper.server.ru", url.getHost());
39: assertFalse(url.isHostIpGiven());
40: assertEquals(54, url.getPort());
41: assertEquals("sub.domain.com.", url.getDomain());
42:
43: url = new DNSPseudoURL("dns://123.456.678.1/example.com.");
44: assertEquals("123.456.678.1", url.getHost());
45: assertTrue(url.isHostIpGiven());
46: assertEquals(53, url.getPort());
47: assertEquals("example.com.", url.getDomain());
48:
49: try {
50: url = new DNSPseudoURL("dns://a.com/domain.com/mama");
51: fail("IllegalArgumentException was not thrown");
52: } catch (IllegalArgumentException e) {
53: // correct behaviour
54: }
55: }
56:
57: public void testConstructorDefaults() {
58: DNSPseudoURL url;
59:
60: url = new DNSPseudoURL("dns://www.mydomain.ru");
61: assertEquals("www.mydomain.ru", url.getHost());
62: assertFalse(url.isHostIpGiven());
63: assertEquals(53, url.getPort());
64: assertEquals(".", url.getDomain());
65:
66: url = new DNSPseudoURL("dns:/mydomain.org");
67: assertEquals("localhost", url.getHost());
68: assertFalse(url.isHostIpGiven());
69: assertEquals(53, url.getPort());
70: assertEquals("mydomain.org.", url.getDomain());
71:
72: url = new DNSPseudoURL("dns:");
73: assertEquals("localhost", url.getHost());
74: assertFalse(url.isHostIpGiven());
75: assertEquals(53, url.getPort());
76: assertEquals(".", url.getDomain());
77: }
78:
79: public static void main(String[] args) {
80: junit.textui.TestRunner.run(DNSPseudoURLTest.class);
81: }
82:
83: }
|