1 22 package org.jboss.test.mx.mxbean.test; 23 24 import java.lang.reflect.Type ; 25 26 import javax.management.openmbean.OpenType ; 27 28 import junit.framework.AssertionFailedError; 29 30 import org.jboss.mx.mxbean.MXBeanUtils; 31 32 38 public abstract class CompositeDataTest extends AbstractMXBeanTest 39 { 40 public CompositeDataTest(String name) 41 { 42 super(name); 43 } 44 45 protected void constructReconstructTest(Object initialValue) throws Exception 46 { 47 constructReconstructTest(initialValue, initialValue); 48 } 49 50 protected void constructReconstructTest(Object initialValue, Type type) throws Exception 51 { 52 constructReconstructTest(initialValue, type, initialValue); 53 } 54 55 protected void constructReconstructTest(Object initialValue, Type type, Object expectedOpenData) throws Exception 56 { 57 constructReconstructTest(initialValue, type, expectedOpenData, initialValue); 58 } 59 60 protected void assertNullFailure(Type type) throws Exception 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 t) 72 { 73 checkThrowable(IllegalArgumentException .class, t); 74 } 75 } 76 77 protected void constructReconstructTest(Object initialValue, Object expectedOpenData) throws Exception 78 { 79 constructReconstructTest(initialValue, expectedOpenData, initialValue); 80 } 81 82 protected void constructReconstructTest(Object initialValue, Object expectedOpenData, Object expected) throws Exception 83 { 84 Type type = initialValue.getClass(); 85 constructReconstructTest(initialValue, type, expectedOpenData, expected); 86 } 87 88 protected void constructReconstructTest(Object initialValue, Type type, Object expectedOpenData, Object expected) throws Exception 89 { 90 OpenType openType = MXBeanUtils.getOpenType(type); 91 constructReconstructTest(initialValue, type, openType, expectedOpenData, expected); 92 } 93 94 protected void constructReconstructTest(Object initialValue, Type type, OpenType openType, Object expectedOpenData, Object expected) throws Exception 95 { 96 Object 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 finalValue = reconstruct(openType, type, openData); 102 checkFinalEquals(expected, finalValue); 103 } 104 105 protected void checkOpenDataEquals(Object expected, Object actual) 106 { 107 checkEquals(expected, actual); 108 } 109 110 protected void checkFinalEquals(Object expected, Object actual) 111 { 112 checkEquals(expected, actual); 113 } 114 115 protected void checkEquals(Object expected, Object actual) 116 { 117 assertEquals(expected, actual); 118 } 119 120 protected Object construct(OpenType openType, Type type, Object value) throws Exception 121 { 122 return MXBeanUtils.construct(openType, value, getClass().getName() + "#" + getName()); 123 } 124 125 protected Object reconstruct(OpenType openType, Type type, Object openData) throws Exception 126 { 127 return MXBeanUtils.reconstruct(openType, type, openData, getClass().getName() + "#" + getName()); 128 } 129 } 130 | Popular Tags |