001: /*
002: * $Id: TestFormPropertyConfig.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.config;
022:
023: import junit.framework.TestCase;
024:
025: /**
026: * Unit tests for the <code>org.apache.struts.config.FormPropertyConfig</code>
027: * class.
028: *
029: * @version $Rev: 471754 $ $Date: 2005-05-21 19:06:53 -0400 (Sat, 21 May 2005)
030: * $
031: */
032: public class TestFormPropertyConfig extends TestCase {
033: public void testBasicInherit() throws Exception {
034: FormPropertyConfig base = new FormPropertyConfig("base",
035: "java.lang.String[]", "", 10);
036: String baseCount = "10";
037:
038: base.setProperty("count", baseCount);
039:
040: FormPropertyConfig sub = new FormPropertyConfig();
041:
042: sub.setName("base");
043:
044: sub.inheritFrom(base);
045:
046: assertEquals("Type was not inherited", base.getType(), sub
047: .getType());
048: assertEquals("Initial is incorrect", base.getInitial(), sub
049: .getInitial());
050: assertEquals("Size was not inherited", base.getSize(), sub
051: .getSize());
052: assertEquals("Arbitrary config property was not inherited",
053: baseCount, sub.getProperty("count"));
054: }
055:
056: public void testInheritWithInitialOverride() throws Exception {
057: FormPropertyConfig base = new FormPropertyConfig("base",
058: "java.lang.String", "value");
059:
060: FormPropertyConfig sub = new FormPropertyConfig();
061:
062: sub.setName("base");
063:
064: String initial = "otherValue";
065:
066: sub.setInitial(initial);
067:
068: sub.inheritFrom(base);
069:
070: assertEquals("Type was not inherited", base.getType(), sub
071: .getType());
072: assertEquals("Initial is incorrect", initial, sub.getInitial());
073: assertEquals("Size is incorrect", base.getSize(), sub.getSize());
074: }
075:
076: public void testInheritWithTypeOverride() throws Exception {
077: FormPropertyConfig base = new FormPropertyConfig("base",
078: "java.lang.String", "");
079:
080: FormPropertyConfig sub = new FormPropertyConfig();
081:
082: sub.setName("base");
083: sub.setType("java.lang.Integer");
084:
085: sub.inheritFrom(base);
086:
087: assertEquals("Type is incorrect", "java.lang.Integer", sub
088: .getType());
089: assertEquals("Initial is incorrect", base.getInitial(), sub
090: .getInitial());
091: assertEquals("Size is incorrect", base.getSize(), sub.getSize());
092: }
093:
094: public void testInheritWithTypeOverride2() throws Exception {
095: FormPropertyConfig base = new FormPropertyConfig("base",
096: "java.lang.String", "");
097:
098: FormPropertyConfig sub = new FormPropertyConfig();
099:
100: sub.setName("base");
101:
102: String type = "java.lang.Integer[]";
103: int size = 10;
104:
105: sub.setType(type);
106: sub.setSize(size);
107:
108: sub.inheritFrom(base);
109:
110: assertEquals("Type is incorrect", type, sub.getType());
111: assertEquals("Initial is incorrect", base.getInitial(), sub
112: .getInitial());
113: assertEquals("Size is incorrect", size, sub.getSize());
114: }
115:
116: public void testInheritWithSizeOverride() throws Exception {
117: FormPropertyConfig base = new FormPropertyConfig("base",
118: "java.lang.String[]", "", 20);
119:
120: FormPropertyConfig sub = new FormPropertyConfig();
121:
122: sub.setName("base");
123:
124: int size = 50;
125:
126: sub.setSize(size);
127:
128: sub.inheritFrom(base);
129:
130: assertEquals("Type was not inherited", base.getType(), sub
131: .getType());
132: assertEquals("Initial is incorrect", base.getInitial(), sub
133: .getInitial());
134: assertEquals("Size is incorrect", size, sub.getSize());
135: }
136: }
|