From 9e3e65f9e6afa952edbe418dcbdb95c9e7d7ed43 Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 6 Dec 2017 17:21:59 +0200 Subject: [PATCH] Add test for ExternalAliasProfile -> AliasProfine and reverse --- engine/alias_it_test.go | 107 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 engine/alias_it_test.go diff --git a/engine/alias_it_test.go b/engine/alias_it_test.go new file mode 100644 index 000000000..12b2ddf82 --- /dev/null +++ b/engine/alias_it_test.go @@ -0,0 +1,107 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +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 engine + +import ( + "reflect" + "testing" + "time" + + "github.com/cgrates/cgrates/utils" +) + +func TestExternalAliasProfileAsAliasProfile(t *testing.T) { + extAls := &ExternalAliasProfile{ + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), + ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), + }, + Aliases: []*AliasEntry{ + &AliasEntry{ + FieldName: "FL1", + Initial: "In1", + Alias: "Al1", + }, + }, + Weight: 20, + } + alsMap := make(map[string]map[string]string) + alsMap["FL1"] = make(map[string]string) + alsMap["FL1"]["In1"] = "Al1" + expected := &AliasProfile{ + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), + ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), + }, + Aliases: alsMap, + Weight: 20, + } + + rcv := extAls.AsAliasProfile() + if !reflect.DeepEqual(expected, rcv) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv)) + } +} + +func TestNewExternalAliasProfileFromAliasProfile(t *testing.T) { + alsMap := make(map[string]map[string]string) + alsMap["FL1"] = make(map[string]string) + alsMap["FL1"]["In1"] = "Al1" + alsPrf := &AliasProfile{ + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), + ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), + }, + Aliases: alsMap, + Weight: 20, + } + + expected := &ExternalAliasProfile{ + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), + ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), + }, + Aliases: []*AliasEntry{ + &AliasEntry{ + FieldName: "FL1", + Initial: "In1", + Alias: "Al1", + }, + }, + Weight: 20, + } + + rcv := NewExternalAliasProfileFromAliasProfile(alsPrf) + if !reflect.DeepEqual(expected, rcv) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv)) + } + +}