Package com.linkedin.data

Examples of com.linkedin.data.DataList


    {
      dataMapsOfRecordTemplates.add(recordTemplate.data());
    }
    DataMap dataMapCollection = new DataMap();
    dataMapCollection.put(CollectionResponse.ELEMENTS,
                          new DataList(dataMapsOfRecordTemplates));
    return new CollectionResponse<T>(dataMapCollection, entryClass);
  }
View Full Code Here


    DataMap actual = new DataMap();
    actual.put("key1", "value1");

    DataMap expected = new DataMap();
    expected.put("key1", "value1");
    expected.put("key2", new DataList());
    expected.put("key3", new DataMap());

    try
    {
      DataAssert.assertDataMapsEqual(actual, expected, Collections.<String>emptySet(), false);
View Full Code Here

      }

      // test wrapping
      array1.clear();
      array1.addAll(input);
      DataList dataList2 = new DataList();
      ArrayTemplate array2 = DataTemplateUtil.wrap(dataList2, schema, templateClass); // with schema arg
      for (E e : input)
      {
        if (e instanceof DataTemplate)
        {
          dataList2.add(((DataTemplate<?>) e).data());
        }
        else if (e instanceof Enum)
        {
          dataList2.add(e.toString());
        }
        else
        {
          dataList2.add(e);
        }
      }
      assertEquals(array1, array2);
      ArrayTemplate array2a = DataTemplateUtil.wrap(dataList2, templateClass); // without schema arg
      assertEquals(array1, array2a);
