KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > bean > TestLightweightBeanInitializer


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.bean;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.Location;
19 import org.apache.hivemind.test.HiveMindTestCase;
20
21 /**
22  * Tests for {@link org.apache.tapestry.bean.LightweightBeanInitializer}.
23  *
24  * @author Howard M. Lewis Ship
25  * @since 4.0
26  */

27 public class TestLightweightBeanInitializer extends HiveMindTestCase
28 {
29     public void testSuccess()
30     {
31         String JavaDoc initializer = "required,minLength=10";
32         TargetBean bean = new TargetBean();
33
34         assertEquals(false, bean.isRequired());
35         assertEquals(0, bean.getMinLength());
36
37         IBeanInitializer bi = new LightweightBeanInitializer(initializer);
38
39         assertEquals(initializer, bi.getPropertyName());
40
41         bi.setBeanProperty(null, bean);
42
43         assertEquals(true, bean.isRequired());
44         assertEquals(10, bean.getMinLength());
45     }
46
47     public void testFailure()
48     {
49         Location l = newLocation();
50
51         IBeanInitializer bi = new LightweightBeanInitializer("zip=zap");
52         bi.setLocation(l);
53
54         TargetBean bean = new TargetBean();
55
56         try
57         {
58             bi.setBeanProperty(null, bean);
59             unreachable();
60         }
61         catch (ApplicationRuntimeException ex)
62         {
63             assertEquals("Class org.apache.tapestry.bean.TargetBean "
64                     + "does not contain a property named 'zip'.", ex.getMessage());
65             assertSame(l, ex.getLocation());
66         }
67     }
68 }
69
Popular Tags