From 993651f18106766d678065cf290cf407c5bf8c77 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Thu, 22 Jul 2021 17:19:24 +0300 Subject: [PATCH] Tested ActivationTime field in RatingProfiles --- apier/v1/rating_profile_late_it_test.go | 164 ++++++++++++++++++++++++ apier/v1/remote_it_test.go | 8 ++ 2 files changed, 172 insertions(+) create mode 100644 apier/v1/rating_profile_late_it_test.go diff --git a/apier/v1/rating_profile_late_it_test.go b/apier/v1/rating_profile_late_it_test.go new file mode 100644 index 000000000..5b7f626d0 --- /dev/null +++ b/apier/v1/rating_profile_late_it_test.go @@ -0,0 +1,164 @@ +// +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" + "path" + "testing" + "time" +) + +var ( + rpLateCfGPath string + rpLateCfg *config.CGRConfig + rpLateRPC *rpc.Client + rpLateConfigDIR string //run tests for specific configuration + + rpLateAPIer = []func(t *testing.T){ + testRpLateInitCfg, + testRpLateInitDataDb, + testRpLateResetStorDb, + testRpLateStartEngine, + testRpLateRPCConn, + testRpLateLoadFromFolder, + testRpLateCDRProcessEvent, + testRpLateKillEngine, + } +) + +//Test start here +func TestRPLateIT2(t *testing.T) { + // no need for a new config with *gob transport in this case + switch *dbType { + case utils.MetaInternal: + rpLateConfigDIR = "tutinternal" + case utils.MetaMySQL: + rpLateConfigDIR = "tutmysql" + case utils.MetaMongo: + rpLateConfigDIR = "tutmongo" + case utils.MetaPostgres: + t.SkipNow() + default: + t.Fatal("Unknown Database type") + } + for _, stest := range rpLateAPIer { + t.Run(rpLateConfigDIR, stest) + } +} + +func testRpLateInitCfg(t *testing.T) { + var err error + rpLateCfGPath = path.Join(*dataDir, "conf", "samples", rpLateConfigDIR) + rpLateCfg, err = config.NewCGRConfigFromPath(rpLateCfGPath) + if err != nil { + t.Error(err) + } +} + +func testRpLateInitDataDb(t *testing.T) { + if err := engine.InitDataDb(rpLateCfg); err != nil { + t.Fatal(err) + } +} + +// Wipe out the cdr database +func testRpLateResetStorDb(t *testing.T) { + if err := engine.InitStorDb(rpLateCfg); err != nil { + t.Fatal(err) + } +} + +// Start CGR Engine +func testRpLateStartEngine(t *testing.T) { + if _, err := engine.StopStartEngine(rpLateCfGPath , *waitRater); err != nil { + t.Fatal(err) + } +} + +// Connect rpc client to rater +func testRpLateRPCConn(t *testing.T) { + var err error + rpLateRPC, err = newRPCClient(rpLateCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed + if err != nil { + t.Fatal(err) + } +} + +func testRpLateLoadFromFolder(t *testing.T) { + var reply string + attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} + if err := rpLateRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + t.Error(err) + } + time.Sleep(100 * time.Millisecond) +} + +func testRpLateCDRProcessEvent(t *testing.T) { + args := &engine.CDRWithAPIOpts{ + CDR: &engine.CDR{ + CGRID: "RandomCgrId", + Tenant: "cgrates.org", + OriginID: "testRpLateCDRProcessEvent", + Source: "testRpLateCDRProcessEvent", + RequestType: utils.MetaPrepaid, + Account: "1001", + Category: "call", + Subject: "1001", + Destination: "1001", + SetupTime: time.Date(2010, 8, 24, 16, 00, 26, 0, time.UTC), + AnswerTime: time.Date(2010, 8, 24, 16, 00, 26, 0, time.UTC), + Usage: 2 * time.Minute, + }, + } + var reply string + if err := rpLateRPC.Call(utils.CDRsV1ProcessCDR, args, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Errorf("UNexpected reply returned") + } + + var replyy []*engine.CDR + req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ + /* + CGRIDs: []string{"RandomCgrId"}, + //RunIDs: []string{utils.MetaRaw, utils.MetaDefault}, + Tenants: []string{"cgrates.org"}, + Categories: []string{"call"}, + Subjects: []string{"1001"}, + + */ + }} + if err := rpLateRPC.Call(utils.CDRsV1GetCDRs, &req, &replyy); err != nil { + t.Error("Unexpected error: ", err.Error()) + } else if len(replyy) != 2 { + t.Error("Unexpected number of CDRs returned: ", len(replyy), "and CDRS: ", utils.ToJSON(replyy)) + } +} + +func testRpLateKillEngine(t *testing.T) { + if err := engine.KillEngine(*waitRater); err != nil { + t.Error(err) + } +} \ No newline at end of file diff --git a/apier/v1/remote_it_test.go b/apier/v1/remote_it_test.go index 6ef6ec67e..3bd09a42c 100644 --- a/apier/v1/remote_it_test.go +++ b/apier/v1/remote_it_test.go @@ -497,6 +497,10 @@ func testInternalRemoteITGetRatingProfile(t *testing.T) { if err != nil { t.Error(err) } + actTime1, err := utils.ParseTimeDetectLayout("2010-01-14T00:00:00Z", "") + if err != nil { + t.Error(err) + } expected := engine.RatingProfile{ Id: "*out:cgrates.org:call:1001", RatingPlanActivations: engine.RatingPlanActivations{ @@ -504,6 +508,10 @@ func testInternalRemoteITGetRatingProfile(t *testing.T) { ActivationTime: actTime, RatingPlanId: "RP_1001", }, + { + ActivationTime: actTime1, + RatingPlanId: "RP_1002", + }, }, } if err := internalRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil {