package com.alibaba.json.bvt.path;

import java.util.List;

import junit.framework.TestCase;

import org.junit.Assert;

import com.alibaba.fastjson.JSONPath;

public class JSONPath_field_wildcard extends TestCase {

    public void test_list_map() throws Exception {
        JSONPath path = new JSONPath("$.*");
        Entity entity = new Entity(123, "wenshao");

        List<Object> fieldValues = (List<Object>) path.eval(entity);
        Assert.assertSame(entity.getId(), fieldValues.get(0));
        Assert.assertSame(entity.getName(), fieldValues.get(1));
    }
    
    public void test_list_map_none_root() throws Exception {
        JSONPath path = new JSONPath("*");
        Entity entity = new Entity(123, "wenshao");
        
        List<Object> fieldValues = (List<Object>) path.eval(entity);
        Assert.assertSame(entity.getId(), fieldValues.get(0));
        Assert.assertSame(entity.getName(), fieldValues.get(1));
    }

    public static class Entity {

        private Integer id;
        private String  name;

        public Entity(Integer id, String name){
            this.id = id;
            this.name = name;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

    }
}

@@ -50,46 +50,122 @@
 til.
-List;%0A%0Aimport junit.framework.TestCase
+Collection;%0Aimport java.util.Iterator;%0Aimport java.util.LinkedHashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0Ai
@@ -228,16 +228,50 @@
 NPath;%0A%0A
+import junit.framework.TestCase;%0A%0A
 public c
@@ -427,38 +427,121 @@
     
-Entity entity = new Entity(123
+Map%3CString, Object%3E map = new LinkedHashMap%3CString, Object%3E();%0A        map.put(%22id%22, 123);%0A        map.put(%22name%22
 , %22w
@@ -551,36 +551,42 @@
 hao%22);%0A%0A        
-List
+Collection
 %3CObject%3E fieldVa
@@ -585,36 +585,42 @@
  fieldValues = (
-List
+Collection
 %3CObject%3E) path.e
@@ -627,76 +627,117 @@
 val(
-entity);%0A        Assert.assertSame(entity.getId(), fieldValues.ge
+map);%0A        Iterator%3CObject%3E it = fieldValues.iterator();%0A        Assert.assertSame(map.get(%22id%22), it.nex
 t(
-0
 ));%0A
@@ -766,43 +766,33 @@
 ame(
-entity
+map
 .get
-Name(), fieldValues.ge
+(%22name%22), it.nex
 t(
-1
 ));%0A

add testcase for JSONPath