destination management tests

This commit is contained in:
Radu Ioan Fericean
2016-05-06 16:22:45 +03:00
parent 85bb46cac6
commit eece1ba3ad
6 changed files with 319 additions and 0 deletions

65
console/destinations.go Normal file
View File

@@ -0,0 +1,65 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012-2015 ITsysCOM
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package console
import (
"github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/engine"
)
func init() {
c := &CmdGetDestination{
name: "destinations",
rpcMethod: "ApierV2.GetDestinations",
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetDestination struct {
name string
rpcMethod string
rpcParams *v2.AttrGetDestinations
*CommandExecuter
}
func (self *CmdGetDestination) Name() string {
return self.name
}
func (self *CmdGetDestination) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetDestination) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v2.AttrGetDestinations{}
}
return self.rpcParams
}
func (self *CmdGetDestination) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetDestination) RpcResult() interface{} {
a := make([]*engine.Destination, 0)
return &a
}

View File

@@ -0,0 +1,13 @@
#Tag,Prefix
GERMANY,+49
GERMANY_MOBILE,+4915
GERMANY_MOBILE,+4916
GERMANY_MOBILE,+4917
DATA_DEST,222
ROMANIA,+40
ROMANIA_MOBILE,+4072
ROMANIA_MOBILE,+4073
ROMANIA_MOBILE,+4074
ROMANIA_MOBILE,+4072
EUROPE,+40
EUROPE,+49
1 #Tag Prefix
2 GERMANY +49
3 GERMANY_MOBILE +4915
4 GERMANY_MOBILE +4916
5 GERMANY_MOBILE +4917
6 DATA_DEST 222
7 ROMANIA +40
8 ROMANIA_MOBILE +4072
9 ROMANIA_MOBILE +4073
10 ROMANIA_MOBILE +4074
11 ROMANIA_MOBILE +4072
12 EUROPE +40
13 EUROPE +49

View File

@@ -0,0 +1,15 @@
#Tag,Prefix
GERMANY,+49
GERMANY_MOBILE,+4915
GERMANY_MOBILE,+4916
GERMANY_MOBILE,+4917
DATA_DEST,222
ROMANIA,+40
ROMANIA_MOBILE,+4072
ROMANIA_MOBILE,+4073
ROMANIA_MOBILE,+4074
ROMANIA_MOBILE,+4072
HUNGARY,+36
EUROPE,+40
EUROPE,+49
EUROPE,+36
1 #Tag Prefix
2 GERMANY +49
3 GERMANY_MOBILE +4915
4 GERMANY_MOBILE +4916
5 GERMANY_MOBILE +4917
6 DATA_DEST 222
7 ROMANIA +40
8 ROMANIA_MOBILE +4072
9 ROMANIA_MOBILE +4073
10 ROMANIA_MOBILE +4074
11 ROMANIA_MOBILE +4072
12 HUNGARY +36
13 EUROPE +40
14 EUROPE +49
15 EUROPE +36

View File

@@ -0,0 +1,13 @@
#Tag,Prefix
GERMANY,+49
GERMANY_MOBILE,+4915
GERMANY_MOBILE,+4916
GERMANY_MOBILE,+4917
DATA_DEST,222
ROMANIA,+40
ROMANIA_MOBILE,+4072
ROMANIA_MOBILE,+4073
ROMANIA_MOBILE,+4074
ROMANIA_MOBILE,+4072
EUROPE,+40
EUROPE,+49
1 #Tag Prefix
2 GERMANY +49
3 GERMANY_MOBILE +4915
4 GERMANY_MOBILE +4916
5 GERMANY_MOBILE +4917
6 DATA_DEST 222
7 ROMANIA +40
8 ROMANIA_MOBILE +4072
9 ROMANIA_MOBILE +4073
10 ROMANIA_MOBILE +4074
11 ROMANIA_MOBILE +4072
12 EUROPE +40
13 EUROPE +49

View File

