diff --git a/engine/attributes_test.go b/engine/attributes_test.go index 7eee2c524..b2f2c2fca 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -1297,3 +1297,168 @@ func TestAttributesParseAttributeSIPCIDInvalidArguments(t *testing.T) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } } + +// func TestAttributesV1ProcessEventMultipleRuns1(t *testing.T) { +// tmp := Cache +// defer func() { +// Cache = tmp +// }() + +// cfg := config.NewDefaultCGRConfig() +// cfg.AttributeSCfg().IndexedSelects = false +// data := NewInternalDB(nil, nil, true) +// dm := NewDataManager(data, cfg.CacheCfg(), nil) +// filterS := NewFilterS(cfg, nil, dm) +// Cache = NewCacheS(cfg, dm, nil) +// alS := NewAttributeService(dm, filterS, cfg) + +// postpaid := config.NewRSRParsersMustCompile(utils.MetaPostpaid, utils.InfieldSep) +// pw := config.NewRSRParsersMustCompile("CGRateS.org", utils.InfieldSep) + +// ap1 := &AttributeProfile{ +// Tenant: "cgrates.org", +// ID: "ATTR1", +// FilterIDs: []string{"*notexists:~*vars.*processedProfileIDs[<~*vars.apTenantID>]:"}, +// Contexts: []string{utils.MetaSessionS}, +// Attributes: []*Attribute{ +// { +// Path: "*req.Password", +// Type: utils.MetaConstant, +// Value: pw, +// }, +// }, +// Weight: 10, +// } +// err = alS.dm.SetAttributeProfile(ap1, true) +// if err != nil { +// t.Error(err) +// } + +// ap2 := &AttributeProfile{ +// Tenant: "cgrates.org", +// ID: "ATTR2", +// Contexts: []string{utils.MetaAny}, +// Attributes: []*Attribute{ +// { +// Path: "*req.RequestType", +// Type: utils.MetaConstant, +// Value: postpaid, +// }, +// }, +// Weight: 20, +// } +// err = alS.dm.SetAttributeProfile(ap2, true) +// if err != nil { +// t.Error(err) +// } + +// args := &AttrArgsProcessEvent{ +// AttributeIDs: []string{"ATTR1", "ATTR2"}, +// Context: utils.StringPointer(utils.MetaAny), +// ProcessRuns: utils.IntPointer(3), +// CGREvent: &utils.CGREvent{ +// Tenant: "cgrates.org", +// ID: "AttrProcessEventMultipleRuns", +// Event: map[string]interface{}{ +// utils.Password: "passwd", +// }, +// }, +// } +// reply := &AttrSProcessEventReply{} + +// if err := alS.V1ProcessEvent(args, reply); err != nil { +// t.Error(err) +// } +// fmt.Println(utils.ToJSON(reply)) +// } + +// func TestAttributesV1ProcessEventMultipleRuns2(t *testing.T) { +// tmp := Cache +// defer func() { +// Cache = tmp +// }() + +// cfg := config.NewDefaultCGRConfig() +// cfg.AttributeSCfg().IndexedSelects = false +// data := NewInternalDB(nil, nil, true) +// dm := NewDataManager(data, cfg.CacheCfg(), nil) +// filterS := NewFilterS(cfg, nil, dm) +// Cache = NewCacheS(cfg, dm, nil) +// alS := NewAttributeService(dm, filterS, cfg) + +// postpaid := config.NewRSRParsersMustCompile(utils.MetaPostpaid, utils.InfieldSep) +// pw := config.NewRSRParsersMustCompile("CGRateS.org", utils.InfieldSep) +// paypal := config.NewRSRParsersMustCompile("cgrates@paypal.com", utils.InfieldSep) + +// ap1 := &AttributeProfile{ +// Tenant: "cgrates.org", +// ID: "ATTR1", +// Contexts: []string{utils.MetaAny}, +// Attributes: []*Attribute{ +// { +// Path: "*req.Password", +// Type: utils.MetaConstant, +// Value: pw, +// }, +// }, +// Weight: 10, +// } +// err = alS.dm.SetAttributeProfile(ap1, true) +// if err != nil { +// t.Error(err) +// } + +// ap2 := &AttributeProfile{ +// Tenant: "cgrates.org", +// ID: "ATTR2", +// FilterIDs: []string{"*exists:~*vars.*processedProfileIDs[cgrates.org:ATTR1]:"}, +// Contexts: []string{utils.MetaAny}, +// Attributes: []*Attribute{ +// { +// Path: "*req.RequestType", +// Type: utils.MetaConstant, +// Value: postpaid, +// }, +// }, +// Weight: 20, +// } +// err = alS.dm.SetAttributeProfile(ap2, true) +// if err != nil { +// t.Error(err) +// } + +// ap3 := &AttributeProfile{ +// Tenant: "cgrates.org", +// ID: "ATTR3", +// FilterIDs: []string{"*exists:~*vars.*processedProfileIDs[cgrates.org:ATTR2]:"}, +// Contexts: []string{utils.MetaAny}, +// Attributes: []*Attribute{ +// { +// Path: "*req.PaypalAccount", +// Type: utils.MetaConstant, +// Value: paypal, +// }, +// }, +// Weight: 30, +// } +// err = alS.dm.SetAttributeProfile(ap3, true) +// if err != nil { +// t.Error(err) +// } + +// args := &AttrArgsProcessEvent{ +// Context: utils.StringPointer(utils.MetaAny), +// ProcessRuns: utils.IntPointer(3), +// CGREvent: &utils.CGREvent{ +// Tenant: "cgrates.org", +// ID: "AttrProcessEventMultipleRuns", +// Event: map[string]interface{}{}, +// }, +// } +// reply := &AttrSProcessEventReply{} + +// if err := alS.V1ProcessEvent(args, reply); err != nil { +// t.Error(err) +// } +// fmt.Println(utils.ToJSON(reply)) +// } diff --git a/engine/libattributes_test.go b/engine/libattributes_test.go index 51f44b974..6a78d5b8d 100644 --- a/engine/libattributes_test.go +++ b/engine/libattributes_test.go @@ -216,3 +216,31 @@ func TestNewAttributeFromInlineWithMultipleVaslues(t *testing.T) { t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expAttrPrf1), utils.ToJSON(attr)) } } + +func TestLibAttributesTenantIDInLine(t *testing.T) { + ap := &AttributeProfile{ + Tenant: "cgrates.org", + ID: "AttrPrf", + Contexts: []string{utils.MetaAny}, + Weight: 10, + } + + exp := "cgrates.org:AttrPrf" + if rcv := ap.TenantIDInline(); rcv != exp { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv) + } +} + +func TestLibAttributesTenantIDMetaPrefix(t *testing.T) { + ap := &AttributeProfile{ + Tenant: "cgrates.org", + ID: "*default", + Contexts: []string{utils.MetaAny}, + Weight: 10, + } + + exp := "*default" + if rcv := ap.TenantIDInline(); rcv != exp { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv) + } +}