From e1d6b96dd8f1eabac6e5fdac22092bed3c38ba2e Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 11 Dec 2017 17:39:03 +0200 Subject: [PATCH] Update apier/v1/suppliers_it_test and tpattribute_it_test --- apier/v1/attributes.go | 4 +- apier/v1/suppliers.go | 2 + apier/v1/suppliers_it_test.go | 114 +++++++++++++++++++++++++++++++ apier/v1/tpattributes_it_test.go | 10 +-- 4 files changed, 124 insertions(+), 6 deletions(-) diff --git a/apier/v1/attributes.go b/apier/v1/attributes.go index 007699fb0..79f768d46 100644 --- a/apier/v1/attributes.go +++ b/apier/v1/attributes.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/cgrates/cache" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -28,7 +29,7 @@ func (apierV1 *ApierV1) GetAttributeProfile(arg utils.TenantID, reply *engine.Ex if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if alsPrf, err := apierV1.DataManager.GetAttributeProfile(arg.Tenant, arg.ID, true, utils.NonTransactional); err != nil { + if alsPrf, err := apierV1.DataManager.GetAttributeProfile(arg.Tenant, arg.ID, false, utils.NonTransactional); err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } @@ -48,6 +49,7 @@ func (apierV1 *ApierV1) SetAttributeProfile(extAls *engine.ExternalAttributeProf if err := apierV1.DataManager.SetAttributeProfile(alsPrf); err != nil { return utils.APIErrorHandler(err) } + cache.RemKey(utils.AttributeProfilePrefix+utils.ConcatenatedKey(extAls.Tenant, extAls.ID), true, "") // ToDo: Remove here with autoreload *reply = utils.OK return nil } diff --git a/apier/v1/suppliers.go b/apier/v1/suppliers.go index 1d85ca7ee..8726ec400 100644 --- a/apier/v1/suppliers.go +++ b/apier/v1/suppliers.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/cgrates/cache" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -47,6 +48,7 @@ func (apierV1 *ApierV1) SetSupplierProfile(spp *engine.SupplierProfile, reply *s if err := apierV1.DataManager.SetSupplierProfile(spp); err != nil { return utils.APIErrorHandler(err) } + cache.RemKey(utils.SupplierProfilePrefix+utils.ConcatenatedKey(spp.Tenant, spp.ID), true, "") // ToDo: Remove here with autoreload *reply = utils.OK return nil } diff --git a/apier/v1/suppliers_it_test.go b/apier/v1/suppliers_it_test.go index 0e9622e38..12bd96da5 100644 --- a/apier/v1/suppliers_it_test.go +++ b/apier/v1/suppliers_it_test.go @@ -36,6 +36,7 @@ var ( splSv1CfgPath string splSv1Cfg *config.CGRConfig splSv1Rpc *rpc.Client + splPrf *engine.SupplierProfile splSv1ConfDIR string //run tests for specific configuration splsDelay int ) @@ -49,6 +50,9 @@ var sTestsSupplierSV1 = []func(t *testing.T){ testV1SplSFromFolder, testV1SplSGetWeightSuppliers, testV1SplSGetLeastCostSuppliers, + testV1SplSSetSupplierProfiles, + testV1SplSUpdateSupplierProfiles, + testV1SplSRemSupplierProfiles, testV1SplSStopEngine, } @@ -207,6 +211,116 @@ func testV1SplSGetLeastCostSuppliers(t *testing.T) { } } +func testV1SplSSetSupplierProfiles(t *testing.T) { + var reply *engine.SupplierProfile + if err := splSv1Rpc.Call("ApierV1.GetSupplierProfile", + &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + splPrf = &engine.SupplierProfile{ + Tenant: "cgrates.org", + ID: "TEST_PROFILE1", + FilterIDs: []string{"FLTR_1"}, + Sorting: "Sort1", + SortingParams: []string{"Param1", "Param2"}, + Suppliers: []*engine.Supplier{ + &engine.Supplier{ + ID: "SPL1", + RatingPlanIDs: []string{"RP1"}, + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res1", "ResGroup2"}, + StatIDs: []string{"Stat1"}, + Weight: 20, + }, + }, + Blocker: false, + Weight: 10, + } + var result string + if err := splSv1Rpc.Call("ApierV1.SetSupplierProfile", splPrf, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + if err := splSv1Rpc.Call("ApierV1.GetSupplierProfile", + &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(splPrf, reply) { + t.Errorf("Expecting: %+v, received: %+v", splPrf, reply) + } +} + +func testV1SplSUpdateSupplierProfiles(t *testing.T) { + splPrf.Suppliers = []*engine.Supplier{ + &engine.Supplier{ + ID: "SPL1", + RatingPlanIDs: []string{"RP1"}, + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res1", "ResGroup2"}, + StatIDs: []string{"Stat1"}, + Weight: 20, + }, + &engine.Supplier{ + ID: "SPL2", + RatingPlanIDs: []string{"RP2"}, + FilterIDs: []string{"FLTR_2"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res2", "ResGroup2"}, + StatIDs: []string{"Stat2"}, + Weight: 20, + }, + } + reverseSuppliers := []*engine.Supplier{ + &engine.Supplier{ + ID: "SPL2", + RatingPlanIDs: []string{"RP2"}, + FilterIDs: []string{"FLTR_2"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res2", "ResGroup2"}, + StatIDs: []string{"Stat2"}, + Weight: 20, + }, + &engine.Supplier{ + ID: "SPL1", + RatingPlanIDs: []string{"RP1"}, + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res1", "ResGroup2"}, + StatIDs: []string{"Stat1"}, + Weight: 20, + }, + } + var result string + if err := splSv1Rpc.Call("ApierV1.SetSupplierProfile", splPrf, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + var reply *engine.SupplierProfile + if err := splSv1Rpc.Call("ApierV1.GetSupplierProfile", + &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(splPrf.Suppliers, reply.Suppliers) && !reflect.DeepEqual(reverseSuppliers, reply.Suppliers) { + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(splPrf), utils.ToJSON(reply)) + } +} + +func testV1SplSRemSupplierProfiles(t *testing.T) { + var resp string + if err := splSv1Rpc.Call("ApierV1.RemSupplierProfile", &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + var reply *engine.SupplierProfile + if err := splSv1Rpc.Call("ApierV1.GetAttributeProfile", &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} + func testV1SplSStopEngine(t *testing.T) { if err := engine.KillEngine(100); err != nil { t.Error(err) diff --git a/apier/v1/tpattributes_it_test.go b/apier/v1/tpattributes_it_test.go index d1e4d3c19..ae38adfcd 100644 --- a/apier/v1/tpattributes_it_test.go +++ b/apier/v1/tpattributes_it_test.go @@ -130,8 +130,8 @@ func testTPAlsPrfSetTPAlsPrf(t *testing.T) { ExpiryTime: "", }, Context: "con1", - Attributes: []*utils.TPRequestAttribute{ - &utils.TPRequestAttribute{ + Substitutes: []*utils.TPRequestSubstitute{ + &utils.TPRequestSubstitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", @@ -168,14 +168,14 @@ func testTPAlsPrfGetTPAlsPrfIDs(t *testing.T) { } func testTPAlsPrfUpdateTPAlsPrf(t *testing.T) { - tpAlsPrf.Attributes = []*utils.TPRequestAttribute{ - &utils.TPRequestAttribute{ + tpAlsPrf.Substitutes = []*utils.TPRequestSubstitute{ + &utils.TPRequestSubstitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", Append: true, }, - &utils.TPRequestAttribute{ + &utils.TPRequestSubstitute{ FieldName: "FL2", Initial: "In2", Alias: "Al2",