KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > mx > mxbean > test > CompositeDataTest


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.mx.mxbean.test;
23
24 import java.lang.reflect.Type JavaDoc;
25
26 import javax.management.openmbean.OpenType JavaDoc;
27
28 import junit.framework.AssertionFailedError;
29
30 import org.jboss.mx.mxbean.MXBeanUtils;
31
32 /**
33  * CompositeDataTest.
34  *
35  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
36  * @version $Revision: 1.1 $
37  */

38 public abstract class CompositeDataTest extends AbstractMXBeanTest
39 {
40    public CompositeDataTest(String JavaDoc name)
41    {
42       super(name);
43    }
44
45    protected void constructReconstructTest(Object JavaDoc initialValue) throws Exception JavaDoc
46    {
47       constructReconstructTest(initialValue, initialValue);
48    }
49
50    protected void constructReconstructTest(Object JavaDoc initialValue, Type JavaDoc type) throws Exception JavaDoc
51    {
52       constructReconstructTest(initialValue, type, initialValue);
53    }
54
55    protected void constructReconstructTest(Object JavaDoc initialValue, Type JavaDoc type, Object JavaDoc expectedOpenData) throws Exception JavaDoc
56    {
57       constructReconstructTest(initialValue, type, expectedOpenData, initialValue);
58    }
59
60    protected void assertNullFailure(Type JavaDoc type) throws Exception JavaDoc
61    {
62       try
63       {
64          constructReconstructTest(null, type);
65          fail("Should not be here");
66       }
67       catch (AssertionFailedError e)
68       {
69          throw e;
70       }
71       catch (Throwable JavaDoc t)
72       {
73          checkThrowable(IllegalArgumentException JavaDoc.class, t);
74       }
75    }
76
77    protected void constructReconstructTest(Object JavaDoc initialValue, Object JavaDoc expectedOpenData) throws Exception JavaDoc
78    {
79       constructReconstructTest(initialValue, expectedOpenData, initialValue);
80    }
81
82    protected void constructReconstructTest(Object JavaDoc initialValue, Object JavaDoc expectedOpenData, Object JavaDoc expected) throws Exception JavaDoc
83    {
84       Type JavaDoc type = initialValue.getClass();
85       constructReconstructTest(initialValue, type, expectedOpenData, expected);
86    }
87
88    protected void constructReconstructTest(Object JavaDoc initialValue, Type JavaDoc type, Object JavaDoc expectedOpenData, Object JavaDoc expected) throws Exception JavaDoc
89    {
90       OpenType JavaDoc openType = MXBeanUtils.getOpenType(type);
91       constructReconstructTest(initialValue, type, openType, expectedOpenData, expected);
92    }
93
94    protected void constructReconstructTest(Object JavaDoc initialValue, Type JavaDoc type, OpenType JavaDoc openType, Object JavaDoc expectedOpenData, Object JavaDoc expected) throws Exception JavaDoc
95    {
96       Object JavaDoc openData = construct(openType, type, initialValue);
97       checkOpenDataEquals(expectedOpenData, openData);
98       if (initialValue != null)
99          assertTrue(openData + " is not " + openType, openType.isValue(openData));
100       
101       Object JavaDoc finalValue = reconstruct(openType, type, openData);
102       checkFinalEquals(expected, finalValue);
103    }
104    
105    protected void checkOpenDataEquals(Object JavaDoc expected, Object JavaDoc actual)
106    {
107       checkEquals(expected, actual);
108    }
109    
110    protected void checkFinalEquals(Object JavaDoc expected, Object JavaDoc actual)
111    {
112       checkEquals(expected, actual);
113    }
114    
115    protected void checkEquals(Object JavaDoc expected, Object JavaDoc actual)
116    {
117       assertEquals(expected, actual);
118    }
119
120    protected Object JavaDoc construct(OpenType JavaDoc openType, Type JavaDoc type, Object JavaDoc value) throws Exception JavaDoc
121    {
122       return MXBeanUtils.construct(openType, value, getClass().getName() + "#" + getName());
123    }
124    
125    protected Object JavaDoc reconstruct(OpenType JavaDoc openType, Type JavaDoc type, Object JavaDoc openData) throws Exception JavaDoc
126    {
127       return MXBeanUtils.reconstruct(openType, type, openData, getClass().getName() + "#" + getName());
128    }
129 }
130
Popular Tags