/* Rating system designed to be used in VoIP Carriers World Copyright (C) 2013 ITsysCOM This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see */ package sessionmanager import ( "github.com/cgrates/cgrates/config" "testing" "time" ) func TestEventCreation(t *testing.T) { body := `Event-Name: RE_SCHEDULE Core-UUID: 792e181c-b6e6-499c-82a1-52a778e7d82d FreeSWITCH-Hostname: h1.ip-switch.net FreeSWITCH-Switchname: h1.ip-switch.net FreeSWITCH-IPv4: 88.198.12.156 FreeSWITCH-IPv6: %3A%3A1 Event-Date-Local: 2012-10-05%2013%3A41%3A38 Event-Date-GMT: Fri,%2005%20Oct%202012%2011%3A41%3A38%20GMT Event-Date-Timestamp: 1349437298012866 Event-Calling-File: switch_scheduler.c Event-Calling-Function: switch_scheduler_execute Event-Calling-Line-Number: 65 Event-Sequence: 34263 Task-ID: 2 Task-Desc: heartbeat Task-Group: core Task-Runtime: 1349437318` ev := new(FSEvent).New(body) if ev.GetName() != "RE_SCHEDULE" { t.Error("Event not parsed correctly: ", ev) } l := len(ev.(FSEvent)) if l != 17 { t.Error("Incorrect number of event fields: ", l) } } // Detects if any of the parsers do not return static values func TestEventParseStatic(t *testing.T) { ev := new(FSEvent).New("") setupTime, _ := ev.GetSetupTime("^2013-12-07 08:42:24") answerTime, _ := ev.GetAnswerTime("^2013-12-07 08:42:24") dur, _ := ev.GetDuration("^60s") if ev.GetReqType("^test") != "test" || ev.GetDirection("^test") != "test" || ev.GetTenant("^test") != "test" || ev.GetTOR("^test") != "test" || ev.GetAccount("^test") != "test" || ev.GetSubject("^test") != "test" || ev.GetDestination("^test") != "test" || setupTime != time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC) || answerTime != time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC) || dur != time.Duration(60)*time.Second { t.Error("Values out of static not matching", ev.GetReqType("^test") != "test", ev.GetDirection("^test") != "test", ev.GetTenant("^test") != "test", ev.GetTOR("^test") != "test", ev.GetAccount("^test") != "test", ev.GetSubject("^test") != "test", ev.GetDestination("^test") != "test", setupTime != time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC), answerTime != time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC), dur != time.Duration(60)*time.Second) } } // Test here if the answer is selected out of headers we specify, even if not default defined func TestEventSelectiveHeaders(t *testing.T) { body := `Event-Name: RE_SCHEDULE Core-UUID: 792e181c-b6e6-499c-82a1-52a778e7d82d FreeSWITCH-Hostname: h1.ip-switch.net FreeSWITCH-Switchname: h1.ip-switch.net FreeSWITCH-IPv4: 88.198.12.156 FreeSWITCH-IPv6: %3A%3A1 Event-Date-Local: 2012-10-05%2013%3A41%3A38 Event-Date-GMT: Fri,%2005%20Oct%202012%2011%3A41%3A38%20GMT Event-Date-Timestamp: 1349437298012866 Event-Calling-File: switch_scheduler.c Event-Calling-Function: switch_scheduler_execute Event-Calling-Line-Number: 65 Event-Sequence: 34263 Task-ID: 2 Task-Desc: heartbeat Task-Group: core Task-Runtime: 1349437318` cfg, _ = config.NewDefaultCGRConfig() config.SetCgrConfig(cfg) ev := new(FSEvent).New(body) setupTime, _ := ev.GetSetupTime("Event-Date-Local") answerTime, _ := ev.GetAnswerTime("Event-Date-Local") dur, _ := ev.GetDuration("Event-Calling-Line-Number") if ev.GetReqType("FreeSWITCH-Hostname") != "h1.ip-switch.net" || ev.GetDirection("FreeSWITCH-Hostname") != "*out" || ev.GetTenant("FreeSWITCH-Hostname") != "h1.ip-switch.net" || ev.GetTOR("FreeSWITCH-Hostname") != "h1.ip-switch.net" || ev.GetAccount("FreeSWITCH-Hostname") != "h1.ip-switch.net" || ev.GetSubject("FreeSWITCH-Hostname") != "h1.ip-switch.net" || ev.GetDestination("FreeSWITCH-Hostname") != "h1.ip-switch.net" || setupTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC) || answerTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC) || dur != time.Duration(65)*time.Second { t.Error("Values out of static not matching", ev.GetReqType("FreeSWITCH-Hostname") != "h1.ip-switch.net", ev.GetDirection("FreeSWITCH-Hostname") != "*out", ev.GetTenant("FreeSWITCH-Hostname") != "h1.ip-switch.net", ev.GetTOR("FreeSWITCH-Hostname") != "h1.ip-switch.net", ev.GetAccount("FreeSWITCH-Hostname") != "h1.ip-switch.net", ev.GetSubject("FreeSWITCH-Hostname") != "h1.ip-switch.net", ev.GetDestination("FreeSWITCH-Hostname") != "h1.ip-switch.net", setupTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC), answerTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC), dur != time.Duration(65)*time.Second) } }