Package org.jboss.metatype.api.values

Examples of org.jboss.metatype.api.values.TableValueSupport


    */
   public void testValues() throws Exception
   {
      TableMetaType tableType = initTableType();

      TableValueSupport data = new TableValueSupport(tableType);

      CompositeValue compData = initCompositeValue(data);
      CompositeValue compData2 = initCompositeValue2(data);
      CompositeValue compData3 = initCompositeValue4(data);

      data.putAll(new CompositeValue[] { compData, compData2, compData3 });

      Collection<CompositeValue> values = data.values();
      assertEquals("Values should contain 3 elements", 3, values.size());
      assertTrue("Values should contain index compData", values.contains(compData));
      assertTrue("Values should contain index compData2", values.contains(compData2));
      assertTrue("Values should contain index compData3", values.contains(compData3));
   }
View Full Code Here


    */
   public void testClone() throws Exception
   {
      TableMetaType tableType = initTableType();

      TableValueSupport data = new TableValueSupport(tableType);

      CompositeValue compData = initCompositeValue(data);
      CompositeValue compData2 = initCompositeValue2(data);
      CompositeValue compData3 = initCompositeValue4(data);

      data.putAll(new CompositeValue[] { compData, compData2, compData3 });

      TableValue clone = data.clone();
      assertEquals("Clone should have the same tabular type", data.getMetaType(), clone.getMetaType());
      assertEquals("Clone should have the same number of elements", data.size(), clone.size());
      CompositeValue compDataClone = clone.get(initValues());
      assertTrue("Should be a shallow clone", compData == compDataClone);
   }
View Full Code Here

    */
   public void testEquals() throws Exception
   {
      TableMetaType tableType = initTableType();

      TableValueSupport data = new TableValueSupport(tableType);

      assertNotSame("Null should not be equal", data, null);
      assertNotSame("Only TableValues should be equal", data, new Object());

      assertEquals("An instance should equal itself", data, data);

      TableValueSupport data2 = new TableValueSupport(tableType);

      assertEquals("Two different instances with the same table type are equal", data, data2);
      assertEquals("Two different instances with the same table type are equal", data2, data);

      TableMetaType tableType2 = initTableType2();
      data2 = new TableValueSupport(tableType2);

      assertNotSame("Instances with different table type are not equal", data, data2);
      assertNotSame("Instances with different table type are not equal", data2, data);

      CompositeValue compData = initCompositeValue(data);
      CompositeValue compData2 = initCompositeValue2(data);
      CompositeValue compData3 = initCompositeValue4(data);

      data.putAll(new CompositeValue[] { compData, compData2, compData3 });

      data2 = new TableValueSupport(tableType);
      data2.putAll(new CompositeValue[] { compData, compData2, compData3 });
      assertEquals("Instances with the same composite values are equal", data, data2);
      assertEquals("Instances with the same composite values are equal", data2, data);

      data2 = new TableValueSupport(tableType);
      data2.putAll(new CompositeValue[] { compData, compData2});
      assertNotSame("Instances with different composite values are not equal", data, data2);
      assertNotSame("Instances with different composite values are not equal", data2, data);
   }
View Full Code Here

    */
   public void testHashCode() throws Exception
   {
      TableMetaType tableType = initTableType();

      TableValueSupport data = new TableValueSupport(tableType);

      CompositeValue compData = initCompositeValue(data);
      CompositeValue compData2 = initCompositeValue2(data);
      CompositeValue compData3 = initCompositeValue4(data);

      data.putAll(new CompositeValue[] { compData, compData2, compData3 });

      int myHashCode = tableType.hashCode() + compData.hashCode() + compData2.hashCode() + compData3.hashCode();
      assertEquals("Wrong hash code generated", myHashCode, data.hashCode());
   }
View Full Code Here

    */
   public void testToString() throws Exception
   {
      TableMetaType tableType = initTableType();

      TableValueSupport data = new TableValueSupport(tableType);

      CompositeValue compData = initCompositeValue(data);
      CompositeValue compData2 = initCompositeValue2(data);
      CompositeValue compData3 = initCompositeValue4(data);

      data.putAll(new CompositeValue[] { compData, compData2, compData3 });

      String toString = data.toString();

      assertTrue("toString() should contain the tabular type", toString.indexOf(tableType.toString()) != -1);
      assertTrue("toString() should contain index=compositeValue for compData",
         toString.indexOf(Arrays.asList(data.calculateIndex(compData)) + "=" + compData) != -1);
      assertTrue("toString() should contain index=compositeValue for compData2",
         toString.indexOf(Arrays.asList(data.calculateIndex(compData2)) + "=" + compData2) != -1);
      assertTrue("toString() should contain index=compositeValue for compData3",
         toString.indexOf(Arrays.asList(data.calculateIndex(compData3)) + "=" + compData3) != -1);
   }
