<commit_before>/**
 * Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U
 *
 * This file is part of fiware-cygnus (FI-WARE project).
 *
 * fiware-cygnus is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
 * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * fiware-cygnus is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with fiware-cygnus. If not, see
 * http://www.gnu.org/licenses/.
 *
 * For those usages not covered by the GNU Affero General Public License please contact with iot_support at tid dot es
 */
package com.telefonica.iot.cygnus.interceptors;

import static com.telefonica.iot.cygnus.utils.TestUtils.getTestTraceHead;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 *
 * @author frb
 */
public class GroupingRuleTest {
    
    /**
     * Constructor.
     */
    public GroupingRuleTest() {
        LogManager.getRootLogger().setLevel(Level.FATAL);
    } // GroupingRuleTest
    
    /**
     * [Groupingrule.isValid] -------- fiware-servicePath field in a grouping rule must start with '/'.
     */
    @Test
    public void testFiwareServicePathStartsWithSlash() {
        System.out.println(getTestTraceHead("[GroupingRule.isValid]")
                + "-------- fiware-servicePath field in a grouping rule must start with '/'");
        JSONObject jsonRule = createJsonObject();
        
        try {
            assertEquals(0, GroupingRule.isValid(jsonRule, true));
            System.out.println(getTestTraceHead("[GroupingRule.isValid]")
                    + "-  OK  - The fiware-servicePath field in the rule '"
                    + jsonRule.toJSONString() + "' starts with '/'");
        } catch (AssertionError e) {
            System.out.println(getTestTraceHead("[GroupingRule.isValid]")
                    + "- FAIL - The fiware-servicePath field in the rule '"
                    + jsonRule.toJSONString() + "' does not start with '/'");
            throw e;
        } // try catch
    } // testFiwareServicePathStartsWithSlash
    
    /**
     * [Groupingrule.getXXXX] -------- Rule's attributes are not null.
     */
    @Test
    public void testIfGetsAreNotNull() {
        System.out.println(getTestTraceHead("[GroupingRule.getXXXX]")
                + "-------- Rule's attributes are not null");
        
        JSONObject jsonObject = createJsonObject();
        jsonObject.put("id",1L);
        
        // Create the rule for doing the tests
        GroupingRule rule = new GroupingRule(jsonObject);
        
        try { 
            assertTrue(rule.getPattern() != null);
            System.out.println(getTestTraceHead("[GroupingRule.getPattern]")
                    + "-  OK  - Rule’s pattern is not null");
        } catch (AssertionError e) {
            System.out.println(getTestTraceHead("[GroupingRule.getPattern]")
                    + "- FAIL - Rule’s pattern is null");
            throw e;
        } // try catch
        
        try { 
            assertTrue(rule.getId() > 0L);
            System.out.println(getTestTraceHead("[GroupingRule.getId]")
                    + "-  OK  - Rule’s id is upper than 0");
        } catch (AssertionError e) {
            System.out.println(getTestTraceHead("[GroupingRule.getId]")
                    + "- FAIL - Rule’s id is invalid");
            throw e;
        } // try catch<commit_msg>FIX minor issue<commit_after>/**
 * Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U
 *
 * This file is part of fiware-cygnus (FI-WARE project).
 *
 * fiware-cygnus is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
 * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * fiware-cygnus is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with fiware-cygnus. If not, see
 * http://www.gnu.org/licenses/.
 *
 * For those usages not covered by the GNU Affero General Public License please contact with iot_support at tid dot es
 */
package com.telefonica.iot.cygnus.interceptors;

import static com.telefonica.iot.cygnus.utils.TestUtils.getTestTraceHead;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 *
 * @author frb
 */
public class GroupingRuleTest {
    
    /**
     * Constructor.
     */
    public GroupingRuleTest() {
        LogManager.getRootLogger().setLevel(Level.FATAL);
    } // GroupingRuleTest
    
    /**
     * [Groupingrule.isValid] -------- fiware-servicePath field in a grouping rule must start with '/'.
     */
    @Test
    public void testFiwareServicePathStartsWithSlash() {
        System.out.println(getTestTraceHead("[GroupingRule.isValid]")
                + "-------- fiware-servicePath field in a grouping rule must start with '/'");
        JSONObject jsonRule = createJsonObject();
        
        try {
            assertEquals(0, GroupingRule.isValid(jsonRule, true));
            System.out.println(getTestTraceHead("[GroupingRule.isValid]")
                    + "-  OK  - The fiware-servicePath field in the rule '"
                    + jsonRule.toJSONString() + "' starts with '/'");
        } catch (AssertionError e) {
            System.out.println(getTestTraceHead("[GroupingRule.isValid]")
                    + "- FAIL - The fiware-servicePath field in the rule '"
                    + jsonRule.toJSONString() + "' does not start with '/'");
            throw e;
        } // try catch
    } // testFiwareServicePathStartsWithSlash
    
    /**
     * [Groupingrule.getXXXX] -------- Rule's attributes are not null.
     */
    @Test
    public void testIfGetsAreNotNull() {
        System.out.println(getTestTraceHead("[GroupingRule.getXXXX]")
                + "-------- Rule's attributes are not null");
        
        JSONObject jsonObject = createJsonObject();
        jsonObject.put("id", 1L);
        
        // Create the rule for doing the tests
        GroupingRule rule = new GroupingRule(jsonObject);
        
        try { 
            assertTrue(rule.getPattern() != null);
            System.out.println(getTestTraceHead("[GroupingRule.getPattern]")
                    + "-  OK  - Rule’s pattern is not null");
        } catch (AssertionError e) {
            System.out.println(getTestTraceHead("[GroupingRule.getPattern]")
                    + "- FAIL - Rule’s pattern is null");
            throw e;
        } // try catch
        
        try { 
            assertTrue(rule.getId() > 0L);
            System.out.println(getTestTraceHead("[GroupingRule.getId]")
                    + "-  OK  - Rule’s id is upper than 0");
        } catch (AssertionError e) {
            System.out.println(getTestTraceHead("[GroupingRule.getId]")
                    + "- FAIL - Rule’s id is invalid");
            throw e;
        } // try catch
{'fraction_non_alphanumeric': 0.1097452794322646, 'fraction_numerical': 0.0027879863135217334, 'mean_word_length': 2.291075896580484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1091138', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2168, 'n_words': 620}