// Path: hangout-filters/hangout-filters-filters/src/main/java/com/ctrip/ops/sysdev/filters/Filters.java
// @Log4j2
// public class Filters extends BaseFilter {
//     public Filters(Map config) {
//         super(config);
//     }
// 
//     protected List<BaseFilter> filterProcessors;
//     private Map<String, Object> event;
// 
//     protected void prepare() {
//         ArrayList<Map> filters = (ArrayList<Map>) config.get("filters");
// 
//         this.filterProcessors = Utils.createFilterProcessors(filters);
//         for (BaseFilter filterProcessor : filterProcessors) {
//             if (filterProcessor.processExtraEventsFunc == true) {
//                 this.processExtraEventsFunc = true;
//             }
//         }
//     }
// 
//     @Override
//     protected Map filter(Map event) {
//         if (this.processExtraEventsFunc == true) {
//             //will prcess the event in filterExtraEvents
//             this.event = event;
//             return event;
//         }
//         if (this.filterProcessors != null) {
//             for (BaseFilter bf : filterProcessors) {
//                 if (event == null) {
//                     break;
//                 }
//                 event = bf.process(event);
//             }
//         }
//         return event;
//     }
// 
//     @Override
//     protected void filterExtraEvents(Stack<Map<String, Object>> to_st) {
//         Stack<Map<String, Object>> from_st = new Stack<Map<String, Object>>();
//         from_st.push(event);
// 
//         for (BaseFilter bf : filterProcessors) {
//             while (!from_st.empty()) {
//                 Map rst = bf.process(from_st.pop());
//                 if (rst != null) {
//                     to_st.push(rst);
//                 }
//             }
//             if (bf.processExtraEventsFunc == true) {
//                 bf.processExtraEvents(to_st);
//             }
//         }
//         return;
//     }
// }


import com.ctrip.ops.sysdev.filters.Filters;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.yaml.snakeyaml.Yaml;
import java.util.HashMap;
import java.util.Map;
package com.ctrip.ops.sysdev.test;



public class TestFilters {
    @Test
    @SuppressWarnings({"rawtypes", "unchecked"})
    public void testFilters() {
        // General Test
        String c = String.format("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
                "if:",
                "  - '<#if message??>true</#if>'",
                "  - '<#if message?contains(\"liu\")>true<#elseif message?contains(\"warn\")>true</#if>'",
                "filters:",
                "    - Grok:",
                "        match:",
                "          - '^(?<logtime>\\S+) %{USERNAME:user} (-|%{LOGLEVEL:level}) %{DATA:msg}$'",
                "        remove_fields: ['message']",
                "    - Add:",
                "        fields:",
                "            test: 'abcd'",
                "    - Date:",
                "        src: logtime",
                "        formats:",
                "            - 'ISO8601'",
                "        remove_fields: ['logtime']");


        Yaml yaml = new Yaml();
        Map config = (Map) yaml.load(c);
        Assert.assertNotNull(config);

// Path: hangout-filters/hangout-filters-filters/src/main/java/com/ctrip/ops/sysdev/filters/Filters.java
// @Log4j2
// public class Filters extends BaseFilter {
//     public Filters(Map config) {
//         super(config);
//     }
// 
//     protected List<BaseFilter> filterProcessors;
//     private Map<String, Object> event;
// 
//     protected void prepare() {
//         ArrayList<Map> filters = (ArrayList<Map>) config.get("filters");
// 
//         this.filterProcessors = Utils.createFilterProcessors(filters);
//         for (BaseFilter filterProcessor : filterProcessors) {
//             if (filterProcessor.processExtraEventsFunc == true) {
//                 this.processExtraEventsFunc = true;
//             }
//         }
//     }
// 
//     @Override
//     protected Map filter(Map event) {
//         if (this.processExtraEventsFunc == true) {
//             //will prcess the event in filterExtraEvents
//             this.event = event;
//             return event;
//         }
//         if (this.filterProcessors != null) {
//             for (BaseFilter bf : filterProcessors) {
//                 if (event == null) {
//                     break;
//                 }
//                 event = bf.process(event);
//             }
//         }
//         return event;
//     }
// 
//     @Override
//     protected void filterExtraEvents(Stack<Map<String, Object>> to_st) {
//         Stack<Map<String, Object>> from_st = new Stack<Map<String, Object>>();
//         from_st.push(event);
// 
//         for (BaseFilter bf : filterProcessors) {
//             while (!from_st.empty()) {
//                 Map rst = bf.process(from_st.pop());
//                 if (rst != null) {
//                     to_st.push(rst);
//                 }
//             }
//             if (bf.processExtraEventsFunc == true) {
//                 bf.processExtraEvents(to_st);
//             }
//         }
//         return;
//     }
// }


// Path: hangout-filters/hangout-filters-filters/src/test/java/com/ctrip/ops/sysdev/test/TestFilters.java
import com.ctrip.ops.sysdev.filters.Filters;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.yaml.snakeyaml.Yaml;
import java.util.HashMap;
import java.util.Map;

package com.ctrip.ops.sysdev.test;



public class TestFilters {
    @Test
    @SuppressWarnings({"rawtypes", "unchecked"})
    public void testFilters() {
        // General Test
        String c = String.format("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
                "if:",
                "  - '<#if message??>true</#if>'",
                "  - '<#if message?contains(\"liu\")>true<#elseif message?contains(\"warn\")>true</#if>'",
                "filters:",
                "    - Grok:",
                "        match:",
                "          - '^(?<logtime>\\S+) %{USERNAME:user} (-|%{LOGLEVEL:level}) %{DATA:msg}$'",
                "        remove_fields: ['message']",
                "    - Add:",
                "        fields:",
                "            test: 'abcd'",
                "    - Date:",
                "        src: logtime",
                "        formats:",
                "            - 'ISO8601'",
                "        remove_fields: ['logtime']");


        Yaml yaml = new Yaml();
        Map config = (Map) yaml.load(c);
        Assert.assertNotNull(config);

        Filters Filtersfilter = new Filters(config);