diff --git a/tpes/tpe_accounts_test.go b/tpes/tpe_accounts_test.go
new file mode 100644
index 000000000..7748bf1df
--- /dev/null
+++ b/tpes/tpe_accounts_test.go
@@ -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
+*/
+
+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 := " cannot find Account with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_actions_test.go b/tpes/tpe_actions_test.go
new file mode 100644
index 000000000..550616476
--- /dev/null
+++ b/tpes/tpe_actions_test.go
@@ -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
+*/
+
+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 := " cannot find Actions id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_attributes_test.go b/tpes/tpe_attributes_test.go
new file mode 100644
index 000000000..d28a07b8c
--- /dev/null
+++ b/tpes/tpe_attributes_test.go
@@ -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
+*/
+
+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 := " cannot find AttributeProfile with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_chargers_test.go b/tpes/tpe_chargers_test.go
new file mode 100644
index 000000000..a30034951
--- /dev/null
+++ b/tpes/tpe_chargers_test.go
@@ -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
+*/
+
+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 := " cannot find ChargerProfile with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_dispatchers_test.go b/tpes/tpe_dispatchers_test.go
new file mode 100644
index 000000000..b94e0cc1e
--- /dev/null
+++ b/tpes/tpe_dispatchers_test.go
@@ -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
+*/
+
+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 := " cannot find DispatcherProfile with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_filters_test.go b/tpes/tpe_filters_test.go
new file mode 100644
index 000000000..6e4f8fa1b
--- /dev/null
+++ b/tpes/tpe_filters_test.go
@@ -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
+*/
+
+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 := " cannot find Filters with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_rates_test.go b/tpes/tpe_rates_test.go
new file mode 100644
index 000000000..6fe5b34f6
--- /dev/null
+++ b/tpes/tpe_rates_test.go
@@ -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
+*/
+
+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 := " cannot find RateProfile with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_resources_test.go b/tpes/tpe_resources_test.go
new file mode 100644
index 000000000..ebd424751
--- /dev/null
+++ b/tpes/tpe_resources_test.go
@@ -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
+*/
+
+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 := " cannot find ResourceProfile with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_routes_test.go b/tpes/tpe_routes_test.go
new file mode 100644
index 000000000..df1bddb44
--- /dev/null
+++ b/tpes/tpe_routes_test.go
@@ -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
+*/
+
+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 := " cannot find RouteProfile with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_stats_test.go b/tpes/tpe_stats_test.go
new file mode 100644
index 000000000..b03bdb5e6
--- /dev/null
+++ b/tpes/tpe_stats_test.go
@@ -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
+*/
+
+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 := " cannot find StatQueueProfile with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpe_thresholds.go b/tpes/tpe_thresholds.go
index 58feb35d9..d773011a7 100644
--- a/tpes/tpe_thresholds.go
+++ b/tpes/tpe_thresholds.go
@@ -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
}
diff --git a/tpes/tpe_thresholds_test.go b/tpes/tpe_thresholds_test.go
new file mode 100644
index 000000000..2536cc6a6
--- /dev/null
+++ b/tpes/tpe_thresholds_test.go
@@ -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
+*/
+
+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 := " cannot find ThresholdProfile with id: "
+ if err.Error() != errExpect {
+ t.Errorf("Expected %v\n but received %v", errExpect, err)
+ }
+}
diff --git a/tpes/tpexporter_test.go b/tpes/tpexporter_test.go
new file mode 100644
index 000000000..7393e1e6a
--- /dev/null
+++ b/tpes/tpexporter_test.go
@@ -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
+*/
+
+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)
+ }
+}