mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Add attribute test(Substitute take value from Header)
This commit is contained in:
committed by
Dan Christian Bogos
parent
cf566042e2
commit
6a73a7cf2c
@@ -57,6 +57,7 @@ var sTestsAlsPrf = []func(t *testing.T){
|
||||
testAttributeSProcessEventWithNoneSubstitute,
|
||||
testAttributeSProcessEventWithNoneSubstitute2,
|
||||
testAttributeSProcessEventWithNoneSubstitute3,
|
||||
testAttributeSProcessEventWithHeader,
|
||||
testAttributeSGetAlsPrfBeforeSet,
|
||||
testAttributeSSetAlsPrf,
|
||||
testAttributeSUpdateAlsPrf,
|
||||
@@ -553,6 +554,66 @@ func testAttributeSProcessEventWithNoneSubstitute3(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testAttributeSProcessEventWithHeader(t *testing.T) {
|
||||
attrPrf1 := &engine.AttributeProfile{
|
||||
Tenant: config.CgrConfig().DefaultTenant,
|
||||
ID: "ATTR_Header",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"*string:Field1:Value1"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
&engine.Attribute{
|
||||
FieldName: "Field2",
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: utils.NewRSRParsersMustCompile("~Field1", true),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Blocker: true,
|
||||
Weight: 10,
|
||||
}
|
||||
var result string
|
||||
if err := attrSRPC.Call("ApierV1.SetAttributeProfile", attrPrf1, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
attrArgs := &engine.AttrArgsProcessEvent{
|
||||
ProcessRuns: utils.IntPointer(1),
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: config.CgrConfig().DefaultTenant,
|
||||
ID: "HeaderEventForAttribute",
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
"Field1": "Value1",
|
||||
},
|
||||
},
|
||||
}
|
||||
eRply := &engine.AttrSProcessEventReply{
|
||||
MatchedProfiles: []string{"ATTR_Header"},
|
||||
AlteredFields: []string{"Field2"},
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: config.CgrConfig().DefaultTenant,
|
||||
ID: "HeaderEventForAttribute",
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
"Field1": "Value1",
|
||||
"Field2": "Value1",
|
||||
},
|
||||
},
|
||||
}
|
||||
var rplyEv engine.AttrSProcessEventReply
|
||||
if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
|
||||
attrArgs, &rplyEv); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eRply, &rplyEv) {
|
||||
t.Errorf("Expecting: %s, received: %s",
|
||||
utils.ToJSON(eRply), utils.ToJSON(rplyEv))
|
||||
}
|
||||
}
|
||||
|
||||
func testAttributeSSetAlsPrf(t *testing.T) {
|
||||
alsPrf = &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
|
||||
@@ -1195,3 +1195,75 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.CGREvent.Event, reply.CGREvent.Event)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttributeProcessSubstitute(t *testing.T) {
|
||||
//refresh the DM
|
||||
if err := dmAtr.DataDB().Flush(""); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if test, err := dmAtr.DataDB().IsDBEmpty(); err != nil {
|
||||
t.Error(err)
|
||||
} else if test != true {
|
||||
t.Errorf("\nExpecting: true got :%+v", test)
|
||||
}
|
||||
attrPrf1 := &AttributeProfile{
|
||||
Tenant: config.CgrConfig().DefaultTenant,
|
||||
ID: "ATTR_1",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"*string:Field1:Value1"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*Attribute{
|
||||
&Attribute{
|
||||
FieldName: "Field2",
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: utils.NewRSRParsersMustCompile("~Field1", true),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Blocker: true,
|
||||
Weight: 10,
|
||||
}
|
||||
// Add attribute in DM
|
||||
if err := dmAtr.SetAttributeProfile(attrPrf1, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
attrArgs := &AttrArgsProcessEvent{
|
||||
ProcessRuns: utils.IntPointer(1),
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: config.CgrConfig().DefaultTenant,
|
||||
ID: utils.GenUUID(),
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
"Field1": "Value1",
|
||||
},
|
||||
},
|
||||
}
|
||||
eRply := &AttrSProcessEventReply{
|
||||
MatchedProfiles: []string{"ATTR_1"},
|
||||
AlteredFields: []string{"Field2"},
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: config.CgrConfig().DefaultTenant,
|
||||
ID: utils.GenUUID(),
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
"Field1": "Value1",
|
||||
"Field2": "Value1",
|
||||
},
|
||||
},
|
||||
}
|
||||
var reply AttrSProcessEventReply
|
||||
if err := attrService.V1ProcessEvent(attrArgs, &reply); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles)
|
||||
}
|
||||
if !reflect.DeepEqual(eRply.AlteredFields, reply.AlteredFields) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, reply.AlteredFields)
|
||||
}
|
||||
if !reflect.DeepEqual(eRply.CGREvent.Event, reply.CGREvent.Event) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.CGREvent.Event, reply.CGREvent.Event)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user