View Full Code Here

    */
   public void testSerialization() throws Exception
   {
      TableMetaType tableType = initTableType();

      TableValueSupport data = new TableValueSupport(tableType);

      CompositeValue compData = initCompositeValue(data);
      CompositeValue compData2 = initCompositeValue2(data);
      CompositeValue compData3 = initCompositeValue4(data);

      data.putAll(new CompositeValue[] { compData, compData2, compData3 });

      byte[] bytes = serialize(data);
      Object result = deserialize(bytes);
      assertEquals(data, result);
   }
View Full Code Here

      CompositeValue compData = initCompositeValue(tableType.getRowType());
      CompositeValue compData2 = initCompositeValue2(initCompositeMetaType2());

      try
      {
         new TableValueSupport(null);
         fail("Expected IllegalArgumentException for null tabular type");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         new TableValueSupport(null, 10, .5f);
         fail("Expected IllegalArgumentException for null tabular type");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         new TableValueSupport(tableType, -1, .5f);
         fail("Expected IllegalArgumentException for negative initial capacity");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         new TableValueSupport(tableType, 10, 0f);
         fail("Expected IllegalArgumentException for zero load factor");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         new TableValueSupport(tableType, 10, -0.5f);
         fail("Expected IllegalArgumentException for negative load factor");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         data.calculateIndex(null);
         fail("Expected IllegalArgumentException for calculate index on null object");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         data.calculateIndex(compData2);
         fail("Expected IllegalArgumentException for calculate index on wrong composite type");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         data.get((MetaValue[]) null);
         fail("Expected IllegalArgumentException for get(null)");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         data.get(new MetaValue[] { initStringWrong() });
         fail("Expected IllegalArgumentException for get(wrong)");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         data.put(null);
         fail("Expected IllegalArgumentException for put(CompositeValue) with null value");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         data.put(compData2);
         fail("Expected IllegalArgumentException for put(CompositeValue) with wrong CompositeType");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         data.put(compData);
         data.put(compData);
         fail("Expected IllegalArgumentException for put(CompositeValue)");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         data.remove((MetaValue[]) null);
         fail("Expected IllegalArgumentException for remove(null)");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         data.remove(new MetaValue[] { initStringWrong() });
         fail("Expected IllegalArgumentException for remove(wrong)");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         CompositeValue[] toPut = new CompositeValue[] { compData, null };
         data.putAll(toPut);
         fail("Expected IllegalArgumentException for putAll(CompositeValue[]) null");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         CompositeValue[] toPut = new CompositeValue[] { compData, compData2 };
         data.putAll(toPut);
         fail("Expected IllegalArgumentException for putAll(CompositeValue[]) wrong composite type");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         CompositeValue[] toPut = new CompositeValue[] { compData, compData };
         data.putAll(toPut);
         fail("Expected IllegalArgumentException for putAll(CompositeValue[]) with duplicate data");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
      }
     
      try
      {
         TableValueSupport data = new TableValueSupport(tableType);
         CompositeValue[] toPut = new CompositeValue[] { compData };
         data.putAll(toPut);
         data.putAll(toPut);
         fail("Expected IllegalArgumentException for putAll(CompositeValue[]) adding a duplicate");
      }
      catch (Throwable t)
      {
         checkThrowable(IllegalArgumentException.class, t);
View Full Code Here

      MetaType[] itemTypes = { keyType, valueType };
      String entryName = Map.Entry.class.getName();
      CompositeMetaType entryType = new ImmutableCompositeMetaType(entryName, entryName, DefaultMetaTypeFactory.MAP_ITEM_NAMES, DefaultMetaTypeFactory.MAP_ITEM_NAMES, itemTypes);
      TableMetaType tableType = new ImmutableTableMetaType(Map.class.getName(), Map.class.getName(), entryType, DefaultMetaTypeFactory.MAP_INDEX_NAMES);
     
      TableValue expected = new TableValueSupport(tableType);
      String[] itemNames = DefaultMetaTypeFactory.MAP_ITEM_NAMES;
     
      MetaValue[] keyValues1 = {SimpleValueSupport.wrap("Hello")};
      CompositeValueSupport key1 = new CompositeValueSupport(keyType, new String[]{"key"}, keyValues1);
      MetaValue[] itemValues = new MetaValue[] {key1, SimpleValueSupport.wrap(new Integer(1)) };
      expected.put(new CompositeValueSupport(entryType, itemNames, itemValues));

      MetaValue[] keyValues2 = {SimpleValueSupport.wrap("Goodbye")};
      CompositeValueSupport key2 = new CompositeValueSupport(keyType, new String[]{"key"}, keyValues2);
      itemValues = new MetaValue[] { key2, SimpleValueSupport.wrap(new Integer(2)) };
      expected.put(new CompositeValueSupport(entryType, itemNames, itemValues));

      MetaValue result = createMetaValue(map, collectionType);
      TableValue actual = assertInstanceOf(result, TableValue.class);
     
      getLog().debug("Map Value: " + actual);
View Full Code Here

      MetaType[] itemTypes = { keyType, valueType };
      String entryName = Map.Entry.class.getName();
      CompositeMetaType entryType = new ImmutableCompositeMetaType(entryName, entryName, DefaultMetaTypeFactory.MAP_ITEM_NAMES, DefaultMetaTypeFactory.MAP_ITEM_NAMES, itemTypes);
      TableMetaType tableType = new ImmutableTableMetaType(Map.class.getName(), Map.class.getName(), entryType, DefaultMetaTypeFactory.MAP_INDEX_NAMES);
     
      TableValue expected = new TableValueSupport(tableType);
      String[] itemNames = DefaultMetaTypeFactory.MAP_ITEM_NAMES;
     
      MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestSimpleComposite.class.getName(), TestSimpleComposite.class.getName());
      compositeType.addItem("something", "something", SimpleMetaType.STRING);
      compositeType.freeze();

      String[] compositeNames = { "something" };
      CompositeValue compositeValue = new CompositeValueSupport(compositeType, compositeNames, new MetaValue[] { SimpleValueSupport.wrap("Hello") });
     
      MetaValue[] itemValues = new MetaValue[] { compositeValue, SimpleValueSupport.wrap(new Integer(1)) };
      expected.put(new CompositeValueSupport(entryType, itemNames, itemValues));

      compositeValue = new CompositeValueSupport(compositeType, compositeNames, new MetaValue[] { SimpleValueSupport.wrap("Goodbye") });
      itemValues = new MetaValue[] { compositeValue, SimpleValueSupport.wrap(new Integer(2)) };
      expected.put(new CompositeValueSupport(entryType, itemNames, itemValues));

      MetaValue result = createMetaValue(map, collectionType);
      TableValue actual = assertInstanceOf(result, TableValue.class);
     
      getLog().debug("Map Value: " + actual);