@@ -0,0 +1,8 @@
#Tag,Prefix
GERMANY,+49
GERMANY_MOBILE,+4915
GERMANY_MOBILE,+4916
GERMANY_MOBILE,+4917
DATA_DEST,222
EUROPE,+40
EUROPE,+49
1 #Tag Prefix
2 GERMANY +49
3 GERMANY_MOBILE +4915
4 GERMANY_MOBILE +4916
5 GERMANY_MOBILE +4917
6 DATA_DEST 222
7 EUROPE +40
8 EUROPE +49

View File

@@ -0,0 +1,205 @@
package general_tests
import (
"net/rpc"
"net/rpc/jsonrpc"
"path"
"testing"
"time"
"github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var destCfgPath string
var destCfg *config.CGRConfig
var destRPC *rpc.Client
var destLoadInst engine.LoadInstance // Share load information between tests
func TestDestManagInitCfg(t *testing.T) {
if !*testIntegration {
return
}
destCfgPath = path.Join(*dataDir, "conf", "samples", "tutlocal")
// Init config first
var err error
destCfg, err = config.NewCGRConfigFromFolder(destCfgPath)
if err != nil {
t.Error(err)
}
destCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(destCfg)
}
// Remove data in both rating and accounting db
func TestDestManagResetDataDb(t *testing.T) {
if !*testIntegration {
return
}
if err := engine.InitDataDb(destCfg); err != nil {
t.Fatal(err)
}
}
// Wipe out the cdr database
func TestDestManagResetStorDb(t *testing.T) {
if !*testIntegration {
return
}
if err := engine.InitStorDb(destCfg); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func TestDestManagStartEngine(t *testing.T) {
if !*testIntegration {
return
}
if _, err := engine.StopStartEngine(destCfgPath, *waitRater); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func TestDestManagRpcConn(t *testing.T) {
if !*testIntegration {
return
}
var err error
destRPC, err = jsonrpc.Dial("tcp", destCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal(err)
}
}
// Load the tariff plan, creating accounts and their balances
func TestDestManagLoadTariffPlanFromFolderAll(t *testing.T) {
if !*testIntegration {
return
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "alldests")}
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.LoadId == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
func TestDestManagAllDestinationLoaded(t *testing.T) {
if !*testIntegration {
return
}
dests := make([]*engine.Destination, 0)
if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil {
t.Error("Got error on ApierV2.GetDestinations: ", err.Error())
} else if len(dests) != 6 {
t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests))
}
var rcvStats utils.CacheStats
if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil {
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
} else if rcvStats.Destinations != 9 {
t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats)
}
}
func TestDestManagLoadTariffPlanFromFolderRemoveSome(t *testing.T) {
if !*testIntegration {
return
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "removesome")}
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.LoadId == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
func TestDestManagRemoveSomeDestinationLoaded(t *testing.T) {
if !*testIntegration {
return
}
dests := make([]*engine.Destination, 0)
if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil {
t.Error("Got error on ApierV2.GetDestinations: ", err.Error())
} else if len(dests) != 6 {
t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests))
}
var rcvStats utils.CacheStats
if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil {
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
} else if rcvStats.Destinations != 9 {
t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats)
}
}
func TestDestManagLoadTariffPlanFromFolderAddBack(t *testing.T) {
if !*testIntegration {
return
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "addback")}
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.LoadId == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
func TestDestManagAddBackDestinationLoaded(t *testing.T) {
if !*testIntegration {
return
}
dests := make([]*engine.Destination, 0)
if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil {
t.Error("Got error on ApierV2.GetDestinations: ", err.Error())
} else if len(dests) != 6 {
t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests))
}
var rcvStats utils.CacheStats
if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil {
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
} else if rcvStats.Destinations != 9 {
t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats)
}
}
func TestDestManagLoadTariffPlanFromFolderAddOne(t *testing.T) {
if !*testIntegration {
return
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "addone")}
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.LoadId == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
func TestDestManagAddOneDestinationLoaded(t *testing.T) {
if !*testIntegration {
return
}
dests := make([]*engine.Destination, 0)
if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil {
t.Error("Got error on ApierV2.GetDestinations: ", err.Error())
} else if len(dests) != 7 {
t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests))
}
var rcvStats utils.CacheStats
if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil {
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
} else if rcvStats.Destinations != 10 {
t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats)
}
}