mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
Unit tests for TPE package
This commit is contained in:
committed by
Dan Christian Bogos
parent
2629732de1
commit
01e24ed1e8
226
tpes/tpe_accounts_test.go
Normal file
226
tpes/tpe_accounts_test.go
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPAccounts(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetAccountDrvF: func(ctx *context.Context, str1 string, str2 string) (*utils.Account, error) {
|
||||
acc := &utils.Account{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Account_simple",
|
||||
Opts: map[string]interface{}{},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 12,
|
||||
},
|
||||
},
|
||||
Type: "*abstract",
|
||||
Opts: map[string]interface{}{
|
||||
"Destination": "10",
|
||||
},
|
||||
Units: utils.NewDecimal(0, 0),
|
||||
},
|
||||
},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
return acc, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPAccounts{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPAccounts(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsAccount(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpAcc := TPAccounts{
|
||||
dm: dm,
|
||||
}
|
||||
acc := &utils.Account{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Account_simple",
|
||||
Opts: map[string]interface{}{},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 12,
|
||||
},
|
||||
},
|
||||
Type: "*abstract",
|
||||
Opts: map[string]interface{}{
|
||||
"Destination": "10",
|
||||
},
|
||||
Units: utils.NewDecimal(0, 0),
|
||||
},
|
||||
},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
tpAcc.dm.SetAccount(context.Background(), acc, false)
|
||||
err = tpAcc.exportItems(context.Background(), wrtr, "cgrates.org", []string{"Account_simple"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// type mockWrtr struct {
|
||||
// io.Writer
|
||||
// }
|
||||
|
||||
// func (mockWrtr) Close() error { return utils.ErrNotImplemented }
|
||||
|
||||
// func TestTPEExportAccountHeaderError(t *testing.T) {
|
||||
// byteBuff := new(bytes.Buffer)
|
||||
// wrtr := mockWrtr{byteBuff}
|
||||
// cfg := config.NewDefaultCGRConfig()
|
||||
// connMng := engine.NewConnManager(cfg)
|
||||
// dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
// GetAccountDrvF: func(ctx *context.Context, str1 string, str2 string) (*utils.Account, error) {
|
||||
// acc := &utils.Account{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "Account_simple",
|
||||
// Opts: map[string]interface{}{},
|
||||
// Balances: map[string]*utils.Balance{
|
||||
// "VoiceBalance": {
|
||||
// ID: "VoiceBalance",
|
||||
// FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
// Weights: utils.DynamicWeights{
|
||||
// {
|
||||
// Weight: 12,
|
||||
// },
|
||||
// },
|
||||
// Type: "*abstract",
|
||||
// Opts: map[string]interface{}{
|
||||
// "Destination": "10",
|
||||
// },
|
||||
// Units: utils.NewDecimal(0, 0),
|
||||
// },
|
||||
// },
|
||||
// Weights: utils.DynamicWeights{
|
||||
// {
|
||||
// Weight: 10,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// return acc, nil
|
||||
// },
|
||||
// }, nil, connMng)
|
||||
// tpAcc := &TPAccounts{
|
||||
// dm: dm,
|
||||
// }
|
||||
// err := tpAcc.exportItems(context.Background(), wrtr, "cgrates.org", []string{"Accountt_simple"})
|
||||
// if err != nil {
|
||||
// t.Errorf("Expected nil\n but received %v", err)
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestTPEExportItemsAccountIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpAcc := TPAccounts{
|
||||
dm: dm,
|
||||
}
|
||||
acc := &utils.Account{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Account_complicated",
|
||||
Opts: map[string]interface{}{},
|
||||
Balances: map[string]*utils.Balance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 12,
|
||||
},
|
||||
},
|
||||
Type: "*abstract",
|
||||
Opts: map[string]interface{}{
|
||||
"Destination": "10",
|
||||
},
|
||||
Units: utils.NewDecimal(0, 0),
|
||||
},
|
||||
},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
tpAcc.dm.SetAccount(context.Background(), acc, false)
|
||||
err = tpAcc.exportItems(context.Background(), wrtr, "cgrates.net", []string{"Account_simple"})
|
||||
errExpect := "<NOT_FOUND> cannot find Account with id: <Account_simple>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
169
tpes/tpe_actions_test.go
Normal file
169
tpes/tpe_actions_test.go
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPActions(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetActionProfileDrvF: func(ctx *context.Context, tenant string, ID string) (*engine.ActionProfile, error) {
|
||||
act := &engine.ActionProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SET_BAL",
|
||||
FilterIDs: []string{
|
||||
"*string:~*req.Account:1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}},
|
||||
Schedule: utils.MetaASAP,
|
||||
Actions: []*engine.APAction{
|
||||
{
|
||||
ID: "SET_BAL",
|
||||
Type: utils.MetaSetBalance,
|
||||
Diktats: []*engine.APDiktat{
|
||||
{
|
||||
Path: "MONETARY",
|
||||
Value: "10",
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
return act, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPActions{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPActions(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsActions(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpAct := TPActions{
|
||||
dm: dm,
|
||||
}
|
||||
act := &engine.ActionProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SET_BAL",
|
||||
FilterIDs: []string{
|
||||
"*string:~*req.Account:1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}},
|
||||
Schedule: utils.MetaASAP,
|
||||
Actions: []*engine.APAction{
|
||||
{
|
||||
ID: "SET_BAL",
|
||||
Type: utils.MetaSetBalance,
|
||||
Diktats: []*engine.APDiktat{
|
||||
{
|
||||
Path: "MONETARY",
|
||||
Value: "10",
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
tpAct.dm.SetActionProfile(context.Background(), act, false)
|
||||
err = tpAct.exportItems(context.Background(), wrtr, "cgrates.org", []string{"SET_BAL"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsActionsIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpAct := TPActions{
|
||||
dm: dm,
|
||||
}
|
||||
act := &engine.ActionProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SET_BAL",
|
||||
FilterIDs: []string{
|
||||
"*string:~*req.Account:1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}},
|
||||
Schedule: utils.MetaASAP,
|
||||
Actions: []*engine.APAction{
|
||||
{
|
||||
ID: "SET_BAL",
|
||||
Type: utils.MetaSetBalance,
|
||||
Diktats: []*engine.APDiktat{
|
||||
{
|
||||
Path: "MONETARY",
|
||||
Value: "10",
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
tpAct.dm.SetActionProfile(context.Background(), act, false)
|
||||
err = tpAct.exportItems(context.Background(), wrtr, "cgrates.org", []string{"UNSET_BAL"})
|
||||
errExpect := "<NOT_FOUND> cannot find Actions id: <UNSET_BAL>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
163
tpes/tpe_attributes_test.go
Normal file
163
tpes/tpe_attributes_test.go
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPAttributes(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetAttributeProfileDrvF: func(ctx *context.Context, str1 string, str2 string) (*engine.AttributeProfile, error) {
|
||||
attr := &engine.AttributeProfile{
|
||||
Tenant: utils.CGRateSorg,
|
||||
ID: "TEST_ATTRIBUTES_TEST",
|
||||
FilterIDs: []string{"*string:~*req.Account:1002", "*exists:~*opts.*usage:"},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
Path: utils.AccountField,
|
||||
Type: utils.MetaConstant,
|
||||
Value: nil,
|
||||
},
|
||||
{
|
||||
Path: "*tenant",
|
||||
Type: utils.MetaConstant,
|
||||
Value: nil,
|
||||
},
|
||||
},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
}
|
||||
return attr, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPAttributes{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPAttributes(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsAttributes(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpAttr := TPAttributes{
|
||||
dm: dm,
|
||||
}
|
||||
attr := &engine.AttributeProfile{
|
||||
Tenant: utils.CGRateSorg,
|
||||
ID: "TEST_ATTRIBUTES_TEST",
|
||||
FilterIDs: []string{"*string:~*req.Account:1002", "*exists:~*opts.*usage:"},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
Path: utils.AccountField,
|
||||
Type: utils.MetaConstant,
|
||||
Value: nil,
|
||||
},
|
||||
{
|
||||
Path: "*tenant",
|
||||
Type: utils.MetaConstant,
|
||||
Value: nil,
|
||||
},
|
||||
},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
}
|
||||
tpAttr.dm.SetAttributeProfile(context.Background(), attr, false)
|
||||
err = tpAttr.exportItems(context.Background(), wrtr, "cgrates.org", []string{"TEST_ATTRIBUTES_TEST"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsAttributesIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpAct := TPAttributes{
|
||||
dm: dm,
|
||||
}
|
||||
attr := &engine.AttributeProfile{
|
||||
Tenant: utils.CGRateSorg,
|
||||
ID: "TEST_ATTRIBUTES_TEST",
|
||||
FilterIDs: []string{"*string:~*req.Account:1002", "*exists:~*opts.*usage:"},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
Path: utils.AccountField,
|
||||
Type: utils.MetaConstant,
|
||||
Value: nil,
|
||||
},
|
||||
{
|
||||
Path: "*tenant",
|
||||
Type: utils.MetaConstant,
|
||||
Value: nil,
|
||||
},
|
||||
},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
}
|
||||
tpAct.dm.SetAttributeProfile(context.Background(), attr, false)
|
||||
err = tpAct.exportItems(context.Background(), wrtr, "cgrates.org", []string{"TEST_ATTRIBUTES"})
|
||||
errExpect := "<NOT_FOUND> cannot find AttributeProfile with id: <TEST_ATTRIBUTES>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
130
tpes/tpe_chargers_test.go
Normal file
130
tpes/tpe_chargers_test.go
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPChargers(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetChargerProfileDrvF: func(ctx *context.Context, tnt, id string) (*engine.ChargerProfile, error) {
|
||||
chgr := &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Chargers1",
|
||||
RunID: utils.MetaDefault,
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
}
|
||||
return chgr, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPChargers{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPChargers(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsChargers(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpChgr := TPChargers{
|
||||
dm: dm,
|
||||
}
|
||||
chgr := &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Chargers1",
|
||||
RunID: utils.MetaDefault,
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
}
|
||||
tpChgr.dm.SetChargerProfile(context.Background(), chgr, false)
|
||||
err = tpChgr.exportItems(context.Background(), wrtr, "cgrates.org", []string{"Chargers1"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsChargersIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpChgr := TPChargers{
|
||||
dm: dm,
|
||||
}
|
||||
chgr := &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Chargers1",
|
||||
RunID: utils.MetaDefault,
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
}
|
||||
tpChgr.dm.SetChargerProfile(context.Background(), chgr, false)
|
||||
err = tpChgr.exportItems(context.Background(), wrtr, "cgrates.org", []string{"Chargers2"})
|
||||
errExpect := "<NOT_FOUND> cannot find ChargerProfile with id: <Chargers2>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
154
tpes/tpe_dispatchers_test.go
Normal file
154
tpes/tpe_dispatchers_test.go
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPDispatchers(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetDispatcherProfileDrvF: func(ctx *context.Context, str1 string, str2 string) (*engine.DispatcherProfile, error) {
|
||||
dsp := &engine.DispatcherProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Dsp1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z"},
|
||||
Strategy: utils.MetaFirst,
|
||||
StrategyParams: map[string]interface{}{
|
||||
utils.MetaDefaultRatio: "false",
|
||||
},
|
||||
Weight: 20,
|
||||
Hosts: engine.DispatcherHostProfiles{
|
||||
{
|
||||
ID: "C1",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
Params: map[string]interface{}{"0": "192.168.54.203"},
|
||||
Blocker: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
return dsp, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPDispatchers{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPDispatchers(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsDispatchers(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpDsp := TPDispatchers{
|
||||
dm: dm,
|
||||
}
|
||||
dsp := &engine.DispatcherProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Dsp1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z"},
|
||||
Strategy: utils.MetaFirst,
|
||||
StrategyParams: map[string]interface{}{
|
||||
utils.MetaDefaultRatio: "false",
|
||||
},
|
||||
Weight: 20,
|
||||
Hosts: engine.DispatcherHostProfiles{
|
||||
{
|
||||
ID: "C1",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
Params: map[string]interface{}{"0": "192.168.54.203"},
|
||||
Blocker: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
tpDsp.dm.SetDispatcherProfile(context.Background(), dsp, false)
|
||||
err = tpDsp.exportItems(context.Background(), wrtr, "cgrates.org", []string{"Dsp1"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsDispatchersIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpDsp := TPDispatchers{
|
||||
dm: dm,
|
||||
}
|
||||
dsp := &engine.DispatcherProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Dsp1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z"},
|
||||
Strategy: utils.MetaFirst,
|
||||
StrategyParams: map[string]interface{}{
|
||||
utils.MetaDefaultRatio: "false",
|
||||
},
|
||||
Weight: 20,
|
||||
Hosts: engine.DispatcherHostProfiles{
|
||||
{
|
||||
ID: "C1",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
Params: map[string]interface{}{"0": "192.168.54.203"},
|
||||
Blocker: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
tpDsp.dm.SetDispatcherProfile(context.Background(), dsp, false)
|
||||
err = tpDsp.exportItems(context.Background(), wrtr, "cgrates.org", []string{"Dsp2"})
|
||||
errExpect := "<NOT_FOUND> cannot find DispatcherProfile with id: <Dsp2>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
172
tpes/tpe_filters_test.go
Normal file
172
tpes/tpe_filters_test.go
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPFilters(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetFilterDrvF: func(ctx *context.Context, str1, str2 string) (*engine.Filter, error) {
|
||||
fltr := &engine.Filter{
|
||||
Tenant: utils.CGRateSorg,
|
||||
ID: "fltr_for_prf",
|
||||
Rules: []*engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Subject",
|
||||
Values: []string{"1004", "6774", "22312"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*opts.Subsystems",
|
||||
Values: []string{"*attributes"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "~*req.Destinations",
|
||||
Values: []string{"+0775", "+442"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaExists,
|
||||
Element: "~*req.NumberOfEvents",
|
||||
},
|
||||
},
|
||||
}
|
||||
return fltr, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPFilters{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPFilters(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsFilters(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpFltr := TPFilters{
|
||||
dm: dm,
|
||||
}
|
||||
fltr := &engine.Filter{
|
||||
Tenant: utils.CGRateSorg,
|
||||
ID: "fltr_for_prf",
|
||||
Rules: []*engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Subject",
|
||||
Values: []string{"1004", "6774", "22312"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*opts.Subsystems",
|
||||
Values: []string{"*attributes"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "~*req.Destinations",
|
||||
Values: []string{"+0775", "+442"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaExists,
|
||||
Element: "~*req.NumberOfEvents",
|
||||
},
|
||||
},
|
||||
}
|
||||
tpFltr.dm.SetFilter(context.Background(), fltr, false)
|
||||
err = tpFltr.exportItems(context.Background(), wrtr, "cgrates.org", []string{"fltr_for_prf"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsFiltersIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpFltr := TPFilters{
|
||||
dm: dm,
|
||||
}
|
||||
fltr := &engine.Filter{
|
||||
Tenant: utils.CGRateSorg,
|
||||
ID: "fltr_for_prf",
|
||||
Rules: []*engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Subject",
|
||||
Values: []string{"1004", "6774", "22312"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*opts.Subsystems",
|
||||
Values: []string{"*attributes"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "~*req.Destinations",
|
||||
Values: []string{"+0775", "+442"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaExists,
|
||||
Element: "~*req.NumberOfEvents",
|
||||
},
|
||||
},
|
||||
}
|
||||
tpFltr.dm.SetFilter(context.Background(), fltr, false)
|
||||
err = tpFltr.exportItems(context.Background(), wrtr, "cgrates.org", []string{"fltr_not_for_prf"})
|
||||
errExpect := "<NOT_FOUND> cannot find Filters with id: <fltr_not_for_prf>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
178
tpes/tpe_rates_test.go
Normal file
178
tpes/tpe_rates_test.go
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPRates(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetRateProfileDrvF: func(ctx *context.Context, str1, str2 string) (*utils.RateProfile, error) {
|
||||
rt := &utils.RateProfile{
|
||||
Tenant: utils.CGRateSorg,
|
||||
ID: "TEST_RATE_IT_TEST",
|
||||
FilterIDs: []string{"*string:~*req.Account:dan"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
MaxCostStrategy: "*free",
|
||||
Rates: map[string]*utils.Rate{
|
||||
"RT_WEEK": {
|
||||
ID: "RT_WEEK",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 0,
|
||||
},
|
||||
},
|
||||
ActivationTimes: "* * * * 1-5",
|
||||
IntervalRates: []*utils.IntervalRate{
|
||||
{
|
||||
IntervalStart: utils.NewDecimal(0, 0),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return rt, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPRates{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPRates(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsRates(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpRt := TPRates{
|
||||
dm: dm,
|
||||
}
|
||||
rt := &utils.RateProfile{
|
||||
Tenant: utils.CGRateSorg,
|
||||
ID: "TEST_RATE_TEST",
|
||||
FilterIDs: []string{"*string:~*req.Account:dan"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
MaxCostStrategy: "*free",
|
||||
Rates: map[string]*utils.Rate{
|
||||
"RT_WEEK": {
|
||||
ID: "RT_WEEK",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 0,
|
||||
},
|
||||
},
|
||||
ActivationTimes: "* * * * 1-5",
|
||||
IntervalRates: []*utils.IntervalRate{
|
||||
{
|
||||
IntervalStart: utils.NewDecimal(0, 0),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
tpRt.dm.SetRateProfile(context.Background(), rt, false, false)
|
||||
err = tpRt.exportItems(context.Background(), wrtr, "cgrates.org", []string{"TEST_RATE_TEST"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsRatesIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpRt := TPRates{
|
||||
dm: dm,
|
||||
}
|
||||
rt := &utils.RateProfile{
|
||||
Tenant: utils.CGRateSorg,
|
||||
ID: "TEST_RATE_TEST",
|
||||
FilterIDs: []string{"*string:~*req.Account:dan"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
MaxCostStrategy: "*free",
|
||||
Rates: map[string]*utils.Rate{
|
||||
"RT_WEEK": {
|
||||
ID: "RT_WEEK",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 0,
|
||||
},
|
||||
},
|
||||
ActivationTimes: "* * * * 1-5",
|
||||
IntervalRates: []*utils.IntervalRate{
|
||||
{
|
||||
IntervalStart: utils.NewDecimal(0, 0),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
tpRt.dm.SetRateProfileRates(context.Background(), rt, false)
|
||||
err = tpRt.exportItems(context.Background(), wrtr, "cgrates.org", []string{"TEST_RATE"})
|
||||
errExpect := "<NOT_FOUND> cannot find RateProfile with id: <TEST_RATE>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
133
tpes/tpe_resources_test.go
Normal file
133
tpes/tpe_resources_test.go
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPResources(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetResourceProfileDrvF: func(ctx *context.Context, tnt string, id string) (*engine.ResourceProfile, error) {
|
||||
rsc := &engine.ResourceProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ResGroup1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Limit: 10,
|
||||
AllocationMessage: "Approved",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
}},
|
||||
ThresholdIDs: []string{utils.MetaNone},
|
||||
}
|
||||
return rsc, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPResources{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPResources(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsResources(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpRsc := TPResources{
|
||||
dm: dm,
|
||||
}
|
||||
rsc := &engine.ResourceProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ResGroup1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Limit: 10,
|
||||
AllocationMessage: "Approved",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
}},
|
||||
ThresholdIDs: []string{utils.MetaNone},
|
||||
}
|
||||
tpRsc.dm.SetResourceProfile(context.Background(), rsc, false)
|
||||
err = tpRsc.exportItems(context.Background(), wrtr, "cgrates.org", []string{"ResGroup1"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsResourcesIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpRsc := TPResources{
|
||||
dm: dm,
|
||||
}
|
||||
rsc := &engine.ResourceProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ResGroup1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Limit: 10,
|
||||
AllocationMessage: "Approved",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
}},
|
||||
ThresholdIDs: []string{utils.MetaNone},
|
||||
}
|
||||
tpRsc.dm.SetResourceProfile(context.Background(), rsc, false)
|
||||
err = tpRsc.exportItems(context.Background(), wrtr, "cgrates.org", []string{"ResGroup2"})
|
||||
errExpect := "<NOT_FOUND> cannot find ResourceProfile with id: <ResGroup2>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
160
tpes/tpe_routes_test.go
Normal file
160
tpes/tpe_routes_test.go
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPRoutes(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetRouteProfileDrvF: func(ctx *context.Context, tnt string, id string) (*engine.RouteProfile, error) {
|
||||
rte := &engine.RouteProfile{
|
||||
ID: "ROUTE_2003",
|
||||
Tenant: "cgrates.org",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Sorting: utils.MetaWeight,
|
||||
SortingParameters: []string{},
|
||||
Routes: []*engine.Route{
|
||||
{
|
||||
ID: "route1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return rte, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPRoutes{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPRoutes(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportRoutes(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpRte := TPRoutes{
|
||||
dm: dm,
|
||||
}
|
||||
rte := &engine.RouteProfile{
|
||||
ID: "ROUTE_2003",
|
||||
Tenant: "cgrates.org",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Sorting: utils.MetaWeight,
|
||||
SortingParameters: []string{},
|
||||
Routes: []*engine.Route{
|
||||
{
|
||||
ID: "route1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
tpRte.dm.SetRouteProfile(context.Background(), rte, false)
|
||||
err = tpRte.exportItems(context.Background(), wrtr, "cgrates.org", []string{"ROUTE_2003"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsRoutesIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpRte := TPRoutes{
|
||||
dm: dm,
|
||||
}
|
||||
rte := &engine.RouteProfile{
|
||||
ID: "ROUTE_2003",
|
||||
Tenant: "cgrates.org",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Sorting: utils.MetaWeight,
|
||||
SortingParameters: []string{},
|
||||
Routes: []*engine.Route{
|
||||
{
|
||||
ID: "route1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
tpRte.dm.SetRouteProfile(context.Background(), rte, false)
|
||||
err = tpRte.exportItems(context.Background(), wrtr, "cgrates.org", []string{"ROUTE_2004"})
|
||||
errExpect := "<NOT_FOUND> cannot find RouteProfile with id: <ROUTE_2004>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
181
tpes/tpe_stats_test.go
Normal file
181
tpes/tpe_stats_test.go
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPStats(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetStatQueueProfileDrvF: func(ctx *context.Context, tnt string, id string) (*engine.StatQueueProfile, error) {
|
||||
stq := &engine.StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SQ_2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
QueueLength: 14,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
{
|
||||
MetricID: utils.MetaASR,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaPDD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCC,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{utils.MetaNone},
|
||||
}
|
||||
return stq, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPStats{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPStats(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportStats(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpStq := TPStats{
|
||||
dm: dm,
|
||||
}
|
||||
stq := &engine.StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SQ_2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
QueueLength: 14,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
{
|
||||
MetricID: utils.MetaASR,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaPDD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCC,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{utils.MetaNone},
|
||||
}
|
||||
tpStq.dm.SetStatQueueProfile(context.Background(), stq, false)
|
||||
err = tpStq.exportItems(context.Background(), wrtr, "cgrates.org", []string{"SQ_2"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsStatsIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpStq := TPStats{
|
||||
dm: dm,
|
||||
}
|
||||
stq := &engine.StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SQ_2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
QueueLength: 14,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
{
|
||||
MetricID: utils.MetaASR,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaPDD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCC,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{utils.MetaNone},
|
||||
}
|
||||
tpStq.dm.SetStatQueueProfile(context.Background(), stq, false)
|
||||
err = tpStq.exportItems(context.Background(), wrtr, "cgrates.org", []string{"SQ_3"})
|
||||
errExpect := "<NOT_FOUND> cannot find StatQueueProfile with id: <SQ_3>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func (tpThd TPThresholds) exportItems(ctx *context.Context, wrtr io.Writer, tnt
|
||||
thdPrf, err = tpThd.dm.GetThresholdProfile(ctx, tnt, thdID, true, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
if err.Error() == utils.ErrNotFound.Error() {
|
||||
return fmt.Errorf("<%s> cannot find Actions id: <%v>", err, thdID)
|
||||
return fmt.Errorf("<%s> cannot find ThresholdProfile with id: <%v>", err, thdID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
139
tpes/tpe_thresholds_test.go
Normal file
139
tpes/tpe_thresholds_test.go
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTPEnewTPThresholds(t *testing.T) {
|
||||
// dataDB := &engine.DataDBM
|
||||
// dm := &engine.NewDataManager()
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetThresholdProfileDrvF: func(ctx *context.Context, tnt string, id string) (*engine.ThresholdProfile, error) {
|
||||
thd := &engine.ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "THD_2",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
ActionProfileIDs: []string{"actPrfID"},
|
||||
MaxHits: 7,
|
||||
MinHits: 0,
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
Async: true,
|
||||
}
|
||||
return thd, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
exp := &TPThresholds{
|
||||
dm: dm,
|
||||
}
|
||||
rcv := newTPThresholds(dm)
|
||||
if rcv.dm != exp.dm {
|
||||
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportThresholds(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpThd := TPThresholds{
|
||||
dm: dm,
|
||||
}
|
||||
thd := &engine.ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "THD_2",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
ActionProfileIDs: []string{"actPrfID"},
|
||||
MaxHits: 7,
|
||||
MinHits: 0,
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
Async: true,
|
||||
}
|
||||
tpThd.dm.SetThresholdProfile(context.Background(), thd, false)
|
||||
err = tpThd.exportItems(context.Background(), wrtr, "cgrates.org", []string{"THD_2"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil\n but received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPEExportItemsThresholdsIDNotFound(t *testing.T) {
|
||||
wrtr := new(bytes.Buffer)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
connMng := engine.NewConnManager(cfg)
|
||||
dataDB, err := engine.NewDataDBConn(cfg.DataDbCfg().Type,
|
||||
cfg.DataDbCfg().Host, cfg.DataDbCfg().Port,
|
||||
cfg.DataDbCfg().Name, cfg.DataDbCfg().User,
|
||||
cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer dataDB.Close()
|
||||
dm := engine.NewDataManager(dataDB, config.CgrConfig().CacheCfg(), connMng)
|
||||
tpThd := TPThresholds{
|
||||
dm: dm,
|
||||
}
|
||||
thd := &engine.ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "THD_2",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
ActionProfileIDs: []string{"actPrfID"},
|
||||
MaxHits: 7,
|
||||
MinHits: 0,
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
Async: true,
|
||||
}
|
||||
tpThd.dm.SetThresholdProfile(context.Background(), thd, false)
|
||||
err = tpThd.exportItems(context.Background(), wrtr, "cgrates.org", []string{"THD_3"})
|
||||
errExpect := "<NOT_FOUND> cannot find ThresholdProfile with id: <THD_3>"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
167
tpes/tpexporter_test.go
Normal file
167
tpes/tpexporter_test.go
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestNewTPExporter(t *testing.T) {
|
||||
// Attributes
|
||||
rcv, err := newTPExporter(utils.MetaAttributes, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expAttr := &TPAttributes{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expAttr) {
|
||||
t.Errorf("Expected %v\n but received %v", expAttr, rcv)
|
||||
}
|
||||
|
||||
//Resources
|
||||
rcv, err = newTPExporter(utils.MetaResources, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expRsc := &TPResources{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expRsc) {
|
||||
t.Errorf("Expected %v\n but received %v", expRsc, rcv)
|
||||
}
|
||||
|
||||
//Filters
|
||||
rcv, err = newTPExporter(utils.MetaFilters, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expFltr := &TPFilters{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expFltr) {
|
||||
t.Errorf("Expected %v\n but received %v", expFltr, rcv)
|
||||
}
|
||||
|
||||
//Rates
|
||||
rcv, err = newTPExporter(utils.MetaRateS, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expRt := &TPRates{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expRt) {
|
||||
t.Errorf("Expected %v\n but received %v", expRt, rcv)
|
||||
}
|
||||
|
||||
//Chargers
|
||||
rcv, err = newTPExporter(utils.MetaChargers, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expChg := &TPChargers{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expChg) {
|
||||
t.Errorf("Expected %v\n but received %v", expChg, rcv)
|
||||
}
|
||||
|
||||
//Routes
|
||||
rcv, err = newTPExporter(utils.MetaRoutes, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expRts := &TPRoutes{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expRts) {
|
||||
t.Errorf("Expected %v\n but received %v", expRts, rcv)
|
||||
}
|
||||
|
||||
//Accounts
|
||||
rcv, err = newTPExporter(utils.MetaAccounts, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expAcc := &TPAccounts{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expAcc) {
|
||||
t.Errorf("Expected %v\n but received %v", expAcc, rcv)
|
||||
}
|
||||
|
||||
//Stats
|
||||
rcv, err = newTPExporter(utils.MetaStats, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expSt := &TPStats{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expSt) {
|
||||
t.Errorf("Expected %v\n but received %v", expSt, rcv)
|
||||
}
|
||||
|
||||
//Actions
|
||||
rcv, err = newTPExporter(utils.MetaActions, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expAct := &TPActions{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expAct) {
|
||||
t.Errorf("Expected %v\n but received %v", expAct, rcv)
|
||||
}
|
||||
|
||||
//Thresholds
|
||||
rcv, err = newTPExporter(utils.MetaThresholds, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expThd := &TPThresholds{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expThd) {
|
||||
t.Errorf("Expected %v\n but received %v", expThd, rcv)
|
||||
}
|
||||
|
||||
//Dispatchers
|
||||
rcv, err = newTPExporter(utils.MetaDispatchers, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expDsp := &TPDispatchers{
|
||||
dm: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(rcv, expDsp) {
|
||||
t.Errorf("Expected %v\n but received %v", expDsp, rcv)
|
||||
}
|
||||
|
||||
//Unsupported type
|
||||
_, err = newTPExporter("does not exist", nil)
|
||||
errExpect := "UNSUPPORTED_TPEXPORTER_TYPE:does not exist"
|
||||
if err.Error() != errExpect {
|
||||
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user