package com.linkedin.helix.store;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.linkedin.helix.ZNRecord;
import com.linkedin.helix.ZkUnitTestBase;
import com.linkedin.helix.manager.zk.ZkClient;
import com.linkedin.helix.store.zk.ZKPropertyStore;

public class TestZNRecordJsonSerializer extends ZkUnitTestBase
{

  @Test
  public void testZNRecordJsonSerializer() throws Exception
  {
    final String testRoot = getShortClassName();

    System.out.println("START " + testRoot + " at " + new Date(System.currentTimeMillis()));

    ZNRecord record = new ZNRecord("node1");
    record.setSimpleField(ZNRecord.LIST_FIELD_BOUND, "" + 3);
    List<String> list = Arrays.asList("one", "two", "three", "four");
    record.setListField("list1", list);

    ZKPropertyStore<ZNRecord> store = new ZKPropertyStore<ZNRecord>(new ZkClient(ZK_ADDR),
        new ZNRecordJsonSerializer(), "/" + testRoot);

    store.setProperty("node1", record);
    ZNRecord newRecord = store.getProperty("node1");
    Assert.assertTrue(newRecord.getListField("list1").size() == 3);

    System.out.println("START " + testRoot + " at " + new Date(System.currentTimeMillis()));

  }
}

@@ -751,16 +751,17 @@
 ng%3E list
+1
  = Array
@@ -809,41 +809,234 @@
     
-record.setListField(%22list1%22, list
+List%3CString%3E list2 = Arrays.asList(%22a%22, %22b%22, %22c%22, %22d%22);%0A    List%3CString%3E list3 = Arrays.asList(%22x%22, %22y%22);%0A    record.setListField(%22list1%22, list1);%0A    record.setListField(%22list2%22, list2);%0A    record.setListField(%22list3%22, list3
 );%0A%0A
@@ -1283,26 +1283,245 @@
     
-Assert.assertTrue(
+list1 = newRecord.getListField(%22list1%22);%0A    Assert.assertTrue(list1.size() == 3);%0A    Assert.assertTrue(list1.contains(%22two%22));%0A    Assert.assertTrue(list1.contains(%22three%22));%0A    Assert.assertTrue(list1.contains(%22four%22));%0A%0A    list2 = 
 newR
@@ -1548,23 +1548,360 @@
 list
-1%22).size() == 3
+2%22);%0A    Assert.assertTrue(list2.size() == 3);%0A    Assert.assertTrue(list2.contains(%22b%22));%0A    Assert.assertTrue(list2.contains(%22c%22));%0A    Assert.assertTrue(list2.contains(%22d%22));%0A%0A    list3 = newRecord.getListField(%22list3%22);%0A    Assert.assertTrue(list3.size() == 2);%0A    Assert.assertTrue(list3.contains(%22x%22));%0A    Assert.assertTrue(list3.contains(%22y%22)
 );%0A%0A
@@ -2000,8 +2000,9 @@
 %0A%0A  %7D%0A%7D%0A
+%0A

add more tests for znrecord list length bound