Пример #1
0
func TestLoadIndividualProfiles(t *testing.T) {
	if !*testLocal {
		return
	}
	loader := NewDbReader(storDb, ratingDbApier, accountDbApier, TEST_SQL)
	// Load ratingPlans. This will also set destination keys
	if ratingPlans, err := storDb.GetTpRatingPlans(TEST_SQL, ""); err != nil {
		t.Fatal("Could not retrieve rating plans")
	} else {
		for tag := range ratingPlans {
			if loaded, err := loader.LoadRatingPlanByTag(tag); err != nil {
				t.Fatalf("Could not load ratingPlan for tag: %s, error: %s", tag, err.Error())
			} else if !loaded {
				t.Fatal("Cound not find ratingPLan with id:", tag)
			}
		}
	}
	// Load rating profiles
	loadId := utils.CSV_LOAD + "_" + TEST_SQL
	if ratingProfiles, err := storDb.GetTpRatingProfiles(&utils.TPRatingProfile{TPid: TEST_SQL, LoadId: loadId}); err != nil {
		t.Fatal("Could not retrieve rating profiles, error: ", err.Error())
	} else if len(ratingProfiles) == 0 {
		t.Fatal("Could not retrieve rating profiles")
	} else {
		for rpId := range ratingProfiles {
			rp, _ := utils.NewTPRatingProfileFromKeyId(TEST_SQL, loadId, rpId)
			if err := loader.LoadRatingProfileFiltered(rp); err != nil {
				t.Fatalf("Could not load ratingProfile with id: %s, error: %s", rpId, err.Error())
			}
		}
	}
	// Load account actions
	if aas, err := storDb.GetTpAccountActions(&utils.TPAccountActions{TPid: TEST_SQL, LoadId: loadId}); err != nil {
		t.Fatal("Could not retrieve account action profiles, error: ", err.Error())
	} else if len(aas) == 0 {
		t.Error("No account actions")
	} else {
		for aaId := range aas {
			aa, _ := utils.NewTPAccountActionsFromKeyId(TEST_SQL, loadId, aaId)
			if err := loader.LoadAccountActionsFiltered(aa); err != nil {
				t.Fatalf("Could not load account actions with id: %s, error: %s", aaId, err.Error())
			}
		}
	}
}
Пример #2
0
func TestLoadIndividualProfiles(t *testing.T) {
	if !*testLocal {
		return
	}
	loader := NewTpReader(ratingDbApier, accountDbApier, storDb, utils.TEST_SQL, "")
	// Load ratingPlans. This will also set destination keys
	if ratingPlans, err := storDb.GetTpRatingPlans(utils.TEST_SQL, "", nil); err != nil {
		t.Fatal("Could not retrieve rating plans")
	} else {
		rpls, err := TpRatingPlans(ratingPlans).GetRatingPlans()
		if err != nil {
			t.Fatal("Could not convert rating plans")
		}
		for tag := range rpls {
			if loaded, err := loader.LoadRatingPlansFiltered(tag); err != nil {
				t.Fatalf("Could not load ratingPlan for tag: %s, error: %s", tag, err.Error())
			} else if !loaded {
				t.Fatal("Cound not find ratingPLan with id:", tag)
			}
		}
	}
	// Load rating profiles
	loadId := utils.CSV_LOAD + "_" + utils.TEST_SQL
	if ratingProfiles, err := storDb.GetTpRatingProfiles(&TpRatingProfile{Tpid: utils.TEST_SQL, Loadid: loadId}); err != nil {
		t.Fatal("Could not retrieve rating profiles, error: ", err.Error())
	} else if len(ratingProfiles) == 0 {
		t.Fatal("Could not retrieve rating profiles")
	} else {
		rpfs, err := TpRatingProfiles(ratingProfiles).GetRatingProfiles()
		if err != nil {
			t.Fatal("Could not convert rating profiles")
		}
		for rpId := range rpfs {
			rp, _ := utils.NewTPRatingProfileFromKeyId(utils.TEST_SQL, loadId, rpId)
			mrp := APItoModelRatingProfile(rp)
			if err := loader.LoadRatingProfilesFiltered(&mrp[0]); err != nil {
				t.Fatalf("Could not load ratingProfile with id: %s, error: %s", rpId, err.Error())
			}
		}
	}
	// Load derived chargers
	loadId = utils.CSV_LOAD + "_" + utils.TEST_SQL
	if derivedChargers, err := storDb.GetTpDerivedChargers(&TpDerivedCharger{Tpid: utils.TEST_SQL, Loadid: loadId}); err != nil {
		t.Fatal("Could not retrieve derived chargers, error: ", err.Error())
	} else if len(derivedChargers) == 0 {
		t.Fatal("Could not retrieve derived chargers")
	} else {
		dcs, err := TpDerivedChargers(derivedChargers).GetDerivedChargers()
		if err != nil {
			t.Fatal("Could not convert derived chargers")
		}
		for dcId := range dcs {
			mdc := &TpDerivedCharger{Tpid: utils.TEST_SQL, Loadid: loadId}
			mdc.SetDerivedChargersId(dcId)
			if err := loader.LoadDerivedChargersFiltered(mdc, true); err != nil {
				t.Fatalf("Could not load derived charger with id: %s, error: %s", dcId, err.Error())
			}
		}
	}
	// Load cdr stats
	//loadId = utils.CSV_LOAD + "_" + utils.TEST_SQL
	if cdrStats, err := storDb.GetTpCdrStats(utils.TEST_SQL, ""); err != nil {
		t.Fatal("Could not retrieve cdr stats, error: ", err.Error())
	} else if len(cdrStats) == 0 {
		t.Fatal("Could not retrieve cdr stats")
	} else {
		cds, err := TpCdrStats(cdrStats).GetCdrStats()
		if err != nil {
			t.Fatal("Could not convert cdr stats")
		}
		for id := range cds {
			if err := loader.LoadCdrStatsFiltered(id, true); err != nil {
				t.Fatalf("Could not load cdr stats with id: %s, error: %s", id, err.Error())
			}
		}
	}
	// Load users
	if users, err := storDb.GetTpUsers(&TpUser{Tpid: utils.TEST_SQL}); err != nil {
		t.Fatal("Could not retrieve users, error: ", err.Error())
	} else if len(users) == 0 {
		t.Fatal("Could not retrieve users")
	} else {
		for _, usr := range users {
			if found, err := loader.LoadUsersFiltered(&usr); found && err != nil {
				t.Fatalf("Could not user with id: %s, error: %s", usr.GetId(), err.Error())
			}
		}
	}
	// Load aliases
	if aliases, err := storDb.GetTpAliases(&TpAlias{Tpid: utils.TEST_SQL}); err != nil {
		t.Fatal("Could not retrieve aliases, error: ", err.Error())
	} else if len(aliases) == 0 {
		t.Fatal("Could not retrieve aliases")
	} else {
		for _, al := range aliases {
			if found, err := loader.LoadAliasesFiltered(&al); found && err != nil {
				t.Fatalf("Could not load aliase with id: %s, error: %s", al.GetId(), err.Error())
			}
		}
	}
	// Load account actions
	if accountActions, err := storDb.GetTpAccountActions(&TpAccountAction{Tpid: utils.TEST_SQL, Loadid: loadId}); err != nil {
		t.Fatal("Could not retrieve account action profiles, error: ", err.Error())
	} else if len(accountActions) == 0 {
		t.Error("No account actions")
	} else {
		aas, err := TpAccountActions(accountActions).GetAccountActions()
		if err != nil {
			t.Fatal("Could not convert account actions")
		}
		for aaId := range aas {
			aa, _ := utils.NewTPAccountActionsFromKeyId(utils.TEST_SQL, loadId, aaId)
			maa := APItoModelAccountAction(aa)

			if err := loader.LoadAccountActionsFiltered(maa); err != nil {
				t.Fatalf("Could not load account actions with id: %s, error: %s", aaId, err.Error())
			}
		}
	}
}