@Test
public void testToCompositeData() throws Exception {

    ServiceReference<?> reference = mock(ServiceReference.class);
    Bundle bundle = mock(Bundle.class);
    String[] interfaces = new String[] { "org.apache.aries.jmx.Test", "org.apache.aries.jmx.Mock" };
    Bundle b1 = mock(Bundle.class);
    when(b1.getBundleId()).thenReturn(new Long(6));
    Bundle b2 = mock(Bundle.class);
    when(b2.getBundleId()).thenReturn(new Long(9));
    when(reference.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(98));
    when(reference.getBundle()).thenReturn(bundle);
    when(bundle.getBundleId()).thenReturn(new Long(34));
    when(reference.getProperty(Constants.OBJECTCLASS)).thenReturn(interfaces);
    when(reference.getUsingBundles()).thenReturn(new Bundle[] { b1, b2 });
    when(reference.getPropertyKeys()).thenReturn( new String[] {"x.vendor", "x.domain", "x.index", "x.optimized" } );
    when(reference.getProperty("x.vendor")).thenReturn("aries");
    when(reference.getProperty("x.domain")).thenReturn("test");
    when(reference.getProperty("x.index")).thenReturn(new Long(67));
    when(reference.getProperty("x.optimized")).thenReturn(true);
    ServiceData serviceData = new ServiceData(reference);
    CompositeData compositeData = serviceData.toCompositeData();
    assertEquals(new Long(98), compositeData.get(IDENTIFIER));
    assertEquals(new Long(34), compositeData.get(BUNDLE_IDENTIFIER));
    assertArrayEquals( new Long[] {new Long(6), new Long(9)}, (Long[]) compositeData.get(USING_BUNDLES));
    assertArrayEquals(interfaces, (String[]) compositeData.get(OBJECT_CLASS));
    TabularData propertiesTable = (TabularData) compositeData.get(PROPERTIES);
    @SuppressWarnings("unchecked")
    Collection<CompositeData> propertyData = (Collection<CompositeData>) propertiesTable.values();
    assertEquals(4, propertyData.size());
    for (CompositeData propertyRow: propertyData) {
        String key = (String) propertyRow.get(KEY);
        if (key.equals("x.vendor")) {
            assertEquals("aries", propertyRow.get(VALUE));
            assertEquals(STRING, propertyRow.get(TYPE));
        } else if (key.equals("x.domain")) {
            assertEquals("test", propertyRow.get(VALUE));
            assertEquals(STRING, propertyRow.get(TYPE));
        } else if (key.equals("x.index")) {
            assertEquals("67", propertyRow.get(VALUE));
            assertEquals(LONG, propertyRow.get(TYPE));
        } else if (key.equals("x.optimized")) {
            assertEquals("true", propertyRow.get(VALUE));
            assertEquals(BOOLEAN, propertyRow.get(TYPE));
        } else {
            fail("unknown key parsed from properties");
        }
    }
}