/**
 * 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.utils;

import com.google.gson.Gson;
import com.telefonica.iot.cygnus.containers.NotifyContextRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

/**
 *
 * @author frb
 */
public final class TestUtils {
    
    private static final int MAX_LEN_TEST_TRACE_HEAD = 40;
    
    /**
     * Constructor. It is private since utility clasess should not have a public or default constructor.
     */
    private TestUtils() {
    } // TestUtils
    
    /**
     * Create a Json-based notificationContextRequest given the string representation of such Json.
     * @param jsonStr
     * @return The Json-based notificationContextRequest
     */
    public static NotifyContextRequest createJsonNotifyContextRequest(String jsonStr) {
        Logger logger = Logger.getLogger(Utils.class);
        NotifyContextRequest notification = null;
        Gson gson = new Gson();

        try {
            notification = gson.fromJson(jsonStr, NotifyContextRequest.class);
        } catch (Exception e) {
            logger.error(e.getMessage());
        } // try catch
        
        return notification;
    } // createJsonNotifyContextRequest
    
    /**
     * Gets a trace head.
     * @param originalHead
     * @return A trace head
     */
    public static String getTestTraceHead(String originalHead) {
        String traceHead = originalHead;
        traceHead += " " + StringUtils.repeat("-", MAX_LEN_TEST_TRACE_HEAD - originalHead.length());
        return traceHead;
    } // getTestTraceHead
} // TestUtils

@@ -1044,16 +1044,64 @@
 equest;%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A
 import o
@@ -1158,20 +1158,164 @@
 che.
-log4j.Logger
+flume.Event;%0Aimport org.apache.flume.event.EventBuilder;%0Aimport org.apache.log4j.Logger;%0Aimport org.json.simple.JSONArray;%0Aimport org.json.simple.JSONObject
 ;%0A%0A/
@@ -2660,16 +2660,1810 @@
 aceHead%0A
+    %0A    public static Event createEvent() %7B%0A        String eventData = createNotification().toJSONString();%0A        Map%3CString, String%3E eventHeaders = new HashMap%3CString, String%3E();%0A        eventHeaders.put(%22fiware-service%22, %22default%22);%0A        eventHeaders.put(%22fiware-servicepath%22, %22/%22);%0A        eventHeaders.put(%22fiware-correlator%22, %220123456789ABCDEF%22);%0A        eventHeaders.put(%22transaction-id%22, %220123456789ABCDEF%22);%0A        return EventBuilder.withBody(eventData.getBytes(), eventHeaders);%0A    %7D // createEvent%0A    %0A    public static JSONObject createNotification() %7B%0A        JSONObject attribute = new JSONObject();%0A        attribute.put(%22name%22, %22temperature%22);%0A        attribute.put(%22type%22, %22centigrade%22);%0A        attribute.put(%22value%22, %2226.5%22);%0A        JSONArray attributes = new JSONArray();%0A        attributes.add(attribute);%0A        JSONObject contextElement = new JSONObject();%0A        contextElement.put(%22attributes%22, attributes);%0A        contextElement.put(%22type%22, %22Room%22);%0A        contextElement.put(%22isPattern%22, %22false%22);%0A        contextElement.put(%22id%22, %22room1%22);%0A        JSONObject statusCode = new JSONObject();%0A        statusCode.put(%22code%22, %22200%22);%0A        statusCode.put(%22reasonPhrase%22, %22OK%22);%0A        JSONObject contextResponse = new JSONObject();%0A        contextResponse.put(%22contextElement%22, contextElement);%0A        contextResponse.put(%22statusCode%22, statusCode);%0A        JSONArray contextResponses = new JSONArray();%0A        contextResponses.add(contextResponse);%0A        JSONObject notification = new JSONObject();%0A        notification.put(%22subscriptionId%22, %2251c0ac9ed714fb3b37d7d5a8%22);%0A        notification.put(%22originator%22, %22localhost%22);%0A        notification.put(%22contextResponses%22, contextResponses);%0A        return notification;%0A    %7D // createNotification%0A    %0A
 %7D // Tes

ADD several utility functions for testing