View Javadoc

1   /* SimpleTypeTest
2    *
3    * $Id: SimpleTypeTest.java 2168 2004-05-28 22:33:09Z stack-sf $
4    *
5    * Created on Apr 15, 2004
6    *
7    * Copyright (C) 2004 Internet Archive.
8    *
9    * This file is part of the Heritrix web crawler (crawler.archive.org).
10   *
11   * Heritrix is free software; you can redistribute it and/or modify
12   * it under the terms of the GNU Lesser Public License as published by
13   * the Free Software Foundation; either version 2.1 of the License, or
14   * any later version.
15   *
16   * Heritrix is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU Lesser Public License for more details.
20   *
21   * You should have received a copy of the GNU Lesser Public License
22   * along with Heritrix; if not, write to the Free Software
23   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24   */
25  package org.archive.crawler.settings;
26  
27  import junit.framework.TestCase;
28  
29  
30  /***
31   * Testing of the SimpleType
32   *
33   * @author John Erik Halse
34   */
35  public class SimpleTypeTest extends TestCase {
36      public void testGetName() {
37          SimpleType t1 = new SimpleType("a", "b", "c");
38          assertEquals("a", t1.getName());
39      }
40  
41      public void testGetDescription() {
42          SimpleType t1 = new SimpleType("a", "b", "c");
43          assertEquals("b", t1.getDescription());
44      }
45  
46      public void testGetDefaultValue() {
47          SimpleType t1 = new SimpleType("a", "b", "c");
48          assertEquals("c", t1.getDefaultValue());
49      }
50  
51      public void testGetLegalValues() {
52          SimpleType t1 = new SimpleType("a", "b", "c", new String[] {"d", "e"});
53          checkArray(new String[] {"d", "e"}, t1.getLegalValues());
54      }
55  
56      public void testSetLegalValues() {
57          SimpleType t1 = new SimpleType("a", "b", "c", new String[] {"d", "e"});
58          t1.setLegalValues(new String[] {"f", "g"});
59          checkArray(new String[] {"f", "g"}, t1.getLegalValues());
60      }
61  
62      public void testGetConstraints() {
63          SimpleType t1 = new SimpleType("a1", "b1", "c1");
64          SimpleType t2 = new SimpleType("a2", "b2", "c2", new String[] {"d", "e"});
65          assertNotNull(t1.getConstraints());
66          assertSame(LegalValueTypeConstraint.class, t2.getConstraints().get(0)
67                  .getClass());
68          assertSame(LegalValueListConstraint.class, t2.getConstraints().get(1)
69                  .getClass());
70      }
71  
72      public void testGetLegalValueType() {
73          SimpleType t1 = new SimpleType("a1", "b1", "c1");
74          SimpleType t2 = new SimpleType("a2", "b2", new Integer(1));
75          SimpleType t3 = new SimpleType("a3", "b3", new TextField("c3"));
76          assertSame(String.class, t1.getLegalValueType());
77          assertSame(Integer.class, t2.getLegalValueType());
78          assertSame(TextField.class, t3.getLegalValueType());
79      }
80  
81      public void testEquals() {
82          SimpleType t1 = new SimpleType("a1", "b1", "c1");
83          SimpleType t2 = new SimpleType("a1", "b1", "c1");
84          SimpleType t3 = new SimpleType("a2", "b2", "c2");
85          assertTrue(t1.equals(t2));
86          assertFalse(t1.equals(t3));
87          assertTrue(t1.equals(t1));
88          assertFalse(t1.equals(null));
89      }
90  
91      private void checkArray(Object a1[], Object a2[]) {
92          assertEquals("Arrays not of same length.", a1.length, a2.length);
93          for (int i = 0; i < a1.length; i++) {
94              assertEquals(a1[i], a2[i]);
95          }
96      }
97  }