diff --git a/apier/v1/tpresources_it_test.go b/apier/v1/tpresources_it_test.go
index d257cc8d9..97190a87e 100644
--- a/apier/v1/tpresources_it_test.go
+++ b/apier/v1/tpresources_it_test.go
@@ -17,6 +17,7 @@ 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 v1
import (
diff --git a/apier/v1/tpsharedgroups.go b/apier/v1/tpsharedgroups.go
index 049ccbad3..26743e71f 100644
--- a/apier/v1/tpsharedgroups.go
+++ b/apier/v1/tpsharedgroups.go
@@ -45,9 +45,10 @@ func (self *ApierV1) GetTPSharedGroups(attrs AttrGetTPSharedGroups, reply *utils
return utils.NewErrMandatoryIeMissing(missing...)
}
if sgs, err := self.StorDb.GetTPSharedGroups(attrs.TPid, attrs.ID); err != nil {
- return utils.NewErrServerError(err)
- } else if len(sgs) == 0 {
- return utils.ErrNotFound
+ if err.Error() != utils.ErrNotFound.Error() {
+ err = utils.NewErrServerError(err)
+ }
+ return err
} else {
*reply = *sgs[0]
}
diff --git a/apier/v1/tpsharedgroups_it_test.go b/apier/v1/tpsharedgroups_it_test.go
new file mode 100644
index 000000000..0f6e311a6
--- /dev/null
+++ b/apier/v1/tpsharedgroups_it_test.go
@@ -0,0 +1,236 @@
+// +build integration
+
+/*
+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 v1
+
+import (
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/utils"
+ "net/rpc"
+ "net/rpc/jsonrpc"
+ "path"
+ "reflect"
+ "testing"
+)
+
+var (
+ tpSharedGroupCfgPath string
+ tpSharedGroupCfg *config.CGRConfig
+ tpSharedGroupRPC *rpc.Client
+ tpSharedGroupDataDir = "/usr/share/cgrates"
+ tpSharedGroups *utils.TPSharedGroups
+ tpSharedGroupDelay int
+ tpSharedGroupConfigDIR string //run tests for specific configuration
+)
+
+var sTestsTPSharedGroups = []func(t *testing.T){
+ testTPSharedGroupsInitCfg,
+ testTPSharedGroupsResetStorDb,
+ testTPSharedGroupsStartEngine,
+ testTPSharedGroupsRpcConn,
+ testTPSharedGroupsBeforeSet,
+ testTPSharedGroupsSetSharedGroups,
+ testTPSharedGroupsAfterSet,
+ testTPSharedGroupsGetTPSharedGroupIds,
+ testTPSharedGroupsUpdateTPShareGroups,
+ testTpSharedGroupsGetTPSharedGroupsAfterUpdate,
+ testTPSharedGroupsRemTPSharedGroups,
+ testTPSharedGroupsGetTPSharedGroupsAfterRemove,
+ testTPSharedGroupsKillEngine,
+}
+
+//Test start here
+func TestTPSharedGroupsITMySql(t *testing.T) {
+ tpSharedGroupConfigDIR = "tutmysql"
+ for _, stest := range sTestsTPSharedGroups {
+ t.Run(tpSharedGroupConfigDIR, stest)
+ }
+}
+
+func TestTPSharedGroupsITMongo(t *testing.T) {
+ tpSharedGroupConfigDIR = "tutmongo"
+ for _, stest := range sTestsTPSharedGroups {
+ t.Run(tpSharedGroupConfigDIR, stest)
+ }
+}
+
+func TestTPSharedGroupsITPG(t *testing.T) {
+ tpSharedGroupConfigDIR = "tutpostgres"
+ for _, stest := range sTestsTPSharedGroups {
+ t.Run(tpSharedGroupConfigDIR, stest)
+ }
+}
+
+func testTPSharedGroupsInitCfg(t *testing.T) {
+ var err error
+ tpSharedGroupCfgPath = path.Join(tpSharedGroupDataDir, "conf", "samples", tpSharedGroupConfigDIR)
+ tpSharedGroupCfg, err = config.NewCGRConfigFromFolder(tpSharedGroupCfgPath)
+ if err != nil {
+ t.Error(err)
+ }
+ tpSharedGroupCfg.DataFolderPath = tpSharedGroupDataDir // Share DataFolderPath through config towards StoreDb for Flush()
+ config.SetCgrConfig(tpSharedGroupCfg)
+ switch tpSharedGroupConfigDIR {
+ case "tutmongo": // Mongo needs more time to reset db
+ tpSharedGroupDelay = 4000
+ default:
+ tpSharedGroupDelay = 2000
+ }
+}
+
+// Wipe out the cdr database
+func testTPSharedGroupsResetStorDb(t *testing.T) {
+ if err := engine.InitStorDb(tpSharedGroupCfg); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// Start CGR Engine
+func testTPSharedGroupsStartEngine(t *testing.T) {
+ if _, err := engine.StopStartEngine(tpSharedGroupCfgPath, tpSharedGroupDelay); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// Connect rpc client to rater
+func testTPSharedGroupsRpcConn(t *testing.T) {
+ var err error
+ tpSharedGroupRPC, err = jsonrpc.Dial("tcp", tpSharedGroupCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
+ if err != nil {
+ t.Fatal(err)
+ }
+}
+
+func testTPSharedGroupsBeforeSet(t *testing.T) {
+ var reply *utils.TPSharedGroups
+ if err := tpSharedGroupRPC.Call("ApierV1.GetTPSharedGroups", AttrGetTPSharedGroups{TPid: "TPS1", ID: "Group1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
+ t.Error(err)
+ }
+}
+
+func testTPSharedGroupsSetSharedGroups(t *testing.T) {
+ tpSharedGroups = &utils.TPSharedGroups{
+ TPid: "TPS1",
+ ID: "Group1",
+ SharedGroups: []*utils.TPSharedGroup{
+ &utils.TPSharedGroup{
+ Account: "AccOne",
+ Strategy: "StrategyOne",
+ RatingSubject: "SubOne",
+ },
+ &utils.TPSharedGroup{
+ Account: "AccTow",
+ Strategy: "StrategyTwo",
+ RatingSubject: "SubTwo",
+ },
+ },
+ }
+ var result string
+ if err := tpSharedGroupRPC.Call("ApierV1.SetTPSharedGroups", tpSharedGroups, &result); err != nil {
+ t.Error(err)
+ } else if result != utils.OK {
+ t.Error("Unexpected reply returned", result)
+ }
+}
+
+func testTPSharedGroupsAfterSet(t *testing.T) {
+ var respond *utils.TPSharedGroups
+ if err := tpSharedGroupRPC.Call("ApierV1.GetTPSharedGroups", &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &respond); err != nil {
+ t.Error(err)
+ } else if !reflect.DeepEqual(tpSharedGroups.TPid, respond.TPid) {
+ t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.TPid, respond.TPid)
+ } else if !reflect.DeepEqual(tpSharedGroups.ID, respond.ID) {
+ t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.ID, respond.ID)
+ } else if !reflect.DeepEqual(len(tpSharedGroups.SharedGroups), len(respond.SharedGroups)) {
+ t.Errorf("Expecting: %+v, received: %+v", len(tpSharedGroups.SharedGroups), len(respond.SharedGroups))
+ }
+}
+
+func testTPSharedGroupsGetTPSharedGroupIds(t *testing.T) {
+ var result []string
+ expectedTPID := []string{"Group1"}
+ if err := tpSharedGroupRPC.Call("ApierV1.GetTPSharedGroupIds", AttrGetTPSharedGroupIds{tpSharedGroups.TPid, utils.Paginator{}}, &result); err != nil {
+ t.Error(err)
+ } else if !reflect.DeepEqual(result, expectedTPID) {
+ t.Errorf("Expecting: %+v, received: %+v", result, expectedTPID)
+ }
+}
+
+func testTPSharedGroupsUpdateTPShareGroups(t *testing.T) {
+ var result string
+ tpSharedGroups.SharedGroups = []*utils.TPSharedGroup{
+ &utils.TPSharedGroup{
+ Account: "AccOne",
+ Strategy: "StrategyOne",
+ RatingSubject: "SubOne",
+ },
+ &utils.TPSharedGroup{
+ Account: "AccTow",
+ Strategy: "StrategyTwo",
+ RatingSubject: "SubTwo",
+ },
+ &utils.TPSharedGroup{
+ Account: "AccPlus",
+ Strategy: "StrategyPlus",
+ RatingSubject: "SubPlus",
+ },
+ }
+ if err := tpSharedGroupRPC.Call("ApierV1.SetTPSharedGroups", tpSharedGroups, &result); err != nil {
+ t.Error(err)
+ } else if result != utils.OK {
+ t.Error("Unexpected reply returned", result)
+ }
+}
+
+func testTpSharedGroupsGetTPSharedGroupsAfterUpdate(t *testing.T) {
+ var expectedTPS *utils.TPSharedGroups
+ if err := tpSharedGroupRPC.Call("ApierV1.GetTPSharedGroups", &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &expectedTPS); err != nil {
+ t.Error(err)
+ } else if !reflect.DeepEqual(tpSharedGroups.TPid, expectedTPS.TPid) {
+ t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.TPid, expectedTPS.TPid)
+ } else if !reflect.DeepEqual(tpSharedGroups.ID, expectedTPS.ID) {
+ t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.ID, expectedTPS.ID)
+ } else if !reflect.DeepEqual(len(tpSharedGroups.SharedGroups), len(expectedTPS.SharedGroups)) {
+ t.Errorf("Expecting: %+v, received: %+v", len(tpSharedGroups.SharedGroups), len(expectedTPS.SharedGroups))
+ }
+}
+
+func testTPSharedGroupsRemTPSharedGroups(t *testing.T) {
+ var resp string
+ if err := tpSharedGroupRPC.Call("ApierV1.RemTPSharedGroups", &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &resp); err != nil {
+ t.Error(err)
+ } else if resp != utils.OK {
+ t.Error("Unexpected reply returned", resp)
+ }
+}
+
+func testTPSharedGroupsGetTPSharedGroupsAfterRemove(t *testing.T) {
+ var reply *utils.TPSharedGroups
+ if err := tpSharedGroupRPC.Call("ApierV1.GetTPSharedGroups", AttrGetTPSharedGroups{TPid: "TPS1", ID: "Group1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
+ t.Error(err)
+ }
+}
+
+func testTPSharedGroupsKillEngine(t *testing.T) {
+ if err := engine.KillEngine(tpSharedGroupDelay); err != nil {
+ t.Error(err)
+ }
+}
diff --git a/apier/v1/tpstats_it_test.go b/apier/v1/tpstats_it_test.go
index 12fefc3a3..4d5f46f84 100644
--- a/apier/v1/tpstats_it_test.go
+++ b/apier/v1/tpstats_it_test.go
@@ -17,6 +17,7 @@ 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 v1
import (
diff --git a/apier/v1/tptimings.go b/apier/v1/tptimings.go
index 269ef467b..34f1a0bba 100644
--- a/apier/v1/tptimings.go
+++ b/apier/v1/tptimings.go
@@ -45,9 +45,10 @@ func (self *ApierV1) GetTPTiming(attrs AttrGetTPTiming, reply *utils.ApierTPTimi
return utils.NewErrMandatoryIeMissing(missing...)
}
if tms, err := self.StorDb.GetTPTimings(attrs.TPid, attrs.ID); err != nil {
- return utils.NewErrServerError(err)
- } else if len(tms) == 0 {
- return utils.ErrNotFound
+ if err.Error() != utils.ErrNotFound.Error() {
+ err = utils.NewErrServerError(err)
+ }
+ return err
} else {
*reply = *tms[0]
}
diff --git a/apier/v1/tptimings_it_test.go b/apier/v1/tptimings_it_test.go
new file mode 100644
index 000000000..c98604151
--- /dev/null
+++ b/apier/v1/tptimings_it_test.go
@@ -0,0 +1,205 @@
+// +build integration
+
+/*
+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 v1
+
+import (
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/utils"
+ "net/rpc"
+ "net/rpc/jsonrpc"
+ "path"
+ "reflect"
+ "testing"
+)
+
+var (
+ tpTimingCfgPath string
+ tpTimingCfg *config.CGRConfig
+ tpTimingRPC *rpc.Client
+ tpTimingDataDir = "/usr/share/cgrates"
+ tpTiming *utils.ApierTPTiming
+ tpTimingDelay int
+ tpTimingConfigDIR string //run tests for specific configuration
+)
+
+var sTestsTPTiming = []func(t *testing.T){
+ testTPTimingsInitCfg,
+ testTPTimingsResetStorDb,
+ testTPTimingsStartEngine,
+ testTPTimingsRpcConn,
+ testTPTimingsGetTPTimingBeforeSet,
+ testTPTimingsSetTPTiming,
+ testTPTimingsGetTPTimingAfterSet,
+ testTPTimingsGetTPTimingIds,
+ testTPTimingsUpdateTPTiming,
+ testTPTimingsGetTPTimingAfterUpdate,
+ testTPTimingsRemTPTiming,
+ testTPTimingsGetTPTimingAfterRemove,
+ testTPTimingsKillEngine,
+}
+
+//Test start here
+func TestTPTimingITMySql(t *testing.T) {
+ tpTimingConfigDIR = "tutmysql"
+ for _, stest := range sTestsTPTiming {
+ t.Run(tpTimingConfigDIR, stest)
+ }
+}
+
+func TestTPTimingITMongo(t *testing.T) {
+ tpTimingConfigDIR = "tutmongo"
+ for _, stest := range sTestsTPTiming {
+ t.Run(tpTimingConfigDIR, stest)
+ }
+}
+
+func TestTPTimingITPG(t *testing.T) {
+ tpTimingConfigDIR = "tutpostgres"
+ for _, stest := range sTestsTPTiming {
+ t.Run(tpTimingConfigDIR, stest)
+ }
+}
+
+func testTPTimingsInitCfg(t *testing.T) {
+ var err error
+ tpTimingCfgPath = path.Join(tpTimingDataDir, "conf", "samples", tpTimingConfigDIR)
+ tpTimingCfg, err = config.NewCGRConfigFromFolder(tpTimingCfgPath)
+ if err != nil {
+ t.Error(err)
+ }
+ tpTimingCfg.DataFolderPath = tpTimingDataDir // Share DataFolderPath through config towards StoreDb for Flush()
+ config.SetCgrConfig(tpTimingCfg)
+ switch tpTimingConfigDIR {
+ case "tutmongo": // Mongo needs more time to reset db
+ tpTimingDelay = 4000
+ default:
+ tpTimingDelay = 2000
+ }
+}
+
+// Wipe out the cdr database
+func testTPTimingsResetStorDb(t *testing.T) {
+ if err := engine.InitStorDb(tpTimingCfg); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// Start CGR Engine
+func testTPTimingsStartEngine(t *testing.T) {
+ if _, err := engine.StopStartEngine(tpTimingCfgPath, tpTimingDelay); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// Connect rpc client to rater
+func testTPTimingsRpcConn(t *testing.T) {
+ var err error
+ tpTimingRPC, err = jsonrpc.Dial("tcp", tpTimingCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
+ if err != nil {
+ t.Fatal(err)
+ }
+}
+
+func testTPTimingsGetTPTimingBeforeSet(t *testing.T) {
+ var reply *utils.ApierTPTiming
+ if err := tpTimingRPC.Call("ApierV1.GetTPTiming", AttrGetTPTiming{TPid: "TPT1", ID: "Timining"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
+ t.Error(err)
+ }
+}
+
+func testTPTimingsSetTPTiming(t *testing.T) {
+ tpTiming = &utils.ApierTPTiming{
+ TPid: "TPT1",
+ ID: "Timing",
+ Years: "2017",
+ Months: "05",
+ MonthDays: "01",
+ WeekDays: "1",
+ Time: "15:00:00Z",
+ }
+ var result string
+ if err := tpTimingRPC.Call("ApierV1.SetTPTiming", tpTiming, &result); err != nil {
+ t.Error(err)
+ } else if result != utils.OK {
+ t.Error("Unexpected reply returned", result)
+ }
+}
+
+func testTPTimingsGetTPTimingAfterSet(t *testing.T) {
+ var respond *utils.ApierTPTiming
+ if err := tpTimingRPC.Call("ApierV1.GetTPTiming", &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &respond); err != nil {
+ t.Error(err)
+ } else if !reflect.DeepEqual(tpTiming, respond) {
+ t.Errorf("Expecting: %+v, received: %+v", tpTiming, respond)
+ }
+}
+
+func testTPTimingsGetTPTimingIds(t *testing.T) {
+ var result []string
+ expectedTPID := []string{"Timing"}
+ if err := tpTimingRPC.Call("ApierV1.GetTPTimingIds", &AttrGetTPTimingIds{TPid: tpTiming.TPid}, &result); err != nil {
+ t.Error(err)
+ } else if !reflect.DeepEqual(result, expectedTPID) {
+ t.Errorf("Expecting: %+v, received: %+v", result, expectedTPID)
+ }
+}
+
+func testTPTimingsUpdateTPTiming(t *testing.T) {
+ var result string
+ tpTiming.Years = "2015"
+ if err := tpTimingRPC.Call("ApierV1.SetTPTiming", tpTiming, &result); err != nil {
+ t.Error(err)
+ } else if result != utils.OK {
+ t.Error("Unexpected reply returned", result)
+ }
+}
+
+func testTPTimingsGetTPTimingAfterUpdate(t *testing.T) {
+ var expectedTPS *utils.ApierTPTiming
+ if err := tpTimingRPC.Call("ApierV1.GetTPTiming", &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &expectedTPS); err != nil {
+ t.Error(err)
+ } else if !reflect.DeepEqual(tpTiming, expectedTPS) {
+ t.Errorf("Expecting: %+v, received: %+v", tpTiming, expectedTPS)
+ }
+}
+
+func testTPTimingsRemTPTiming(t *testing.T) {
+ var resp string
+ if err := tpTimingRPC.Call("ApierV1.RemTPTiming", &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &resp); err != nil {
+ t.Error(err)
+ } else if resp != utils.OK {
+ t.Error("Unexpected reply returned", resp)
+ }
+}
+
+func testTPTimingsGetTPTimingAfterRemove(t *testing.T) {
+ var reply *utils.ApierTPTiming
+ if err := tpTimingRPC.Call("ApierV1.GetTPTiming", AttrGetTPTiming{TPid: "TPT1", ID: "Timining"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
+ t.Error(err)
+ }
+}
+
+func testTPTimingsKillEngine(t *testing.T) {
+ if err := engine.KillEngine(tpTimingDelay); err != nil {
+ t.Error(err)
+ }
+}
diff --git a/apier/v1/tpusers_it_test.go b/apier/v1/tpusers_it_test.go
index 9f1c978bb..27a1c891d 100644
--- a/apier/v1/tpusers_it_test.go
+++ b/apier/v1/tpusers_it_test.go
@@ -17,6 +17,7 @@ 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 v1
import (
diff --git a/data/conf/samples/tutmysql/cgrates.json b/data/conf/samples/tutmysql/cgrates.json
index bb2983bd3..ce0358ea1 100644
--- a/data/conf/samples/tutmysql/cgrates.json
+++ b/data/conf/samples/tutmysql/cgrates.json
@@ -118,7 +118,7 @@
"historys": {
- "enabled": false,
+ "enabled": true,
},