package com.ctrip.ops.sysdev.render;

/**
 * Created by liujia on 17/2/10.
 */

import com.ctrip.ops.sysdev.fieldDeleter.FieldDeleter;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

public class TestFieldDeleter {
    @Test
    public void testFieldDeleter() {
        FieldDeleter fieldDeleter = FieldDeleter.getFieldDeleter("[a][b]");
        HashMap event = new HashMap() {{
            this.put("test1", "ab");
            this.put("a", new HashMap() {{
                this.put("b", 123);
                this.put("b2", "hello");
            }});
        }};

        fieldDeleter.delete(event);
        Assert.assertEquals(event.get("test1"), "ab");
        Assert.assertEquals(((Map) event.get("a")).get("b2"), "hello");
        Assert.assertNull(((Map) event.get("a")).get("b"));
    }
}

@@ -208,23 +208,71 @@
 va.util.
-HashMap
+Arrays;%0Aimport java.util.HashMap;%0Aimport java.util.List
 ;%0Aimport
@@ -826,32 +826,32 @@
 b2%22), %22hello%22);%0A
-
         Assert.a
@@ -893,16 +893,1590 @@
 t(%22b%22));
+%0A%0A        // delete a map%0A        fieldDeleter = FieldDeleter.getFieldDeleter(%22a%22);%0A        event = new HashMap() %7B%7B%0A            this.put(%22test1%22, %22ab%22);%0A            this.put(%22a%22, new HashMap() %7B%7B%0A                this.put(%22b%22, 123);%0A                this.put(%22b2%22, %22hello%22);%0A            %7D%7D);%0A        %7D%7D;%0A%0A        fieldDeleter.delete(event);%0A        Assert.assertEquals(event.get(%22test1%22), %22ab%22);%0A        Assert.assertNull(event.get(%22a%22));%0A%0A%0A        // NOT contain%0A        fieldDeleter = FieldDeleter.getFieldDeleter(%22%5Ba%5D%5Bb%5D%22);%0A        event = new HashMap() %7B%7B%0A            this.put(%22test1%22, %22ab%22);%0A            this.put(%22a%22, Arrays.asList(1, 2));%0A        %7D%7D;%0A%0A        fieldDeleter.delete(event);%0A        Assert.assertEquals(event.get(%22test1%22), %22ab%22);%0A        Assert.assertEquals(((List) event.get(%22a%22)).size(), 2);%0A        Assert.assertEquals(((List) event.get(%22a%22)).get(0), 1);%0A        Assert.assertEquals(((List) event.get(%22a%22)).get(1), 2);%0A%0A        // NOT map%0A        fieldDeleter = FieldDeleter.getFieldDeleter(%22%5Ba%5D%5Bb%5D%5Bc%5D%22);%0A        event = new HashMap() %7B%7B%0A            this.put(%22test1%22, %22ab%22);%0A            this.put(%22a%22, new HashMap() %7B%7B%0A                this.put(%22b%22, Arrays.asList(1, 2));%0A            %7D%7D);%0A        %7D%7D;%0A%0A        fieldDeleter.delete(event);%0A        Assert.assertEquals(event.get(%22test1%22), %22ab%22);%0A        Assert.assertEquals(((Map) event.get(%22a%22)).size(), 1);%0A        Map a = (Map) event.get(%22a%22);%0A        List b = (List) a.get(%22b%22);%0A        Assert.assertEquals(b.size(), 2);%0A        Assert.assertEquals(b.get(0), 1);%0A        Assert.assertEquals(b.get(1), 2);
 %0A    %7D%0A%7D

add test case