mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update TPTest with new renaming
This commit is contained in:
committed by
Dan Christian Bogos
parent
b8e4c3cfc3
commit
3445708472
@@ -153,34 +153,34 @@ func testAttributeSGetAttributeForEvent(t *testing.T) {
|
||||
Context: utils.MetaRating,
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)},
|
||||
Substitutes: []*engine.AttributeSubstitute{
|
||||
&engine.AttributeSubstitute{
|
||||
FieldName: utils.ACCOUNT,
|
||||
Initial: utils.ANY,
|
||||
Alias: "1001",
|
||||
Append: false,
|
||||
Attributes: []*engine.Attribute{
|
||||
&engine.Attribute{
|
||||
FieldName: utils.ACCOUNT,
|
||||
Initial: utils.ANY,
|
||||
Substitute: "1001",
|
||||
Append: false,
|
||||
},
|
||||
&engine.AttributeSubstitute{
|
||||
FieldName: utils.SUBJECT,
|
||||
Initial: utils.ANY,
|
||||
Alias: "1001",
|
||||
Append: true,
|
||||
&engine.Attribute{
|
||||
FieldName: utils.SUBJECT,
|
||||
Initial: utils.ANY,
|
||||
Substitute: "1001",
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 10.0,
|
||||
}
|
||||
reverseSubstitute := []*engine.AttributeSubstitute{
|
||||
&engine.AttributeSubstitute{
|
||||
FieldName: utils.SUBJECT,
|
||||
Initial: utils.ANY,
|
||||
Alias: "1001",
|
||||
Append: true,
|
||||
reverseSubstitute := []*engine.Attribute{
|
||||
&engine.Attribute{
|
||||
FieldName: utils.SUBJECT,
|
||||
Initial: utils.ANY,
|
||||
Substitute: "1001",
|
||||
Append: true,
|
||||
},
|
||||
&engine.AttributeSubstitute{
|
||||
FieldName: utils.ACCOUNT,
|
||||
Initial: utils.ANY,
|
||||
Alias: "1001",
|
||||
Append: false,
|
||||
&engine.Attribute{
|
||||
FieldName: utils.ACCOUNT,
|
||||
Initial: utils.ANY,
|
||||
Substitute: "1001",
|
||||
Append: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -202,8 +202,8 @@ func testAttributeSGetAttributeForEvent(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(eAttrPrf.ActivationInterval.ExpiryTime.Local(), attrReply.ActivationInterval.ExpiryTime.Local()) {
|
||||
t.Errorf("Expecting: %s, received: %s",
|
||||
eAttrPrf.ActivationInterval.ExpiryTime.Local(), attrReply.ActivationInterval.ExpiryTime.Local())
|
||||
} else if !reflect.DeepEqual(eAttrPrf.Substitutes, attrReply.Substitutes) && !reflect.DeepEqual(reverseSubstitute, attrReply.Substitutes) {
|
||||
t.Errorf("Expecting: %s, received: %s", utils.ToJSON(eAttrPrf.Substitutes), utils.ToJSON(attrReply.Substitutes))
|
||||
} else if !reflect.DeepEqual(eAttrPrf.Attributes, attrReply.Attributes) && !reflect.DeepEqual(reverseSubstitute, attrReply.Attributes) {
|
||||
t.Errorf("Expecting: %s, received: %s", utils.ToJSON(eAttrPrf.Attributes), utils.ToJSON(attrReply.Attributes))
|
||||
} else if !reflect.DeepEqual(eAttrPrf.Weight, attrReply.Weight) {
|
||||
t.Errorf("Expecting: %s, received: %s", eAttrPrf.Weight, attrReply.Weight)
|
||||
}
|
||||
@@ -268,12 +268,12 @@ func testAttributeSSetAlsPrf(t *testing.T) {
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(),
|
||||
},
|
||||
Substitutes: []*engine.AttributeSubstitute{
|
||||
&engine.AttributeSubstitute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Alias: "Al1",
|
||||
Append: true,
|
||||
Attributes: []*engine.Attribute{
|
||||
&engine.Attribute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Substitute: "Al1",
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
@@ -291,26 +291,26 @@ func testAttributeSSetAlsPrf(t *testing.T) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf.FilterIDs, reply.FilterIDs)
|
||||
} else if !reflect.DeepEqual(alsPrf.ActivationInterval, reply.ActivationInterval) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf.ActivationInterval, reply.ActivationInterval)
|
||||
} else if !reflect.DeepEqual(len(alsPrf.Substitutes), len(reply.Substitutes)) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Substitutes), utils.ToJSON(reply.Substitutes))
|
||||
} else if !reflect.DeepEqual(len(alsPrf.Attributes), len(reply.Attributes)) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Attributes), utils.ToJSON(reply.Attributes))
|
||||
} else if !reflect.DeepEqual(alsPrf.ID, reply.ID) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf.ID, reply.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func testAttributeSUpdateAlsPrf(t *testing.T) {
|
||||
alsPrf.Substitutes = []*engine.AttributeSubstitute{
|
||||
&engine.AttributeSubstitute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Alias: "Al1",
|
||||
Append: true,
|
||||
alsPrf.Attributes = []*engine.Attribute{
|
||||
&engine.Attribute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Substitute: "Al1",
|
||||
Append: true,
|
||||
},
|
||||
&engine.AttributeSubstitute{
|
||||
FieldName: "FL2",
|
||||
Initial: "In2",
|
||||
Alias: "Al2",
|
||||
Append: false,
|
||||
&engine.Attribute{
|
||||
FieldName: "FL2",
|
||||
Initial: "In2",
|
||||
Substitute: "Al2",
|
||||
Append: false,
|
||||
},
|
||||
}
|
||||
var result string
|
||||
@@ -326,8 +326,8 @@ func testAttributeSUpdateAlsPrf(t *testing.T) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf.FilterIDs, reply.FilterIDs)
|
||||
} else if !reflect.DeepEqual(alsPrf.ActivationInterval, reply.ActivationInterval) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf.ActivationInterval, reply.ActivationInterval)
|
||||
} else if !reflect.DeepEqual(len(alsPrf.Substitutes), len(reply.Substitutes)) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Substitutes), utils.ToJSON(reply.Substitutes))
|
||||
} else if !reflect.DeepEqual(len(alsPrf.Attributes), len(reply.Attributes)) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Attributes), utils.ToJSON(reply.Attributes))
|
||||
} else if !reflect.DeepEqual(alsPrf.ID, reply.ID) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf.ID, reply.ID)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ var (
|
||||
tpAlsPrfCfg *config.CGRConfig
|
||||
tpAlsPrfRPC *rpc.Client
|
||||
tpAlsPrfDataDir = "/usr/share/cgrates"
|
||||
tpAlsPrf *utils.TPAttribute
|
||||
tpAlsPrf *utils.TPAttributeProfile
|
||||
tpAlsPrfDelay int
|
||||
tpAlsPrfConfigDIR string //run tests for specific configuration
|
||||
)
|
||||
@@ -113,14 +113,14 @@ func testTPAlsPrfRPCConn(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPAlsPrfGetTPAlsPrfBeforeSet(t *testing.T) {
|
||||
var reply *utils.TPAttribute
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttribute", &AttrGetTPAttribute{TPid: "TP1", ID: "ALS1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
var reply *utils.TPAttributeProfile
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeProfile", &AttrGetTPAttributeProfile{TPid: "TP1", ID: "ALS1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPAlsPrfSetTPAlsPrf(t *testing.T) {
|
||||
tpAlsPrf = &utils.TPAttribute{
|
||||
tpAlsPrf = &utils.TPAttributeProfile{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Attr1",
|
||||
@@ -130,18 +130,18 @@ func testTPAlsPrfSetTPAlsPrf(t *testing.T) {
|
||||
ExpiryTime: "",
|
||||
},
|
||||
Context: "con1",
|
||||
Substitutes: []*utils.TPAttributeSubstitute{
|
||||
&utils.TPAttributeSubstitute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Alias: "Al1",
|
||||
Append: true,
|
||||
Attributes: []*utils.TPAttribute{
|
||||
&utils.TPAttribute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Substitute: "Al1",
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.SetTPAttribute", tpAlsPrf, &result); err != nil {
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.SetTPAttributeProfile", tpAlsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
@@ -149,8 +149,8 @@ func testTPAlsPrfSetTPAlsPrf(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPAlsPrfGetTPAlsPrfAfterSet(t *testing.T) {
|
||||
var reply *utils.TPAttribute
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttribute", &AttrGetTPAttribute{TPid: "TP1", ID: "Attr1"}, &reply); err != nil {
|
||||
var reply *utils.TPAttributeProfile
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeProfile", &AttrGetTPAttributeProfile{TPid: "TP1", ID: "Attr1"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpAlsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpAlsPrf, reply)
|
||||
@@ -160,7 +160,7 @@ func testTPAlsPrfGetTPAlsPrfAfterSet(t *testing.T) {
|
||||
func testTPAlsPrfGetTPAlsPrfIDs(t *testing.T) {
|
||||
var result []string
|
||||
expectedTPID := []string{"Attr1"}
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeIds", &AttrGetTPAttributeIds{TPid: "TP1"}, &result); err != nil {
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeProfileIds", &AttrGetTPAttributeProfileIds{TPid: "TP1"}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedTPID, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
|
||||
@@ -168,22 +168,22 @@ func testTPAlsPrfGetTPAlsPrfIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPAlsPrfUpdateTPAlsPrf(t *testing.T) {
|
||||
tpAlsPrf.Substitutes = []*utils.TPAttributeSubstitute{
|
||||
&utils.TPAttributeSubstitute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Alias: "Al1",
|
||||
Append: true,
|
||||
tpAlsPrf.Attributes = []*utils.TPAttribute{
|
||||
&utils.TPAttribute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Substitute: "Al1",
|
||||
Append: true,
|
||||
},
|
||||
&utils.TPAttributeSubstitute{
|
||||
FieldName: "FL2",
|
||||
Initial: "In2",
|
||||
Alias: "Al2",
|
||||
Append: false,
|
||||
&utils.TPAttribute{
|
||||
FieldName: "FL2",
|
||||
Initial: "In2",
|
||||
Substitute: "Al2",
|
||||
Append: false,
|
||||
},
|
||||
}
|
||||
var result string
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.SetTPAttribute", tpAlsPrf, &result); err != nil {
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.SetTPAttributeProfile", tpAlsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
@@ -191,8 +191,8 @@ func testTPAlsPrfUpdateTPAlsPrf(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) {
|
||||
var reply *utils.TPAttribute
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttribute", &AttrGetTPAttribute{TPid: "TP1", ID: "Attr1"}, &reply); err != nil {
|
||||
var reply *utils.TPAttributeProfile
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeProfile", &AttrGetTPAttributeProfile{TPid: "TP1", ID: "Attr1"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpAlsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpAlsPrf, reply)
|
||||
@@ -201,7 +201,7 @@ func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) {
|
||||
|
||||
func testTPAlsPrfRemTPAlsPrf(t *testing.T) {
|
||||
var resp string
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.RemTPAttribute", &AttrRemTPAttribute{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &resp); err != nil {
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.RemTPAttributeProfile", &AttrRemTPAttributeProfile{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.OK {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
@@ -209,8 +209,8 @@ func testTPAlsPrfRemTPAlsPrf(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPAlsPrfGetTPAlsPrfAfterRemove(t *testing.T) {
|
||||
var reply *utils.TPAttribute
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttribute", &AttrGetTPAttribute{TPid: "TP1", ID: "ALS1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
var reply *utils.TPAttributeProfile
|
||||
if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeProfile", &AttrGetTPAttributeProfile{TPid: "TP1", ID: "ALS1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,25 +22,25 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// Creates a new Filter within a tariff plan
|
||||
func (self *ApierV1) SetTPFilter(attrs utils.TPFilter, reply *string) error {
|
||||
// Creates a new FilterProfile within a tariff plan
|
||||
func (self *ApierV1) SetTPFilterProfile(attrs utils.TPFilterProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.SetTPFilters([]*utils.TPFilter{&attrs}); err != nil {
|
||||
if err := self.StorDb.SetTPFilters([]*utils.TPFilterProfile{&attrs}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrGetTPFilter struct {
|
||||
type AttrGetTPFilterProfile struct {
|
||||
TPid string // Tariff plan id
|
||||
ID string // Filter id
|
||||
}
|
||||
|
||||
// Queries specific Filter on tariff plan
|
||||
func (self *ApierV1) GetTPFilter(attr AttrGetTPFilter, reply *utils.TPFilter) error {
|
||||
// Queries specific FilterProfile on tariff plan
|
||||
func (self *ApierV1) GetTPFilterProfile(attr AttrGetTPFilterProfile, reply *utils.TPFilterProfile) error {
|
||||
if missing := utils.MissingStructFields(&attr, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
@@ -55,13 +55,13 @@ func (self *ApierV1) GetTPFilter(attr AttrGetTPFilter, reply *utils.TPFilter) er
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrGetTPFilterIds struct {
|
||||
type AttrGetTPFilterProfileIds struct {
|
||||
TPid string // Tariff plan id
|
||||
utils.Paginator
|
||||
}
|
||||
|
||||
// Queries Filter identities on specific tariff plan.
|
||||
func (self *ApierV1) GetTPFilterIds(attrs AttrGetTPFilterIds, reply *[]string) error {
|
||||
// Queries FilterProfile identities on specific tariff plan.
|
||||
func (self *ApierV1) GetTPFilterProfileIds(attrs AttrGetTPFilterProfileIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
@@ -76,14 +76,14 @@ func (self *ApierV1) GetTPFilterIds(attrs AttrGetTPFilterIds, reply *[]string) e
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrRemTPFilter struct {
|
||||
type AttrRemTPFilterProfile struct {
|
||||
TPid string // Tariff plan id
|
||||
Tenant string
|
||||
ID string // Filter id
|
||||
}
|
||||
|
||||
// Removes specific Filter on Tariff plan
|
||||
func (self *ApierV1) RemTPFilter(attrs AttrRemTPFilter, reply *string) error {
|
||||
// Removes specific FilterProfile on Tariff plan
|
||||
func (self *ApierV1) RemTPFilterProfile(attrs AttrRemTPFilterProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ var (
|
||||
tpFilterCfg *config.CGRConfig
|
||||
tpFilterRPC *rpc.Client
|
||||
tpFilterDataDir = "/usr/share/cgrates"
|
||||
tpFilter *utils.TPFilter
|
||||
tpFilter *utils.TPFilterProfile
|
||||
tpFilterDelay int
|
||||
tpFilterConfigDIR string //run tests for specific configuration
|
||||
)
|
||||
@@ -120,19 +120,19 @@ func testTPFilterRpcConn(t *testing.T) {
|
||||
}
|
||||
|
||||
func ttestTPFilterGetTPFilterBeforeSet(t *testing.T) {
|
||||
var reply *utils.TPFilter
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilter", &AttrGetTPFilter{TPid: "TP1", ID: "Filter"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
var reply *utils.TPFilterProfile
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilterProfile", &AttrGetTPFilterProfile{TPid: "TP1", ID: "Filter"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPFilterSetTPFilter(t *testing.T) {
|
||||
tpFilter = &utils.TPFilter{
|
||||
tpFilter = &utils.TPFilterProfile{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Filter",
|
||||
Filters: []*utils.TPRequestFilter{
|
||||
&utils.TPRequestFilter{
|
||||
Filters: []*utils.TPFilter{
|
||||
&utils.TPFilter{
|
||||
Type: "*string",
|
||||
FieldName: "Account",
|
||||
Values: []string{"1001", "1002"},
|
||||
@@ -145,7 +145,7 @@ func testTPFilterSetTPFilter(t *testing.T) {
|
||||
}
|
||||
|
||||
var result string
|
||||
if err := tpFilterRPC.Call("ApierV1.SetTPFilter", tpFilter, &result); err != nil {
|
||||
if err := tpFilterRPC.Call("ApierV1.SetTPFilterProfile", tpFilter, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
@@ -153,41 +153,39 @@ func testTPFilterSetTPFilter(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPFilterGetTPFilterAfterSet(t *testing.T) {
|
||||
var reply *utils.TPFilter
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilter", &AttrGetTPFilter{TPid: "TP1", ID: "Filter"}, &reply); err != nil {
|
||||
var reply *utils.TPFilterProfile
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilterProfile", &AttrGetTPFilterProfile{TPid: "TP1", ID: "Filter"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpFilter, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpFilter, reply)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testTPFilterGetFilterIds(t *testing.T) {
|
||||
var result []string
|
||||
expectedTPID := []string{"Filter"}
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilterIds", &AttrGetTPFilterIds{TPid: "TP1"}, &result); err != nil {
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilterProfileIds", &AttrGetTPFilterProfileIds{TPid: "TP1"}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedTPID, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testTPFilterUpdateTPFilter(t *testing.T) {
|
||||
tpFilter.Filters = []*utils.TPRequestFilter{
|
||||
&utils.TPRequestFilter{
|
||||
tpFilter.Filters = []*utils.TPFilter{
|
||||
&utils.TPFilter{
|
||||
Type: "*string",
|
||||
FieldName: "Account",
|
||||
Values: []string{"1001", "1002"},
|
||||
},
|
||||
&utils.TPRequestFilter{
|
||||
&utils.TPFilter{
|
||||
Type: "*string_prefix",
|
||||
FieldName: "Destination",
|
||||
Values: []string{"10", "20"},
|
||||
},
|
||||
}
|
||||
var result string
|
||||
if err := tpFilterRPC.Call("ApierV1.SetTPFilter", tpFilter, &result); err != nil {
|
||||
if err := tpFilterRPC.Call("ApierV1.SetTPFilterProfile", tpFilter, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
@@ -195,8 +193,8 @@ func testTPFilterUpdateTPFilter(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPFilterGetTPFilterAfterUpdate(t *testing.T) {
|
||||
var reply *utils.TPFilter
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilter", &AttrGetTPFilter{TPid: "TP1", ID: "Filter"}, &reply); err != nil {
|
||||
var reply *utils.TPFilterProfile
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilterProfile", &AttrGetTPFilterProfile{TPid: "TP1", ID: "Filter"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpFilter, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpFilter, reply)
|
||||
@@ -205,7 +203,7 @@ func testTPFilterGetTPFilterAfterUpdate(t *testing.T) {
|
||||
|
||||
func testTPFilterRemTPFilter(t *testing.T) {
|
||||
var resp string
|
||||
if err := tpFilterRPC.Call("ApierV1.RemTPFilter", &AttrRemTPFilter{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &resp); err != nil {
|
||||
if err := tpFilterRPC.Call("ApierV1.RemTPFilterProfile", &AttrRemTPFilterProfile{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.OK {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
@@ -213,8 +211,8 @@ func testTPFilterRemTPFilter(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPFilterGetTPFilterAfterRemove(t *testing.T) {
|
||||
var reply *utils.TPFilter
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilter", &AttrGetTPFilter{TPid: "TP1", ID: "Filter"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
var reply *utils.TPFilterProfile
|
||||
if err := tpFilterRPC.Call("ApierV1.GetTPFilterProfile", &AttrGetTPFilterProfile{TPid: "TP1", ID: "Filter"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// Creates a new Supplier within a tariff plan
|
||||
func (self *ApierV1) SetTPSupplierProfile(attrs utils.TPSupplier, reply *string) error {
|
||||
// Creates a new SupplierProfile within a tariff plan
|
||||
func (self *ApierV1) SetTPSupplierProfile(attrs utils.TPSupplierProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.SetTPSuppliers([]*utils.TPSupplier{&attrs}); err != nil {
|
||||
if err := self.StorDb.SetTPSuppliers([]*utils.TPSupplierProfile{&attrs}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
@@ -39,8 +39,8 @@ type AttrGetTPSupplierProfile struct {
|
||||
ID string // Filter id
|
||||
}
|
||||
|
||||
// Queries specific Supplier on tariff plan
|
||||
func (self *ApierV1) GetTPSupplierProfile(attr AttrGetTPSupplierProfile, reply *utils.TPSupplier) error {
|
||||
// Queries specific SupplierProfile on tariff plan
|
||||
func (self *ApierV1) GetTPSupplierProfile(attr AttrGetTPSupplierProfile, reply *utils.TPSupplierProfile) error {
|
||||
if missing := utils.MissingStructFields(&attr, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
@@ -55,13 +55,13 @@ func (self *ApierV1) GetTPSupplierProfile(attr AttrGetTPSupplierProfile, reply *
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrGetTPSupplierIDs struct {
|
||||
type AttrGetTPSupplierProfileIDs struct {
|
||||
TPid string // Tariff plan id
|
||||
utils.Paginator
|
||||
}
|
||||
|
||||
// Queries Supplier identities on specific tariff plan.
|
||||
func (self *ApierV1) GetTPSupplierProfileIDs(attrs AttrGetTPSupplierIDs, reply *[]string) error {
|
||||
// Queries SupplierProfile identities on specific tariff plan.
|
||||
func (self *ApierV1) GetTPSupplierProfileIDs(attrs AttrGetTPSupplierProfileIDs, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
@@ -76,14 +76,14 @@ func (self *ApierV1) GetTPSupplierProfileIDs(attrs AttrGetTPSupplierIDs, reply *
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrRemTPSupplier struct {
|
||||
type AttrRemTPSupplierProfile struct {
|
||||
TPid string // Tariff plan id
|
||||
Tenant string
|
||||
ID string // LCR id
|
||||
}
|
||||
|
||||
// Removes specific Supplier on Tariff plan
|
||||
func (self *ApierV1) RemTPSupplierProfile(attrs AttrRemTPSupplier, reply *string) error {
|
||||
// Removes specific SupplierProfile on Tariff plan
|
||||
func (self *ApierV1) RemTPSupplierProfile(attrs AttrRemTPSupplierProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ var (
|
||||
tpSplPrfCfg *config.CGRConfig
|
||||
tpSplPrfRPC *rpc.Client
|
||||
tpSplPrfDataDire = "/usr/share/cgrates"
|
||||
tpSplPr *utils.TPSupplier
|
||||
tpSplPr *utils.TPSupplierProfile
|
||||
tpSplPrfDelay int
|
||||
tpSplPrfConfigDIR string //run tests for specific configuration
|
||||
)
|
||||
@@ -120,7 +120,7 @@ func testTPSplPrfGetTPSplPrfBeforeSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPSplPrfSetTPSplPrf(t *testing.T) {
|
||||
tpSplPr = &utils.TPSupplier{
|
||||
tpSplPr = &utils.TPSupplierProfile{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SUPL_1",
|
||||
@@ -131,10 +131,11 @@ func testTPSplPrfSetTPSplPrf(t *testing.T) {
|
||||
},
|
||||
Sorting: "*lowest_cost",
|
||||
SortingParams: []string{},
|
||||
Suppliers: []*utils.TPRequestSupplier{
|
||||
&utils.TPRequestSupplier{
|
||||
Suppliers: []*utils.TPSupplier{
|
||||
&utils.TPSupplier{
|
||||
ID: "supplier1",
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
AccountIDs: []string{"Acc1", "Acc2"},
|
||||
RatingPlanIDs: []string{"RPL_1"},
|
||||
ResourceIDs: []string{"ResGroup1"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
@@ -152,18 +153,18 @@ func testTPSplPrfSetTPSplPrf(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPSplPrfGetTPSplPrfAfterSet(t *testing.T) {
|
||||
var reply *utils.TPSupplier
|
||||
var reply *utils.TPSupplierProfile
|
||||
if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpSplPr, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpSplPr, reply)
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpSplPr), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPSplPrfGetTPSplPrfIDs(t *testing.T) {
|
||||
var result []string
|
||||
expectedTPID := []string{"SUPL_1"}
|
||||
if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfileIDs", &AttrGetTPSupplierIDs{TPid: "TP1"}, &result); err != nil {
|
||||
if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfileIDs", &AttrGetTPSupplierProfileIDs{TPid: "TP1"}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedTPID, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
|
||||
@@ -172,17 +173,19 @@ func testTPSplPrfGetTPSplPrfIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPSplPrfUpdateTPSplPrf(t *testing.T) {
|
||||
tpSplPr.Suppliers = []*utils.TPRequestSupplier{
|
||||
&utils.TPRequestSupplier{
|
||||
tpSplPr.Suppliers = []*utils.TPSupplier{
|
||||
&utils.TPSupplier{
|
||||
ID: "supplier1",
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
AccountIDs: []string{"Acc1", "Acc2"},
|
||||
RatingPlanIDs: []string{"RPL_1"},
|
||||
ResourceIDs: []string{"ResGroup1"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
},
|
||||
&utils.TPRequestSupplier{
|
||||
&utils.TPSupplier{
|
||||
ID: "supplier2",
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
AccountIDs: []string{"Acc3"},
|
||||
RatingPlanIDs: []string{"RPL_1"},
|
||||
ResourceIDs: []string{"ResGroup1"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
@@ -197,17 +200,17 @@ func testTPSplPrfUpdateTPSplPrf(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPSplPrfGetTPSplPrfAfterUpdate(t *testing.T) {
|
||||
var reply *utils.TPSupplier
|
||||
var reply *utils.TPSupplierProfile
|
||||
if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpSplPr, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpSplPr, reply)
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpSplPr), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPSplPrfRemTPSplPrf(t *testing.T) {
|
||||
var resp string
|
||||
if err := tpSplPrfRPC.Call("ApierV1.RemTPSupplierProfile", &AttrRemTPSupplier{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"}, &resp); err != nil {
|
||||
if err := tpSplPrfRPC.Call("ApierV1.RemTPSupplierProfile", &AttrRemTPSupplierProfile{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.OK {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
@@ -215,7 +218,7 @@ func testTPSplPrfRemTPSplPrf(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPSplPrfGetTPSplPrfAfterRemove(t *testing.T) {
|
||||
var reply *utils.TPSupplier
|
||||
var reply *utils.TPSupplierProfile
|
||||
if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -1671,22 +1671,22 @@ func TestLoadAttributeProfiles(t *testing.T) {
|
||||
TPid: testTPID,
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ALS1",
|
||||
Context: "con1",
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: "2014-07-29T15:00:00Z",
|
||||
},
|
||||
Context: "con1",
|
||||
Attributes: []*utils.TPAttribute{
|
||||
&utils.TPAttribute{
|
||||
FieldName: "Field1",
|
||||
Initial: "Initial1",
|
||||
Substitute: "Alias1",
|
||||
Substitute: "Sub1",
|
||||
Append: true,
|
||||
},
|
||||
&utils.TPAttribute{
|
||||
FieldName: "Field2",
|
||||
Initial: "Initial2",
|
||||
Substitute: "Alias2",
|
||||
Substitute: "Sub2",
|
||||
Append: false,
|
||||
},
|
||||
},
|
||||
@@ -1696,8 +1696,18 @@ func TestLoadAttributeProfiles(t *testing.T) {
|
||||
resKey := utils.TenantID{Tenant: "cgrates.org", ID: "ALS1"}
|
||||
if len(csvr.attributeProfiles) != len(eAttrProfiles) {
|
||||
t.Errorf("Failed to load attributeProfiles: %s", utils.ToIJSON(csvr.attributeProfiles))
|
||||
} else if !reflect.DeepEqual(eAttrProfiles[resKey], csvr.attributeProfiles[resKey]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAttrProfiles[resKey], csvr.attributeProfiles[resKey])
|
||||
} else if !reflect.DeepEqual(eAttrProfiles[resKey].Tenant, csvr.attributeProfiles[resKey].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAttrProfiles[resKey].Tenant, csvr.attributeProfiles[resKey].Tenant)
|
||||
} else if !reflect.DeepEqual(eAttrProfiles[resKey].ID, csvr.attributeProfiles[resKey].ID) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAttrProfiles[resKey].ID, csvr.attributeProfiles[resKey].ID)
|
||||
} else if !reflect.DeepEqual(eAttrProfiles[resKey].Context, csvr.attributeProfiles[resKey].Context) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAttrProfiles[resKey].Context, csvr.attributeProfiles[resKey].Context)
|
||||
} else if !reflect.DeepEqual(eAttrProfiles[resKey].FilterIDs, csvr.attributeProfiles[resKey].FilterIDs) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAttrProfiles[resKey].FilterIDs, csvr.attributeProfiles[resKey].FilterIDs)
|
||||
} else if !reflect.DeepEqual(eAttrProfiles[resKey].ActivationInterval.ActivationTime, csvr.attributeProfiles[resKey].ActivationInterval.ActivationTime) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAttrProfiles[resKey].ActivationInterval, csvr.attributeProfiles[resKey].ActivationInterval)
|
||||
} else if !reflect.DeepEqual(eAttrProfiles[resKey].Attributes, csvr.attributeProfiles[resKey].Attributes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAttrProfiles[resKey].Attributes, csvr.attributeProfiles[resKey].Attributes)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1173,13 +1173,13 @@ func testOnStorITCacheSupplierProfile(t *testing.T) {
|
||||
}
|
||||
|
||||
func testOnStorITCacheAttributeProfile(t *testing.T) {
|
||||
mapSubstitutes := make(map[string]map[string]*AttributeSubstitute)
|
||||
mapSubstitutes["FN1"] = make(map[string]*AttributeSubstitute)
|
||||
mapSubstitutes["FN1"]["Init1"] = &AttributeSubstitute{
|
||||
FieldName: "FN1",
|
||||
Initial: "Init1",
|
||||
Alias: "Val1",
|
||||
Append: true,
|
||||
mapSubstitutes := make(map[string]map[string]*Attribute)
|
||||
mapSubstitutes["FN1"] = make(map[string]*Attribute)
|
||||
mapSubstitutes["FN1"]["Init1"] = &Attribute{
|
||||
FieldName: "FN1",
|
||||
Initial: "Init1",
|
||||
Substitute: "Val1",
|
||||
Append: true,
|
||||
}
|
||||
attrProfile := &AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -1188,9 +1188,9 @@ func testOnStorITCacheAttributeProfile(t *testing.T) {
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(),
|
||||
},
|
||||
Context: "con1",
|
||||
Substitutes: mapSubstitutes,
|
||||
Weight: 20,
|
||||
Context: "con1",
|
||||
Attributes: mapSubstitutes,
|
||||
Weight: 20,
|
||||
}
|
||||
if err := onStor.SetAttributeProfile(attrProfile); err != nil {
|
||||
t.Error(err)
|
||||
@@ -2543,13 +2543,13 @@ func testOnStorITCRUDSupplierProfile(t *testing.T) {
|
||||
}
|
||||
|
||||
func testOnStorITCRUDAttributeProfile(t *testing.T) {
|
||||
mapSubstitutes := make(map[string]map[string]*AttributeSubstitute)
|
||||
mapSubstitutes["FN1"] = make(map[string]*AttributeSubstitute)
|
||||
mapSubstitutes["FN1"]["Init1"] = &AttributeSubstitute{
|
||||
FieldName: "FN1",
|
||||
Initial: "Init1",
|
||||
Alias: "Val1",
|
||||
Append: true,
|
||||
mapSubstitutes := make(map[string]map[string]*Attribute)
|
||||
mapSubstitutes["FN1"] = make(map[string]*Attribute)
|
||||
mapSubstitutes["FN1"]["Init1"] = &Attribute{
|
||||
FieldName: "FN1",
|
||||
Initial: "Init1",
|
||||
Substitute: "Val1",
|
||||
Append: true,
|
||||
}
|
||||
attrProfile := &AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -2558,9 +2558,9 @@ func testOnStorITCRUDAttributeProfile(t *testing.T) {
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(),
|
||||
},
|
||||
Context: "con1",
|
||||
Substitutes: mapSubstitutes,
|
||||
Weight: 20,
|
||||
Context: "con1",
|
||||
Attributes: mapSubstitutes,
|
||||
Weight: 20,
|
||||
}
|
||||
if _, rcvErr := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
|
||||
Reference in New Issue
Block a user