View Full Code Here

      MetaType[] itemTypes = { keyType, valueType };
      String entryName = Map.Entry.class.getName();
      CompositeMetaType entryType = new ImmutableCompositeMetaType(entryName, entryName, DefaultMetaTypeFactory.MAP_ITEM_NAMES, DefaultMetaTypeFactory.MAP_ITEM_NAMES, itemTypes);
      TableMetaType tableType = new ImmutableTableMetaType(Map.class.getName(), Map.class.getName(), entryType, DefaultMetaTypeFactory.MAP_INDEX_NAMES);
     
      TableValue expected = new TableValueSupport(tableType);
      String[] itemNames = DefaultMetaTypeFactory.MAP_ITEM_NAMES;
     
      MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestSimpleComposite.class.getName(), TestSimpleComposite.class.getName());
      compositeType.addItem("something", "something", SimpleMetaType.STRING);
      compositeType.freeze();

      String[] compositeNames = { "something" };
      CompositeValue compositeValue = new CompositeValueSupport(compositeType, compositeNames, new MetaValue[] { SimpleValueSupport.wrap("Hello") });
     
      MetaValue[] keyValues1 = {SimpleValueSupport.wrap("Hello")};
      CompositeValueSupport key1 = new CompositeValueSupport(keyType, new String[]{"key"}, keyValues1);
      MetaValue[] itemValues = new MetaValue[] { key1, compositeValue };
      expected.put(new CompositeValueSupport(entryType, itemNames, itemValues));

      MetaValue[] keyValues2 = {SimpleValueSupport.wrap("Goodbye")};
      CompositeValueSupport key2 = new CompositeValueSupport(keyType, new String[]{"key"}, keyValues2);
      compositeValue = new CompositeValueSupport(compositeType, compositeNames, new MetaValue[] { SimpleValueSupport.wrap("Goodbye") });
      itemValues = new MetaValue[] { key2, compositeValue };
      expected.put(new CompositeValueSupport(entryType, itemNames, itemValues));

      MetaValue result = createMetaValue(map, collectionType);
      TableValue actual = assertInstanceOf(result, TableValue.class);
     
      getLog().debug("Map Value: " + actual);
View Full Code Here

TOP

Related Classes of org.jboss.metatype.api.values.TableValueSupport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.