View Full Code Here

  {
    try
    {
      Exception exc = null;
      ArrayTemplate arrayTemplateBad = templateClass.newInstance();
      DataList badDataList = new DataList();
      ArrayTemplate badWrappedArrayTemplate = DataTemplateUtil.wrap(badDataList, schema, templateClass);

      List<E> badIn = (List<E>) badInput;

      // add(E element)
      for (E o : badIn)
      {
        try
        {
          exc = null;
          arrayTemplateBad.add(o);
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(o == null || exc instanceof ClassCastException);
        assertTrue(o != null || exc instanceof NullPointerException);
      }

      // add(int index, E element)
      for (Object o : badIn)
      {
        try
        {
          exc = null;
          arrayTemplateBad.add(0, (E) o);
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(o == null || exc instanceof ClassCastException);
        assertTrue(o != null || exc instanceof NullPointerException);
      }

      // addAll(Collection<E> c)
      try
      {
        exc = null;
        arrayTemplateBad.addAll(badIn);
      }
      catch (Exception e)
      {
        exc = e;
      }
      assertTrue(exc != null);
      assertTrue(exc instanceof ClassCastException);

      // set(int index, E element)
      arrayTemplateBad.addAll(good);
      assertTrue(arrayTemplateBad.size() > 1);
      for (Object o : badIn)
      {
        try
        {
          exc = null;
          arrayTemplateBad.set(0, (E) o);
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(o == null || exc instanceof ClassCastException);
        assertTrue(o != null || exc instanceof NullPointerException);
      }

      // listIterator add
      for (Object o : badIn)
      {
        try
        {
          exc = null;
          ListIterator<E> it = arrayTemplateBad.listIterator(0);
          it.add((E) o);
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(o == null || exc instanceof ClassCastException);
        assertTrue(o != null || exc instanceof NullPointerException);
      }

      // listIterator set
      for (Object o : badIn)
      {
        try
        {
          exc = null;
          ListIterator<E> it = arrayTemplateBad.listIterator(0);
          it.next();
          it.set((E) o);
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(o == null || exc instanceof ClassCastException);
        assertTrue(o != null || exc instanceof NullPointerException);
      }

      badDataList.clear();
      badDataList.addAll(badOutput);
      badWrappedArrayTemplate = DataTemplateUtil.wrap(badDataList, schema, templateClass);

      // Get returns bad
      for (int i = 0; i < badWrappedArrayTemplate.size(); ++i)
      {
        try
        {
          exc = null;
          badWrappedArrayTemplate.get(i);
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(exc instanceof TemplateOutputCastException);
      }

      // Set returns bad
      badDataList.clear();
      badDataList.addAll(badOutput);
      assertEquals(badWrappedArrayTemplate.size(), badOutput.size());
      for (int i = 0; i < badWrappedArrayTemplate.size(); ++i)
      {
        try
        {
          exc = null;
          badWrappedArrayTemplate.set(i, good.get(0));
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(exc instanceof TemplateOutputCastException);
      }

      // Remove returns bad
      badDataList.clear();
      badDataList.addAll(badOutput);
      assertEquals(badWrappedArrayTemplate.size(), badOutput.size());
      for (int i = 0; i < badWrappedArrayTemplate.size(); ++i)
      {
        try
        {
          exc = null;
          badWrappedArrayTemplate.remove(0);
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(exc instanceof TemplateOutputCastException);
      }

      // Iterator returns bad
      for (Object o : badOutput)
      {
        badDataList.clear();
        badDataList.add(o);
        try
        {
          exc = null;
          badWrappedArrayTemplate.iterator().next();
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(exc instanceof TemplateOutputCastException);
      }

      // ListIterator returns bad
      for (Object o : badOutput)
      {
        badDataList.clear();
        badDataList.add(o);
        try
        {
          exc = null;
          badWrappedArrayTemplate.listIterator().next();
        }
        catch (Exception e)
        {
          exc = e;
        }
        assertTrue(exc != null);
        assertTrue(exc instanceof TemplateOutputCastException);
      }
      for (Object o : badOutput)
      {
        badDataList.clear();
        badDataList.add(o);
        try
        {
          exc = null;
          badWrappedArrayTemplate.listIterator(badWrappedArrayTemplate.size()).previous();
        }
View Full Code Here

      // deleteCommand value is of type DataList
      assert deleteCommand.getClass() == DataList.class;
      // data is of type DataMap
      assert data.getClass() == DataMap.class;

      DataList delDataList = (DataList) deleteCommand;
      DataMap dataDataMap = (DataMap) data;

      for (Object key : delDataList)
      {
        if (usedFields.containsKey(key))
View Full Code Here

        assertEquals(castTo.get(i), array1.get(i));
        assertEquals(array1.data().get(i), castTo.get(i));
      }

      // test underlying is non-native, convert on get to element type on get.
      DataList dataList2 = new DataList(castFrom);
      ArrayTemplate array2 = DataTemplateUtil.wrap(dataList2, schema, templateClass);
      for (int i = 0; i < castTo.size(); ++i)
      {
        assertSame(dataList2.get(i), castFrom.get(i));
        assertEquals(castTo.get(i), array2.get(i));
      }
    }
    catch (InstantiationException exc)
    {
View Full Code Here

    ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"boolean\" }");

    List<Boolean> input = Arrays.asList(true, false); // must be unique
    List<Boolean> adds = Arrays.asList(false, true, true, false);
    List<Object> badInput = asList(1, 2L, 3f, 4.0, "hello", ByteString.empty(), new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(1, 2L, 3f, 4.0, "hello", ByteString.empty(), new DataMap(), new DataList());

    testArray(BooleanArray.class, schema, input, adds);
    testArrayBadInput(BooleanArray.class, schema, input, badInput, badOutput);
  }
View Full Code Here

    ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"int\" }");

    List<Integer> input = Arrays.asList(1, 3, 5, 7, 11); // must be unique
    List<Integer> adds = Arrays.asList(13, 17, 19);
    List<Object> badInput = asList(true, "hello", ByteString.empty(), new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(true, "hello", ByteString.empty(), new DataMap(), new DataList());

    testArray(IntegerArray.class, schema, input, adds);
    testArrayBadInput(IntegerArray.class, schema, input, badInput, badOutput);

    @SuppressWarnings("unchecked")
View Full Code Here

    ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"long\" }");

    List<Long> input = Arrays.asList(1L, 3L, 5L, 7L, 11L); // must be unique
    List<Long> adds = Arrays.asList(13L, 17L, 19L);
    List<Object> badInput = asList(true, "hello", ByteString.empty(), new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(true, "hello", ByteString.empty(), new DataMap(), new DataList());

    testArray(LongArray.class, schema, input, adds);
    testArrayBadInput(LongArray.class, schema, input, badInput, badOutput);

    @SuppressWarnings("unchecked")
View Full Code Here

    ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"float\" }");

    List<Float> input = Arrays.asList(1.0f, 3.0f, 5.0f, 7.0f, 11.0f); // must be unique
    List<Float> adds = Arrays.asList(13.0f, 17.0f, 19.0f);
    List<Object> badInput = asList(true, "hello", ByteString.empty(), new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(true, "hello", ByteString.empty(), new DataMap(), new DataList());

    testArray(FloatArray.class, schema, input, adds);
    testArrayBadInput(FloatArray.class, schema, input, badInput, badOutput);

    @SuppressWarnings("unchecked")
View Full Code Here

TOP

Related Classes of com.linkedin.data.DataList

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.