001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Alexei Y. Zakharov
021: * @version $Revision: 1.1.2.4 $
022: */package org.apache.harmony.jndi.provider.dns;
023:
024: import javax.naming.InvalidNameException;
025: import javax.naming.Name;
026: import javax.naming.NamingException;
027:
028: import junit.framework.Test;
029: import junit.framework.TestCase;
030: import junit.framework.TestSuite;
031:
032: /**
033: * Test class to test
034: * <code>org.apache.harmony.jndi.provider.dns.DNSNameParser</code> class.
035: * @author Alexei Zakharov
036: * @version $Revision: 1.1.2.4 $
037: */
038: public class DNSNameParserTest extends TestCase {
039:
040: /**
041: * Tests a <code>parse()</code> method.
042: * @see org.apache.harmony.jndi.provider.dns.DNSNameParser#parse(String)
043: */
044: public void testParse() throws NamingException {
045: String nameStr1 = "www.intel.com";
046: String nameStr2 = "mydomain.com.";
047: String nameStr3 = "myhost.mysubdomain.mydomain.com.";
048: String nameStr4 = "mydomain.com..";
049: String nameStr5 = "ddddddddddddddddddddddddddddddddddddddddddddddd"
050: + "dddddddddddddddddddddddddddddddddddddddddddddddddd"
051: + "dddddddddddddddddddddddddddddddddddddddddddddddddd.a.com";
052: String nameStr6 = "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
053: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
054: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
055: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
056: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
057: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
058: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
059: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
060: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
061: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
062: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
063: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa."
064: + "aaaaaaaaaa.aaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa";
065: Name name;
066:
067: DNSNameParser parser = new DNSNameParser();
068: name = parser.parse(nameStr1);
069: assertEquals("The size of the name is wrong", 3, name.size());
070: assertEquals("Wrong label", "com", name.get(0));
071: assertEquals("Wrong label", "intel", name.get(1));
072: assertEquals("Wrong label", "www", name.get(2));
073: name = parser.parse(nameStr2);
074: assertEquals("The size of the name is wrong", 3, name.size());
075: assertEquals("Wrong label", "", name.get(0));
076: assertEquals("Wrong label", "com", name.get(1));
077: assertEquals("Wrong label", "mydomain", name.get(2));
078: name = parser.parse(nameStr3);
079: assertEquals("The size of the name is wrong", 5, name.size());
080: assertEquals("Wrong label", "", name.get(0));
081: assertEquals("Wrong label", "com", name.get(1));
082: assertEquals("Wrong label", "mydomain", name.get(2));
083: assertEquals("Wrong label", "mysubdomain", name.get(3));
084: assertEquals("Wrong label", "myhost", name.get(4));
085: try {
086: name = parser.parse(nameStr4);
087: fail("DNS name contains two null labels but "
088: + "InvalidNameException has not been thrown while parsing");
089: } catch (InvalidNameException e) {
090: }
091: try {
092: name = parser.parse(nameStr5);
093: fail("Too long label was given but "
094: + "InvalidNameException was not thrown while parsing");
095: } catch (InvalidNameException e) {
096: }
097: try {
098: name = parser.parse(nameStr6);
099: fail("Too long name was given but "
100: + "InvalidNameException was not thrown while parsing");
101: } catch (InvalidNameException e) {
102: }
103: }
104:
105: public static Test suite() {
106: return new TestSuite(DNSNameParserTest.class);
107: }
108:
109: public static void main(String argv[]) {
110: junit.textui.TestRunner.run(suite());
111: }
112:
113: }
|