KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > system > controller > configure > value > text > test > TextValueTest


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.system.controller.configure.value.text.test;
23
24 import java.math.BigDecimal JavaDoc;
25 import java.text.DateFormat JavaDoc;
26 import java.text.SimpleDateFormat JavaDoc;
27 import java.util.Date JavaDoc;
28
29 import javax.management.ObjectName JavaDoc;
30
31 import org.jboss.deployment.DeploymentException;
32 import org.jboss.test.system.controller.AbstractControllerTest;
33 import org.jboss.test.system.controller.support.BrokenDynamicMBeanAttributeInfoTypeNotFound;
34 import org.jboss.test.system.controller.support.BrokenDynamicMBeanNoAttributeInfoType;
35 import org.jboss.test.system.controller.support.Simple;
36 import org.jboss.test.system.controller.support.SimpleMBean;
37 import org.jboss.util.NestedRuntimeException;
38
39 /**
40  * TextValueTest.
41  *
42  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
43  * @version $Revision: 1.1 $
44  */

45 public abstract class TextValueTest extends AbstractControllerTest
46 {
47    private static final DateFormat JavaDoc dateFormat = new SimpleDateFormat JavaDoc("EEE MMM d HH:mm:ss z yyyy");
48    
49    private static final String JavaDoc stringValue = new String JavaDoc("StringValue");
50    private static final Byte JavaDoc byteValue = new Byte JavaDoc("12");
51    private static final Boolean JavaDoc booleanValue = Boolean.TRUE;
52    // TODO character
53
// private static final Character characterValue = new Character('a');
54
private static final Short JavaDoc shortValue = new Short JavaDoc("123");
55    private static final Integer JavaDoc integerValue = new Integer JavaDoc("1234");
56    private static final Long JavaDoc longValue = new Long JavaDoc("12345");
57    private static final Float JavaDoc floatValue = new Float JavaDoc("3.14");
58    private static final Double JavaDoc doubleValue = new Double JavaDoc("3.14e12");
59    private static final Date JavaDoc dateValue = createDate("Mon Jan 01 00:00:00 CET 2001");
60    private static final BigDecimal JavaDoc bigDecimalValue = new BigDecimal JavaDoc("12e4");
61    //private static final BigInteger bigIntegerValue = new BigInteger("123456");
62

63    public TextValueTest(String JavaDoc name)
64    {
65       super(name);
66    }
67    
68    public void testPropertyEditors() throws Exception JavaDoc
69    {
70       ObjectName JavaDoc name = SimpleMBean.OBJECT_NAME;
71       
72       assertInstall(name);
73       try
74       {
75          Simple test = getSimple();
76
77          assertEquals(stringValue, test.getAString());
78          assertEquals(byteValue, test.getAByte());
79          assertEquals(booleanValue, test.getABoolean());
80          // TODO character
81
// assertEquals(characterValue, test.getACharacter());
82
assertEquals(shortValue, test.getAShort());
83          assertEquals(integerValue, test.getAnInt());
84          assertEquals(longValue, test.getALong());
85          assertEquals(floatValue, test.getAFloat());
86          assertEquals(doubleValue, test.getADouble());
87          assertEquals(dateValue, test.getADate());
88          assertEquals(bigDecimalValue, test.getABigDecimal());
89          // TODO BigInteger
90
//assertEquals(bigIntegerValue, test.getABigInteger());
91
assertEquals(byteValue.byteValue(), test.getAbyte());
92          assertEquals(booleanValue.booleanValue(), test.isAboolean());
93          // TODO character
94
// assertEquals(characterValue.charValue(), test.getAchar());
95
assertEquals(shortValue.shortValue(), test.getAshort());
96          assertEquals(integerValue.intValue(), test.getAnint());
97          assertEquals(longValue.longValue(), test.getAlong());
98          assertEquals(floatValue.floatValue(), test.getAfloat());
99          assertEquals(doubleValue.doubleValue(), test.getAdouble());
100       }
101       finally
102       {
103          assertUninstall(name);
104       }
105    }
106    
107    public void testNoPropertyEditor() throws Exception JavaDoc
108    {
109       assertDeployFailure(SimpleMBean.OBJECT_NAME, DeploymentException.class);
110    }
111    
112    public void testNoAttributeInfoType() throws Exception JavaDoc
113    {
114       assertDeployFailure(BrokenDynamicMBeanNoAttributeInfoType.OBJECT_NAME, DeploymentException.class);
115    }
116    
117    public void testAttributeInfoTypeNotFound() throws Exception JavaDoc
118    {
119       assertDeployFailure(BrokenDynamicMBeanAttributeInfoTypeNotFound.OBJECT_NAME, ClassNotFoundException JavaDoc.class);
120    }
121
122    private static Date JavaDoc createDate(String JavaDoc date)
123    {
124       try
125       {
126          return dateFormat.parse(date);
127       }
128       catch (Exception JavaDoc e)
129       {
130          throw new NestedRuntimeException(e);
131       }
132    }
133 }
134
Popular Tags