1 8 package test.javax.management.openmbean; 9 10 import java.util.Collection ; 11 import javax.management.openmbean.CompositeDataSupport ; 12 import javax.management.openmbean.CompositeType ; 13 import javax.management.openmbean.OpenDataException ; 14 import javax.management.openmbean.OpenType ; 15 import javax.management.openmbean.SimpleType ; 16 import javax.management.openmbean.TabularDataSupport ; 17 import javax.management.openmbean.TabularType ; 18 19 import junit.framework.TestCase; 20 21 24 public class CompositeDataSupportTest extends TestCase 25 { 26 private String [] itemNames = null; 27 private String [] itemDescriptions = null; 28 private OpenType [] itemTypes; 29 private CompositeType tShirtType; 30 31 private String [] indexNames; 32 private TabularType allTShirtTypes; 33 private TabularDataSupport tabularSupport; 34 35 private CompositeDataSupport compositeData; 36 37 public CompositeDataSupportTest(String s) 38 { 39 super(s); 40 } 41 42 protected void setUp() throws Exception 43 { 44 super.setUp(); 45 itemNames = new String []{"model", "color", "size", "price"}; 46 itemDescriptions = new String []{"TShirt's model name", "TShirt's color", "TShirt's size", "TShirt's price"}; 47 itemTypes = new OpenType []{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.FLOAT}; 48 indexNames = new String []{"model", "color", "size"}; 49 tShirtType = new CompositeType ("tShirt", 50 "a TShirt", 51 itemNames, 52 itemDescriptions, 53 itemTypes); 54 55 allTShirtTypes = new TabularType ("tShirts", 56 "List of available TShirts", 57 tShirtType, indexNames); 59 60 Object [] itemValues = new Object []{"MX4J", "red", "L", new Float (15.0f)}; 61 62 compositeData = new CompositeDataSupport (tShirtType, itemNames, itemValues); 63 tabularSupport = new TabularDataSupport (allTShirtTypes); 65 } 66 67 protected void tearDown() throws Exception 68 { 69 super.tearDown(); 70 } 71 72 public void testConstructor() 73 { 74 try 75 { 76 Object [] itemValues = new Object []{"MX4J", "red", "L", new Float (15.0f)}; 77 CompositeDataSupport support = new CompositeDataSupport (tShirtType, itemNames, itemValues); 78 assertTrue(support != null); 79 } 80 catch (OpenDataException e) 81 { 82 e.printStackTrace(); 83 } 84 85 try 87 { 88 Object [] itemValues = new Object []{"MX4J", "red", null, new Float (15.0f)}; 89 CompositeDataSupport support = new CompositeDataSupport (tShirtType, itemNames, itemValues); 90 assertTrue(support != null); 91 } 92 catch (OpenDataException e) 93 { 94 e.printStackTrace(); 95 } 96 } 97 98 public void testGet() 99 { 100 String expected = "MX4J"; 101 String obj = (String )compositeData.get("model"); 102 assertTrue("expected was stored as the value against model", expected.equals(obj)); 103 104 } 105 106 public void testGetAll() 107 { 108 int expectedLength = 4; 109 Object [] obj = compositeData.getAll(itemNames); 110 assertEquals(expectedLength, obj.length); 111 } 112 113 public void testValues() 114 { 115 int expected = 4; 116 Collection result = compositeData.values(); 117 assertEquals(expected, result.size()); 118 } 119 120 public void testSparseValues() throws Exception 121 { 122 Object [] sparsevalues = new Object []{"MX4J", null, "L", new Float (15.0f)}; 123 CompositeDataSupport sparsedata = new CompositeDataSupport (tShirtType, itemNames, sparsevalues); 124 assertTrue("Null instance", sparsedata != null); 125 } 126 127 public void testEquals() throws Exception 128 { 129 Object [] testvalues = {"MX4J", "White", "XL", new Float (15.0f)}; 130 CompositeDataSupport cdone = 131 new CompositeDataSupport (tShirtType, itemNames, testvalues); 132 133 assertFalse("cdone equals 'null'", cdone.equals(null)); 134 assertFalse("cdone equals Integer value", 135 cdone.equals(new Integer (42))); 136 137 String [] items = new String []{"model", "color", "size", "price"}; 138 String [] descriptions = 139 new String []{ 140 "TShirt's model name", 141 "TShirt's color", 142 "TShirt's size", 143 "TShirt's price"}; 144 OpenType [] types = 145 new OpenType []{ 146 SimpleType.STRING, 147 SimpleType.STRING, 148 SimpleType.STRING, 149 SimpleType.FLOAT}; 150 CompositeType shirt = 151 new CompositeType ("tShirt", 152 "A 'Tee' Shirt", 153 items, 154 descriptions, 155 types); 156 CompositeDataSupport cdtwo = 157 new CompositeDataSupport (shirt, items, testvalues); 158 assertTrue("cdtwo not equal to cdone", cdtwo.equals(cdone)); 159 160 cdone = 161 new CompositeDataSupport (tShirtType, 162 items, 163 new Object []{"GAP", null, "S", new Float (30.0f)}); 164 cdtwo = 165 new CompositeDataSupport (shirt, 166 items, 167 new Object []{"GAP", null, "S", new Float (30.0f)}); 168 assertTrue("sparse cdtwo not equal to sparse cdone", 169 cdtwo.equals(cdone)); 170 171 } 172 } 173 | Popular Tags |