diff --git a/apier/v1/alias_it_test.go b/apier/v1/alias_it_test.go index c6c9fcc58..cd14ab106 100644 --- a/apier/v1/alias_it_test.go +++ b/apier/v1/alias_it_test.go @@ -151,8 +151,14 @@ func testAlsPrfSetAlsPrf(t *testing.T) { var reply *engine.ExternalAliasProfile if err := alsPrfRPC.Call("ApierV1.GetAliasProfile", &utils.TenantID{Tenant: "cgrates.org", ID: "ALS1"}, &reply); err != nil { t.Error(err) - } else if !reflect.DeepEqual(alsPrf, reply) { - t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf), utils.ToJSON(reply)) + } else if !reflect.DeepEqual(alsPrf.FilterIDs, reply.FilterIDs) { + 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.Aliases), len(reply.Aliases)) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Aliases), utils.ToJSON(reply.Aliases)) + } else if !reflect.DeepEqual(alsPrf.ID, reply.ID) { + t.Errorf("Expecting : %+v, received: %+v", alsPrf.ID, reply.ID) } } @@ -178,8 +184,14 @@ func testAlsPrfUpdateAlsPrf(t *testing.T) { var reply *engine.ExternalAliasProfile if err := alsPrfRPC.Call("ApierV1.GetAliasProfile", &utils.TenantID{Tenant: "cgrates.org", ID: "ALS1"}, &reply); err != nil { t.Error(err) - } else if !reflect.DeepEqual(alsPrf, reply) { - t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf), utils.ToJSON(reply)) + } else if !reflect.DeepEqual(alsPrf.FilterIDs, reply.FilterIDs) { + 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.Aliases), len(reply.Aliases)) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Aliases), utils.ToJSON(reply.Aliases)) + } else if !reflect.DeepEqual(alsPrf.ID, reply.ID) { + t.Errorf("Expecting : %+v, received: %+v", alsPrf.ID, reply.ID) } } diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index db2709966..2e53c39c8 100755 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -1059,3 +1059,118 @@ func TestFilterToTPFilter(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", tpfilter, eTPFilter) } } + +func TestAPItoAliasProfile(t *testing.T) { + tpAlsPrf := &utils.TPAlias{ + TPid: "TP1", + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.TPActivationInterval{ + ActivationTime: "2014-07-14T14:35:00Z", + ExpiryTime: "", + }, + Aliases: []*utils.TPAliasEntry{ + &utils.TPAliasEntry{ + FieldName: "FL1", + Initial: "In1", + Alias: "Al1", + }, + }, + Weight: 20, + } + alsMap := make(map[string]map[string]string) + alsMap["FL1"] = make(map[string]string) + alsMap["FL1"]["In1"] = "Al1" + expected := &AliasProfile{ + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), + }, + Aliases: alsMap, + Weight: 20, + } + if rcv, err := APItoAliasProfile(tpAlsPrf, "UTC"); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expected, rcv) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv)) + } +} + +func TestAPItoModelTPAlias(t *testing.T) { + tpAlsPrf := &utils.TPAlias{ + TPid: "TP1", + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.TPActivationInterval{ + ActivationTime: "2014-07-14T14:35:00Z", + ExpiryTime: "", + }, + Aliases: []*utils.TPAliasEntry{ + &utils.TPAliasEntry{ + FieldName: "FL1", + Initial: "In1", + Alias: "Al1", + }, + }, + Weight: 20, + } + expected := TPAliases{ + &TPAlias{ + Tpid: "TP1", + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: "FLTR_ACNT_dan;FLTR_DST_DE", + FieldName: "FL1", + Initial: "In1", + Alias: "Al1", + ActivationInterval: "2014-07-14T14:35:00Z", + Weight: 20, + }, + } + rcv := APItoModelTPAlias(tpAlsPrf) + if !reflect.DeepEqual(expected, rcv) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv)) + } +} + +func TestModelAsTPAlias(t *testing.T) { + model := TPAliases{ + &TPAlias{ + Tpid: "TP1", + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: "FLTR_ACNT_dan;FLTR_DST_DE", + FieldName: "FL1", + Initial: "In1", + Alias: "Al1", + ActivationInterval: "2014-07-14T14:35:00Z", + Weight: 20, + }, + } + expected := &utils.TPAlias{ + TPid: "TP1", + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.TPActivationInterval{ + ActivationTime: "2014-07-14T14:35:00Z", + ExpiryTime: "", + }, + Aliases: []*utils.TPAliasEntry{ + &utils.TPAliasEntry{ + FieldName: "FL1", + Initial: "In1", + Alias: "Al1", + }, + }, + Weight: 20, + } + rcv := model.AsTPAlias() + if !reflect.DeepEqual(expected, rcv[0]) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv[0])) + } +}