TT#78651 migrate to new KEMI interface

We are going to use both modules app_lua and app_lua_sr until we
solve the missing pieces on KEMI:

* KSR.pvx.xavp_get() returns a string like '<<xavp:%p>>' not a table like
  sr.xavp.get()
* KEMI lacks of something like sr.xavp.get_keys() funtion

So, migrate everything that we can to KEMI and keep using sr approach
for just that two cases

- mocks/sr.lua: use same objects for same behaviour

Change-Id: I475ff8f820586cdc94c75bff7466238215e05673
changes/34/38934/7
Victor Seva 6 years ago
parent 27d34829b3
commit dc1ba69f3f

1
.gitignore vendored

@ -1,3 +1,4 @@
*~
kamailio
reports
*.pyc

@ -0,0 +1,74 @@
--
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This package is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- .
-- On Debian systems, the complete text of the GNU General
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
local logging = require ('logging')
local log_file = require ('logging.file')
local lemock = require ('lemock')
local hdrMock = require 'mocks.hdr'
local pvMock = require 'mocks.pv'
local pvxMock = require 'mocks.pvx'
-- class srMock
local ksrMock = {
__class__ = 'ksrMock',
_logger = log_file("reports/ksr_%s.log", "%Y-%m-%d"),
_logger_levels = {
dbg = logging.DEBUG,
info = logging.INFO,
warn = logging.WARN,
err = logging.ERROR,
crit = logging.FATAL
}
}
local ksrMock_MT = { __index = ksrMock, __newindex = lemock.controller():mock() }
function ksrMock.new()
local t = {}
t.hdr = hdrMock.new()
t.pv = pvMock.new(t.hdr)
function t.log(level, message)
if not t._logger_levels[level] then
error(string.format("level %s unknown", tostring(level)))
end
t._logger:log(t._logger_levels[level], message)
end
function t.dbg(message)
t._logger:log(logging.DEBUG, message)
end
function t.err(message)
t._logger:log(logging.ERROR, message)
end
function t.info(message)
t._logger:log(logging.INFO, message)
end
function t.notice(message)
t._logger:log(logging.INFO, message)
end
function t.warn(message)
t._logger:log(logging.WARN, message)
end
function t.crit(message)
t._logger:log(logging.FATAL, message)
end
t.pvx = pvxMock.new(t.pv)
setmetatable(t, ksrMock_MT)
return t
end
-- end class
return ksrMock

@ -308,7 +308,7 @@ local pvMock = {
local result = t._is(id)
if result.clean then
-- clean var
t.log("dbg",string.format("sr.pv erase avp[%s]", result.id))
t.log("dbg",string.format("KSR.pv erase avp[%s]", result.id))
t.vars[result.private_id] = nil
end
if not t.vars[result.private_id] then
@ -316,7 +316,7 @@ local pvMock = {
else
t._addvalue_with_value(result, value)
end
t.log("dbg", string.format("sr.pv vars:%s", utable.tostring(t.vars)))
t.log("dbg", string.format("KSR.pv vars:%s", utable.tostring(t.vars)))
end
function t.seti(id, value)
@ -366,7 +366,7 @@ local pvMock = {
elseif result.type == 'var' or result.type == 'dlg_var' then
t.vars[result.private_id] = nil
end
t.log("dbg", string.format("sr.pv vars:%s", utable.tostring(t.vars)))
t.log("dbg", string.format("KSR.pv vars:%s", utable.tostring(t.vars)))
end
function t.is_null(id)

@ -0,0 +1,74 @@
--
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This package is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- .
-- On Debian systems, the complete text of the GNU General
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
local logging = require ('logging')
local log_file = require ('logging.file')
-- class pvxMock
local pvxMock = {
__class__ = 'pvxMock',
_logger = log_file("reports/pvx_%s.log", "%Y-%m-%d"),
_logger_levels = {
dbg = logging.DEBUG,
info = logging.INFO,
warn = logging.WARN,
err = logging.ERROR,
crit = logging.FATAL
}
}
function pvxMock.new(pv)
local t = {}
t.__class__ = 'pvxMock'
t.pv = pv
function t._get_xavp(xavp_name, mode)
local private_id = "xavp:" .. xavp_name
if not t.pv.vars[private_id] then
if mode == "NULL_NONE" then
return nil
elseif mode == "NULL_EMPTY" then
return ""
elseif mode == "NULL_PRINT" then
return "<null>"
end
else
local s = tostring(t.pv.vars[private_id])
return "<<xavp:"..s:sub(8)..">>"
end
end
function t.xavp_get(xavp_name)
return t._get_xavp(xavp_name, "NULL_NONE")
end
function t.xavp_gete(xavp_name)
return t._get_xavp(xavp_name, "NULL_EMPTY")
end
function t.xavp_getw(xavp_name)
return t._get_xavp(xavp_name, "NULL_PRINT")
end
local pvxMock_MT = { __index = pvxMock }
setmetatable(t, pvxMock_MT)
return t
end
--end class
return pvxMock

@ -38,10 +38,10 @@ local srMock = {
}
}
local srMock_MT = { __index = srMock, __newindex = lemock.controller():mock() }
function srMock.new()
function srMock.new(ksr)
local t = {}
t.hdr = hdrMock.new()
t.pv = pvMock.new(t.hdr)
t.hdr = ksr.hdr
t.pv = ksr.pv
function t.log(level, message)
if not t._logger_levels[level] then
error(string.format("level %s unknown", tostring(level)))

@ -35,7 +35,7 @@ local xavpMock = {
function xavpMock.new(pv)
local t = {}
t.__class__ = 'hdrMock'
t.__class__ = 'xavpMock'
t.pv = pv
function t._get_xavp(xavp_name, index, mode)
@ -44,7 +44,8 @@ local xavpMock = {
if not t.pv.vars[private_id] then
error(string.format("%s not found", xavp_name))
elseif not t.pv.vars[private_id][index] then
error(string.format("%s[%d] not found", xavp_name, index))
error(string.format("%s[%s] not found",
xavp_name, tostring(index)))
end
if mode == 0 then
for k,v in pairs(t.pv.vars[private_id][index]) do

@ -1,2 +1,2 @@
globals = {'sr', '_ENV'}
globals = {'KSR', '_ENV'}
ignore = { '212' }

@ -34,15 +34,15 @@ local NGCPAvp_MT = {
}
NGCPAvp_MT.__call = function(s, value)
if not value then
return sr.pv.get(s.id)
return KSR.pv.get(s.id)
elseif type(value) == "table" then
for i = #value, 1, -1 do
s(value[i])
end
elseif type(value) == "number" then
sr.pv.seti(s.id, value)
KSR.pv.seti(s.id, value)
elseif type(value) == "string" then
sr.pv.sets(s.id, value)
KSR.pv.sets(s.id, value)
else
error("value is not a number or string")
end
@ -52,17 +52,17 @@ local NGCPAvp_MT = {
local indx = 0
local res = {}
val = sr.pv.get(string.format(t.id_indx, indx))
val = KSR.pv.get(string.format(t.id_indx, indx))
if not val then return nil end
while val do
table.insert(res, val)
indx = indx + 1
val = sr.pv.get(string.format(t.id_indx, indx))
val = KSR.pv.get(string.format(t.id_indx, indx))
end
return res
end
NGCPAvp_MT.__tostring = function(s)
local value = sr.pv.get(s.id)
local value = KSR.pv.get(s.id)
return string.format("%s:%s", s.id, tostring(value))
end
return setmetatable( t, NGCPAvp_MT )
@ -72,13 +72,13 @@ local NGCPAvp_MT = {
if not level then
level = "dbg"
end
sr.log(level, tostring(self))
KSR.log(level, tostring(self))
end
function NGCPAvp:del(value)
local values = self.all()
if not values or not value then return end
sr.pv.unset(self.id_all)
KSR.pv.unset(self.id_all)
for i = #values, 1, -1 do
if values[i] ~= value then
self(values[i])
@ -87,7 +87,7 @@ local NGCPAvp_MT = {
end
function NGCPAvp:clean()
sr.pv.unset(self.id_all)
KSR.pv.unset(self.id_all)
end
-- class
return NGCPAvp

@ -97,11 +97,11 @@ local NGCPConfig_MT = { __index = NGCPConfig }
local ok,_ = pcall(check_connection, self.con)
if not ok then
self.con = nil
sr.log("dbg", "lost database connection. Reconnecting")
KSR.log("dbg", "lost database connection. Reconnecting")
end
end
if not self.con then
sr.log("dbg","connecting to mysql")
KSR.log("dbg","connecting to mysql")
self.con = self.env:connect( self.db_database,
self.db_username, self.db_pass, self.db_host, self.db_port)
end

@ -136,7 +136,7 @@ NGCPContractPrefs_MT.__tostring = function ()
row = cur:fetch({}, "a")
end
else
sr.log("dbg", string.format("no results for query:%s", query))
KSR.log("dbg", string.format("no results for query:%s", query))
end
cur:close()

@ -30,18 +30,18 @@ function NGCPDlgVar:new(id)
NGCPDlgVar_MT.__call = function(s, value)
if not value then
return sr.pv.get(s.id)
return KSR.pv.get(s.id)
elseif type(value) == "number" then
sr.pv.seti(s.id, value)
KSR.pv.seti(s.id, value)
elseif type(value) == "string" then
sr.pv.sets(s.id, value)
KSR.pv.sets(s.id, value)
else
error("value is not a number or string")
end
end
NGCPDlgVar_MT.__tostring = function(s)
local value = sr.pv.get(s.id)
local value = KSR.pv.get(s.id)
return string.format("%s:%s", s.id, tostring(value))
end
return setmetatable( t, NGCPDlgVar_MT )
@ -51,11 +51,11 @@ function NGCPDlgVar:log(level)
if not level then
level = "dbg"
end
sr.log(level, tostring(self))
KSR.log(level, tostring(self))
end
function NGCPDlgVar:clean()
sr.pv.unset(self.id)
KSR.pv.unset(self.id)
end
return NGCPDlgVar

@ -72,7 +72,7 @@ end
function NGCPDlgCounters._connect(config)
local client = redis.connect(config.host,config.port);
client:select(config.db);
sr.log("dbg", string.format("connected to redis server %s:%d at %s\n",
KSR.log("dbg", string.format("connected to redis server %s:%d at %s\n",
config.host, config.port, config.db));
return client;
end
@ -81,12 +81,12 @@ end
local res = self.central:decr(key);
if res == 0 then
self.central:del(key);
sr.log("dbg", string.format("central:del[%s] counter is 0\n", key));
KSR.log("dbg", string.format("central:del[%s] counter is 0\n", key));
elseif res < 0 and not self.config.allow_negative then
self.central:del(key);
sr.log("warn", string.format("central:del[%s] counter was %s\n", key, tostring(res)));
KSR.log("warn", string.format("central:del[%s] counter was %s\n", key, tostring(res)));
else
sr.log("dbg", string.format("central:decr[%s]=>[%s]\n", key, tostring(res)));
KSR.log("dbg", string.format("central:decr[%s]=>[%s]\n", key, tostring(res)));
end
return res;
end
@ -116,15 +116,15 @@ end
self.central = self._connect(self.config.central);
end
local res = self.central:incr(key);
sr.log("dbg", string.format("central:incr[%s]=>%s\n", key, tostring(res)));
KSR.log("dbg", string.format("central:incr[%s]=>%s\n", key, tostring(res)));
if not self._test_connection(self.pair) then
self.pair = self._connect(self.config.pair);
end
if self.config.check_pair_dup and self:is_in_set(callid, key) then
sr.log("warn", string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key));
KSR.log("warn", string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key));
end
local pos = self.pair:lpush(callid, key);
sr.log("dbg", string.format("pair:lpush[%s]=>[%s] %s\n", callid, key, tostring(pos)));
KSR.log("dbg", string.format("pair:lpush[%s]=>[%s] %s\n", callid, key, tostring(pos)));
end
function NGCPDlgCounters:del_key(callid, key)
@ -133,11 +133,11 @@ end
end
local num = self.pair:lrem(callid, 1, key);
if num == 0 then
sr.log("dbg", string.format("pair:lrem[%s]=>[%s] no such key found in list, skipping decrement",
KSR.log("dbg", string.format("pair:lrem[%s]=>[%s] no such key found in list, skipping decrement",
callid, key));
return false;
end
sr.log("dbg", string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num));
KSR.log("dbg", string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num));
if not self._test_connection(self.central) then
self.central = self._connect(self.config.central);
end
@ -157,7 +157,7 @@ end
end
while key do
self:_decr(key);
sr.log("dbg", string.format("pair:lpop[%s]=>[%s]\n", callid, key));
KSR.log("dbg", string.format("pair:lpop[%s]=>[%s]\n", callid, key));
key = self.pair:lpop(callid);
end
end
@ -167,7 +167,7 @@ end
self.central = self._connect(self.config.central);
end
local res = self.central:get(key);
sr.log("dbg", string.format("central:get[%s]=>%s\n", key, tostring(res)));
KSR.log("dbg", string.format("central:get[%s]=>%s\n", key, tostring(res)));
return res;
end
-- class

@ -71,7 +71,7 @@ end
local function _connect(config)
local client = redis.connect(config.host,config.port);
client:select(config.db);
sr.log("dbg", string.format("connected to redis server %s:%d at %s\n",
KSR.log("dbg", string.format("connected to redis server %s:%d at %s\n",
config.host, config.port, config.db));
return client;
end
@ -81,9 +81,9 @@ end
local num = self.central:llen(key);
if num == 0 then
self.central:del(key);
sr.log("dbg", string.format("central[%s] is empty. Removed\n", key));
KSR.log("dbg", string.format("central[%s] is empty. Removed\n", key));
else
sr.log("dbg", string.format("central:lrem[%s]=>[%s]\n", key, tostring(num)));
KSR.log("dbg", string.format("central:lrem[%s]=>[%s]\n", key, tostring(num)));
end
return num;
end
@ -113,15 +113,15 @@ end
self.central = _connect(self.config.central);
end
local pos = self.central:rpush(key, callid);
sr.log("dbg", string.format("central:rpush[%s]=>[%s] %s\n", key, callid, tostring(pos)));
KSR.log("dbg", string.format("central:rpush[%s]=>[%s] %s\n", key, callid, tostring(pos)));
if not _test_connection(self.pair) then
self.pair = _connect(self.config.pair);
end
if self.config.check_pair_dup and self:is_in_set(callid, key) then
sr.log("warn", string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key));
KSR.log("warn", string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key));
end
pos = self.pair:lpush("list:"..callid, key);
sr.log("dbg", string.format("pair:lpush[list:%s]=>[%s] %s\n", callid, key, tostring(pos)));
KSR.log("dbg", string.format("pair:lpush[list:%s]=>[%s] %s\n", callid, key, tostring(pos)));
end
function NGCPDlgList:del(callid, key)
@ -130,10 +130,10 @@ end
end
local num = self.pair:lrem("list:"..callid, 0, key);
if num == 0 then
sr.log("dbg", string.format("pair:lrem[list:%s] no such key %s found in list", callid, key));
KSR.log("dbg", string.format("pair:lrem[list:%s] no such key %s found in list", callid, key));
return false;
end
sr.log("dbg", string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num));
KSR.log("dbg", string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num));
if not _test_connection(self.central) then
self.central = _connect(self.config.central);
end
@ -154,7 +154,7 @@ end
end
while key do
self:_del(key, callid);
sr.log("dbg", string.format("pair:lpop[%s]=>[%s]\n", callid, key));
KSR.log("dbg", string.format("pair:lpop[%s]=>[%s]\n", callid, key));
key = self.pair:lpop("list:"..callid);
end
end

@ -92,7 +92,7 @@ NGCPDomainPrefs_MT.__tostring = function ()
row = cur:fetch({}, "a")
end
else
sr.log("dbg", string.format("no results for query:%s", query))
KSR.log("dbg", string.format("no results for query:%s", query))
end
cur:close()

@ -93,7 +93,7 @@ NGCPFaxPrefs_MT.__tostring = function ()
end
end
else
sr.log("dbg", string.format("no results for query:%s", query))
KSR.log("dbg", string.format("no results for query:%s", query))
end
cur:close()

@ -63,7 +63,7 @@ end
local function _connect(config)
local client = redis.connect(config.host,config.port);
client:select(config.db);
sr.log("dbg", string.format("connected to redis server %s:%d at %s\n",
KSR.log("dbg", string.format("connected to redis server %s:%d at %s\n",
config.host, config.port, config.db));
return client;
end
@ -77,7 +77,7 @@ end
if res == 1 then
self.client:expire(key, self.config.expire);
end
sr.log("dbg", string.format("[%s]=>[%s] expires:%s\n", key, tostring(res), tostring(self.config.expires)));
KSR.log("dbg", string.format("[%s]=>[%s] expires:%s\n", key, tostring(res), tostring(self.config.expires)));
return res;
end

@ -138,19 +138,19 @@ end
for _,pref in pairs(self.prefs) do
xavp = pref:xavp("caller")
xavp_log = tostring(xavp)
sr.log(level, string.format("%s:%s\n", xavp.name, xavp_log))
KSR.log(level, string.format("%s:%s\n", xavp.name, xavp_log))
xavp = pref:xavp("callee")
xavp_log = tostring(xavp)
sr.log(level, string.format("%s:%s\n", xavp.name, xavp_log))
KSR.log(level, string.format("%s:%s\n", xavp.name, xavp_log))
end
else
if self.prefs[vtype] then
xavp = self.prefs[vtype]:xavp("caller")
xavp_log = tostring(xavp)
sr.log(level, string.format("%s:%s\n", xavp.name, xavp_log))
KSR.log(level, string.format("%s:%s\n", xavp.name, xavp_log))
xavp = self.prefs[vtype]:xavp("callee")
xavp_log = tostring(xavp)
sr.log(level, string.format("%s:%s\n", xavp.name, xavp_log))
KSR.log(level, string.format("%s:%s\n", xavp.name, xavp_log))
else
error(string.format("there is no prefs for %s", vtype))
end

@ -94,13 +94,13 @@ NGCPPeerPrefs_MT.__tostring = function ()
row = cur:fetch({}, "a")
end
else
sr.log("dbg", string.format("no results for query:%s", query))
KSR.log("dbg", string.format("no results for query:%s", query))
end
cur:close()
xavp = self:xavp(level, result)
for k,v in pairs(defaults) do
sr.log("dbg", string.format("setting default[%s]:%s", k, tostring(v)))
KSR.log("dbg", string.format("setting default[%s]:%s", k, tostring(v)))
xavp(k, v)
end
return keys

@ -79,7 +79,7 @@ NGCPProfilePrefs_MT.__tostring = function ()
row = cur:fetch({}, "a")
end
else
sr.log("dbg", string.format("no results for query:%s", query))
KSR.log("dbg", string.format("no results for query:%s", query))
end
cur:close()
if utable.size(result) > 0 then

@ -64,7 +64,7 @@ end
function NGCPRecentCalls._connect(config)
local client = redis.connect(config.host,config.port)
client:select(config.db)
sr.log("info", string.format("connected to redis server %s:%d at %s\n",
KSR.log("info", string.format("connected to redis server %s:%d at %s\n",
config.host, config.port, config.db))
return client
end
@ -87,7 +87,7 @@ end
if res then
self.central:expire(key, self.config.expire)
end
sr.log("info", string.format("central:hset[%s]=>[%s] callid: %s uuid: %s " ..
KSR.log("info", string.format("central:hset[%s]=>[%s] callid: %s uuid: %s " ..
"start_time: %s duration: %d caller: %s callee: %s source: %s expire: %d\n",
key, tostring(res),
callid, uuid,
@ -107,7 +107,7 @@ end
if res then
self.central:expire(key, self.config.out_expire)
end
sr.log("info", string.format("central:hset[%s]=>[%s] %s: %s expire: %d\n",
KSR.log("info", string.format("central:hset[%s]=>[%s] %s: %s expire: %d\n",
key, tostring(res),
element, tostring(value),
self.config.out_expire))
@ -121,7 +121,7 @@ end
local res = self.central:hgetall(key)
if res then
sr.log("info", string.format("central:hget[%s]=>[%s]\n",
KSR.log("info", string.format("central:hget[%s]=>[%s]\n",
key, tostring(res[element])))
return res[element]
@ -136,7 +136,7 @@ end
end
self.central:del(key)
sr.log("info", string.format("central:del[%s] removed\n", key));
KSR.log("info", string.format("central:del[%s] removed\n", key));
return 0
end

@ -124,7 +124,7 @@ NGCPRealPrefs_MT.__tostring = function ()
if value then
real_values[v] = value
else
sr.log("err", string.format("key:%s not in user, profile or domain", v))
KSR.log("err", string.format("key:%s not in user, profile or domain", v))
end
end
local real_keys = {}

@ -95,13 +95,13 @@ NGCPUserPrefs_MT.__tostring = function ()
row = cur:fetch({}, "a")
end
else
sr.log("dbg", string.format("no results for query:%s", query))
KSR.log("dbg", string.format("no results for query:%s", query))
end
cur:close()
xavp = self:xavp(level, result)
for k,v in pairs(defaults) do
sr.log("dbg", string.format("setting default[%s]:%s", k, tostring(v)))
KSR.log("dbg", string.format("setting default[%s]:%s", k, tostring(v)))
xavp(k, v)
end
return keys

@ -36,23 +36,23 @@ local NGCPXAvp_MT = {
local id = string.format("$xavp(%s[0]=>%s)", s.name, key)
--print(string.format("id:%s", id))
if not value then
return sr.pv.get(id)
return KSR.pv.get(id)
elseif type(value) == "number" then
utable.add(s.keys, key)
--sr.log("dbg", string.format("seti: [%s]:%d", id, value))
sr.pv.seti(id, value)
KSR.pv.seti(id, value)
elseif type(value) == "string" then
utable.add(s.keys, key)
--sr.log("dbg", string.format("sets: [%s]:%s", id, value))
sr.pv.sets(id, value)
KSR.pv.sets(id, value)
elseif type(value) == "table" then
utable.add(s.keys, key)
for i = #value, 1, -1 do
local v = value[i]
if type(v) == "number" then
sr.pv.seti(id, v)
KSR.pv.seti(id, v)
elseif type(v) == "string" then
sr.pv.sets(id, v)
KSR.pv.sets(id, v)
else
error("unknown type: %s", type(v))
end
@ -68,7 +68,7 @@ local NGCPXAvp_MT = {
if ll then
output = utable.tostring(ll)
end
sr.log("dbg", string.format("output:%s", output))
KSR.log("dbg", string.format("output:%s", output))
return output
end
setmetatable( t, NGCPXAvp_MT )
@ -95,43 +95,43 @@ local NGCPXAvp_MT = {
function NGCPXAvp._setvalue(id, vtype, value)
local check
-- sr.log("info", string.format("vtype:[%s]:%d", type(vtype), vtype))
-- KSR.log("info", string.format("vtype:[%s]:%d", type(vtype), vtype))
if type(vtype) == "string" then
vtype = tonumber(vtype)
end
if vtype == 0 then
sr.log("dbg",string.format("sr.pv.sets->%s:%s", id, value))
KSR.log("dbg",string.format("sr.pv.sets->%s:%s", id, value))
if type(value) == 'number' then
value = tostring(value)
end
sr.pv.sets(id, value)
KSR.pv.sets(id, value)
elseif vtype == 1 then
if type(value) == "string" then
value = tonumber(value)
end
sr.pv.seti(id, value)
KSR.pv.seti(id, value)
else
sr.log("err",string.format("can't set value:%s of type:%s",
KSR.log("err",string.format("can't set value:%s of type:%s",
tostring(value), tostring(vtype)))
end
if value and id then
check = sr.pv.get(id)
check = KSR.pv.get(id)
if check then
if type(check) == 'table' then
utable.tostring(check)
end
else
--error(string.format("%s:nil", id))
sr.log("err", string.format("%s:nil", id))
KSR.log("err", string.format("%s:nil", id))
end
end
end
function NGCPXAvp:_create(l)
local name = string.format("$xavp(%s=>dummy)", self.name)
if not sr.pv.get(name) then
if not KSR.pv.get(name) then
NGCPXAvp._setvalue(name, 0, self.level)
sr.log("dbg",string.format("%s created with dummy value:%s", name, self.level))
KSR.log("dbg",string.format("%s created with dummy value:%s", name, self.level))
end
for i=1,#l do
name = string.format("$xavp(%s[0]=>%s)", tostring(self.name), tostring(l[i].attribute))
@ -152,10 +152,10 @@ local NGCPXAvp_MT = {
function NGCPXAvp:clean(key)
if key then
local id = string.format("$xavp(%s[0]=>%s[*])", self.name, key)
sr.pv.unset(id)
KSR.pv.unset(id)
else
sr.pv.unset(string.format("$xavp(%s)", self.name))
sr.pv.sets(string.format("$xavp(%s=>dummy)", self.name), self.level)
KSR.pv.unset(string.format("$xavp(%s)", self.name))
KSR.pv.sets(string.format("$xavp(%s=>dummy)", self.name), self.level)
end
end
-- class

@ -14,8 +14,8 @@ parser:flag("-c --config-db", "redis db defined at config")
parser:flag("-C --config-host", "redis server defined at config")
-- luacheck: globals dlg_config
sr = {}
sr.log = function (level, str)
KSR = {}
KSR.log = function (level, str)
print(string.format("[%s] %s", level, str))
end

@ -12,8 +12,8 @@ local parser = argparse() {
parser:argument("callid", "Call-Id to remove")
-- luacheck: globals dlg_config
sr = {}
sr.log = function (level, str)
KSR = {}
KSR.log = function (level, str)
print(string.format("[%s] %s", level, str))
end

@ -1,3 +1,3 @@
globals = {'sr', 'srMock'}
globals = {'KSR', 'sr'}
-- until we fix the luaunit new format at run_tests.sh
ignore = {'assert.*', '212'}

@ -0,0 +1,40 @@
--
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This package is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- .
-- On Debian systems, the complete text of the GNU General
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
--
require('luaunit')
local ksrMock = require 'mocks.ksr'
-- luacheck: ignore TestKEMIMock
TestKEMIMock = {}
function TestKEMIMock:setUp()
self.KSR = ksrMock.new()
end
function TestKEMIMock:test_hdr_get()
self.KSR.hdr.insert("From: hola\r\n")
assertEquals(self.KSR.hdr.headers, {"From: hola\r\n"})
assertEquals(self.KSR.pv.get("$hdr(From)"), "hola")
end
function TestKEMIMock:test_log()
assertEvalToTrue(self.KSR.log)
self.KSR.log("dbg", "Hi dude!")
assertError(self.KSR.log, "debug", "Hi dude!")
end

@ -0,0 +1,65 @@
--
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This package is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- .
-- On Debian systems, the complete text of the GNU General
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
--
require('luaunit')
local pvMock = require 'mocks.pv'
local pvxMock = require 'mocks.pvx'
-- luacheck: ignore TestXAVPMock
TestXAVPMock = {}
function TestXAVPMock:setUp()
self.pv = pvMock.new()
self.pvx = pvxMock.new(self.pv)
self.pv.sets("$xavp(test=>uno)", "uno")
assertEquals(self.pv.get("$xavp(test[0]=>uno)"), "uno")
self.pv.seti("$xavp(test[0]=>dos)", 4)
self.pv.seti("$xavp(test[0]=>dos)", 2)
assertEquals(self.pv.get("$xavp(test[0]=>dos)"), 2)
self.pv.seti("$xavp(test=>uno)", 3)
self.pv.seti("$xavp(test[0]=>uno)", 1)
assertEquals(self.pv.get("$xavp(test[0]=>uno)"), 1)
self.pv.sets("$xavp(test[0]=>dos)", "dos")
assertEquals(self.pv.get("$xavp(test[0]=>dos)"), "dos")
self.pv.seti("$xavp(test[0]=>tres)", 3)
assertEquals(self.pv.get("$xavp(test[0]=>tres)"), 3)
--
assertEquals(self.pv.get("$xavp(test[1]=>uno)"), "uno")
assertEquals(self.pv.get("$xavp(test[1]=>dos)"), 2)
end
function TestXAVPMock:tearDown()
self.pv.vars = {}
end
function TestXAVPMock:test_xavp_get()
local l = self.pvx.xavp_get("test")
local m = tostring(self.pv.vars["xavp:test"])
assertItemsEquals(l, "<<xavp:"..m:sub(8)..">>")
end
function TestXAVPMock:test_xavp_gete()
assertItemsEquals(self.pvx.xavp_gete("fake"), "")
end
function TestXAVPMock:test_xavp_getw()
assertItemsEquals(self.pvx.xavp_getw("fake"), "<null>")
end
--EOF

@ -19,12 +19,18 @@
--
require('luaunit')
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
-- luacheck: ignore TestSRMock
TestSRMock = {}
function TestSRMock:setUp()
self.sr = srMock.new()
self.ksr = ksrMock.new()
self.sr = srMock.new(self.ksr)
end
function TestSRMock:test_hdr()
assertIs(self.sr.hdr, self.ksr.hdr)
end
function TestSRMock:test_hdr_get()
@ -33,8 +39,30 @@ TestSRMock = {}
assertEquals(self.sr.pv.get("$hdr(From)"), "hola")
end
function TestSRMock:test_pv()
self.sr.pv.sets("$var(test)", "value")
assertEquals(self.sr.pv.get("$var(test)"), "value")
assertIs(self.sr.pv, self.ksr.pv)
end
function TestSRMock:test_pv_get()
assertIs(self.sr.pv, self.ksr.pv)
end
function TestSRMock:test_log()
assertEvalToTrue(self.sr.log)
assertNotNil(self.sr.log)
end
function TestSRMock:test_log_dbg()
self.sr.log("dbg", "Hi dude!")
assertError(self.sr.log, "debug", "Hi dude!")
end
function TestSRMock:test_xavp()
assertNotNil(self.sr.xavp)
end
function TestSRMock:test_xavp_get()
assertErrorMsgContains(
"dummy not found", self.sr.xavp.get, "dummy", 0, 0)
end

@ -28,8 +28,10 @@ local FPFetch = require 'tests_v.fp_vars'
local utils = require 'ngcp.utils'
local utable = utils.table
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env
local dp_vars = DPFetch:new()
@ -69,19 +71,7 @@ TestNGCP = {} --class
end
function TestNGCP:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_prof_prefs)")
sr.pv.unset("$xavp(callee_prof_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.pv.unset("$xavp(caller_fax_prefs)")
sr.pv.unset("$xavp(callee_fax_prefs)")
self.ngcp = nil
KSR.pv.vars= {}
end
function TestNGCP:test_config()
@ -107,27 +97,27 @@ TestNGCP = {} --class
end
function TestNGCP:test_prefs_init()
sr.log("dbg", "TestNGCP:test_prefs_init")
KSR.log("dbg", "TestNGCP:test_prefs_init")
assertEvalToTrue(self.ngcp)
assertEvalToTrue(self.ngcp.prefs)
assertEvalToTrue(self.ngcp.prefs.peer)
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.usr)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.dom)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.real)
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.prof)
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertEvalToTrue(self.ngcp.prefs.fax)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
end
function TestNGCP:test_log_pref()
@ -195,12 +185,12 @@ TestNGCP = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>account_id)"), 2)
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>cli)"), "4311001")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>cc)"), "43")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>ac)"), "1")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>no_nat_sipping)"), "no")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>account_id)"), 2)
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>cli)"), "4311001")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>cc)"), "43")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>ac)"), "1")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>no_nat_sipping)"), "no")
end
function TestNGCP:test_caller_usr_load_empty_usr()
@ -228,15 +218,15 @@ TestNGCP = {} --class
"inbound_uprn"
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"), "caller")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller")
--- the default is on real and dom NOT in usr
assertIsNil(sr.pv.get("$xavp(caller_usr_prefs=>sst_enable)"))
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>sst_enable)"), "no")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>sst_enable)"), "no")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertIsNil(sr.pv.get("$xavp(caller_real_prefs=>force_outbound_calls_to_peer)"))
assertIsNil(sr.pv.get("$xavp(caller_dom_prefs=>force_outbound_calls_to_peer)"))
assertIsNil(KSR.pv.get("$xavp(caller_usr_prefs=>sst_enable)"))
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertIsNil(KSR.pv.get("$xavp(caller_real_prefs=>force_outbound_calls_to_peer)"))
assertIsNil(KSR.pv.get("$xavp(caller_dom_prefs=>force_outbound_calls_to_peer)"))
end
function TestNGCP:test_caller_usr_load()
@ -308,13 +298,13 @@ TestNGCP = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs[0]=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs[0]=>dummy)"), "caller")
--- the default is on real NOT in usr
assertIsNil(sr.pv.get("$xavp(caller_usr_prefs[0]=>sst_enable)"))
assertEquals(sr.pv.get("$xavp(caller_real_prefs[0]=>sst_enable)"), "no")
assertEquals(sr.pv.get("$xavp(caller_real_prefs[0]=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs[0]=>force_outbound_calls_to_peer)"), 1)
assertEquals(sr.pv.get("$xavp(caller_real_prefs[0]=>force_outbound_calls_to_peer)"), 1)
assertIsNil(KSR.pv.get("$xavp(caller_usr_prefs[0]=>sst_enable)"))
assertEquals(KSR.pv.get("$xavp(caller_real_prefs[0]=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs[0]=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs[0]=>force_outbound_calls_to_peer)"), 1)
assertEquals(KSR.pv.get("$xavp(caller_real_prefs[0]=>force_outbound_calls_to_peer)"), 1)
end
function TestNGCP:test_callee_usr_load_empty()
@ -389,12 +379,12 @@ TestNGCP = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>sst_enable)"), "no")
--- the default is on real NOT in usr
assertIsNil(sr.pv.get("$xavp(callee_usr_prefs=>sst_enable)"))
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>sst_enable)"), "no")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertIsNil(KSR.pv.get("$xavp(callee_usr_prefs=>sst_enable)"))
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
end
function TestNGCP:test_callee_usr_load_prof()
@ -465,13 +455,13 @@ TestNGCP = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>sst_enable)"), "no")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>sst_enable)"), "yes")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>sst_enable)"), "yes")
--- the default is on real NOT in usr
assertIsNil(sr.pv.get("$xavp(callee_usr_prefs=>sst_enable)"))
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>sst_enable)"), "yes")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertIsNil(KSR.pv.get("$xavp(callee_usr_prefs=>sst_enable)"))
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>sst_enable)"), "yes")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
end
function TestNGCP:test_callee_usr_load_prof_usr()
@ -534,12 +524,12 @@ TestNGCP = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>sst_enable)"), "no")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>sst_enable)"), "yes")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>sst_enable)"), "yes")
--- the default is on real NOT in usr
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>sst_enable)"), "no")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>sst_enable)"), "no")
end
function TestNGCP:test_caller_peer_load_empty()
@ -573,9 +563,9 @@ TestNGCP = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"), "caller")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>sst_enable)"), "no")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
end
function TestNGCP:test_callee_peer_load_empty()
@ -609,23 +599,23 @@ TestNGCP = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>sst_enable)"), "no")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>sst_enable)"), "no")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
end
function TestNGCP:test_clean()
local xavp = NGCPXAvp:new('callee','usr_prefs')
xavp("testid",1)
xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller")
self.ngcp:clean()
assertEquals(sr.pv.get("$avp(s:callee_cfb)"),nil)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
assertIsNil(sr.pv.get("$xavp(user)"))
assertEquals(KSR.pv.get("$avp(s:callee_cfb)"),nil)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
assertIsNil(KSR.pv.get("$xavp(user)"))
end
function TestNGCP:test_clean_caller_groups()
@ -634,10 +624,10 @@ TestNGCP = {} --class
for _,v in pairs(groups) do
local xavp = self.ngcp.prefs[v]:xavp("caller")
xavp(string.format("test_%s", v), v)
assertEquals(sr.pv.get(string.format("$xavp(caller_%s_prefs=>test_%s)", v, v)), v)
assertEquals(sr.pv.get(string.format("$xavp(caller_%s_prefs=>dummy)", v)), "caller")
assertEquals(KSR.pv.get(string.format("$xavp(caller_%s_prefs=>test_%s)", v, v)), v)
assertEquals(KSR.pv.get(string.format("$xavp(caller_%s_prefs=>dummy)", v)), "caller")
self.ngcp:clean("caller", v)
assertEquals(sr.pv.get(string.format("$xavp(caller_%s_prefs=>dummy)", v)), "caller")
assertEquals(KSR.pv.get(string.format("$xavp(caller_%s_prefs=>dummy)", v)), "caller")
end
assertError(self.ngcp.clean, self.ngcp, "caller", "whatever")
end
@ -649,34 +639,34 @@ TestNGCP = {} --class
for _,v in pairs(groups) do
local xavp = self.ngcp.prefs[v]:xavp("callee")
xavp(string.format("test_%s", v), v)
assertEquals(sr.pv.get(string.format("$xavp(callee_%s_prefs=>test_%s)", v, v)), v)
assertEquals(sr.pv.get(string.format("$xavp(callee_%s_prefs=>dummy)", v)), "callee")
assertEquals(KSR.pv.get(string.format("$xavp(callee_%s_prefs=>test_%s)", v, v)), v)
assertEquals(KSR.pv.get(string.format("$xavp(callee_%s_prefs=>dummy)", v)), "callee")
self.ngcp:clean("callee", v)
assertEquals(sr.pv.get(string.format("$xavp(callee_%s_prefs=>dummy)", v)), "callee")
assertEquals(KSR.pv.get(string.format("$xavp(callee_%s_prefs=>dummy)", v)), "callee")
end
assertError(self.ngcp.clean, self.ngcp, "callee", "whatever")
end
function TestNGCP:test_callee_clean()
local callee_xavp = NGCPDomainPrefs:xavp('callee')
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
callee_xavp("testid",1)
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
callee_xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
local caller_xavp = NGCPDomainPrefs:xavp('caller')
caller_xavp("other",1)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>other)"),1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
self.ngcp:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),'caller')
assertIsNil(sr.pv.get("$xavp(callee_dom_prefs=>testid)"))
assertIsNil(sr.pv.get("$xavp(callee_dom_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"),'caller')
assertIsNil(KSR.pv.get("$xavp(callee_dom_prefs=>testid)"))
assertIsNil(KSR.pv.get("$xavp(callee_dom_prefs=>foo)"))
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"), "callee")
end
function TestNGCP:test_caller_clean()
@ -686,19 +676,19 @@ TestNGCP = {} --class
local caller_xavp = NGCPXAvp:new('caller','peer_prefs')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
self.ngcp:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertNil(sr.pv.get("$xavp(caller_peer_prefs=>other)"))
assertNil(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertNil(KSR.pv.get("$xavp(caller_peer_prefs=>other)"))
assertNil(KSR.pv.get("$xavp(caller_peer_prefs=>otherfoo)"))
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
end
function TestNGCP:test_tostring()

@ -20,9 +20,9 @@
require('luaunit')
local lemock = require('lemock')
local srMock = require 'mocks.sr'
local ksrMock = require 'mocks.ksr'
sr = srMock:new()
KSR = ksrMock:new()
local mc

@ -18,10 +18,10 @@
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
--
require('luaunit')
local srMock = require 'mocks.sr'
local ksrMock = require 'mocks.ksr'
local NGCPAvp = require 'ngcp.avp'
sr = srMock.new()
KSR = ksrMock.new()
-- luacheck: ignore TestNGCPAvp
TestNGCPAvp = {} --class
@ -30,7 +30,7 @@ TestNGCPAvp = {} --class
end
function TestNGCPAvp:tearDown()
sr.pv.vars = {}
KSR.pv.vars = {}
end
function TestNGCPAvp:test_avp_id()
@ -38,9 +38,9 @@ TestNGCPAvp = {} --class
end
function TestNGCPAvp:test_avp_get()
sr.pv.sets("$avp(s:testid)", "value")
KSR.pv.sets("$avp(s:testid)", "value")
assertEquals(self.avp(), "value")
sr.pv.sets("$avp(s:testid)", "1")
KSR.pv.sets("$avp(s:testid)", "1")
assertItemsEquals(self.avp(), "1")
assertItemsEquals(self.avp:all(),{"1","value"})
end

@ -21,8 +21,10 @@ require('luaunit')
local lemock = require('lemock')
local CPFetch = require 'tests_v.cp_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local cp_vars = CPFetch:new()
@ -64,19 +66,7 @@ TestNGCPContractPrefs = {} --class
end
function TestNGCPContractPrefs:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_contract_prefs)")
sr.pv.unset("$xavp(callee_contract_prefs)")
sr.pv.unset("$xavp(caller_prof_prefs)")
sr.pv.unset("$xavp(callee_prof_prefs)")
sr.pv.unset("$xavp(caller_prof_prefs)")
sr.pv.unset("$xavp(callee_prof_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---TestNGCPContractPrefs::cleaned---")
KSR.pv.vars= {}
end
function TestNGCPContractPrefs:test_init()
@ -106,8 +96,8 @@ TestNGCPContractPrefs = {} --class
mc:verify()
assertItemsEquals(keys, {"sst_enable"})
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>sst_enable)"),"no")
assertNil(sr.pv.get("$xavp(callee_contract_prefs=>location_id)"))
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>sst_enable)"),"no")
assertNil(KSR.pv.get("$xavp(callee_contract_prefs=>location_id)"))
end
function TestNGCPContractPrefs:test_callee_load()
@ -125,22 +115,22 @@ TestNGCPContractPrefs = {} --class
mc:verify()
assertItemsEquals(keys, {"sst_enable"})
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>sst_enable)"),"yes")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>location_id)"),1)
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>sst_enable)"),"yes")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>location_id)"),1)
end
function TestNGCPContractPrefs:test_clean()
local xavp = NGCPContractPrefs:xavp('callee')
xavp("testid",1)
xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
self.d:clean()
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
assertNil(sr.pv.get("$xavp(prof)"))
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
assertNil(KSR.pv.get("$xavp(prof)"))
end
function TestNGCPContractPrefs:test_callee_clean()
@ -150,19 +140,19 @@ TestNGCPContractPrefs = {} --class
local caller_xavp = NGCPContractPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>dummy)"),'caller')
assertNil(sr.pv.get("$xavp(callee_contract_prefs=>testid)"))
assertNil(sr.pv.get("$xavp(callee_contract_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>dummy)"),'caller')
assertNil(KSR.pv.get("$xavp(callee_contract_prefs=>testid)"))
assertNil(KSR.pv.get("$xavp(callee_contract_prefs=>foo)"))
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
end
function TestNGCPContractPrefs:test_caller_clean()
@ -172,19 +162,19 @@ TestNGCPContractPrefs = {} --class
local caller_xavp = NGCPContractPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertNil(sr.pv.get("$xavp(caller_contract_prefs=>other)"))
assertNil(sr.pv.get("$xavp(caller_contract_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_contract_prefs=>dummy)"),"caller")
assertNil(KSR.pv.get("$xavp(caller_contract_prefs=>other)"))
assertNil(KSR.pv.get("$xavp(caller_contract_prefs=>otherfoo)"))
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_contract_prefs=>dummy)"),"callee")
end
function TestNGCPContractPrefs:test_tostring()

@ -18,10 +18,10 @@
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
--
require('luaunit')
local srMock = require 'mocks.sr'
local ksrMock = require 'mocks.ksr'
local NGCPDlgVar = require 'ngcp.dlg_var'
sr = srMock:new()
KSR = ksrMock:new()
-- luacheck: ignore TestNGCPDlgVar
TestNGCPDlgVar = {} --class
function TestNGCPDlgVar:setUp()
@ -29,7 +29,7 @@ TestNGCPDlgVar = {} --class
end
function TestNGCPDlgVar:tearDown()
sr.pv.vars = {}
KSR.pv.vars = {}
end
function TestNGCPDlgVar:test_dlg_var_id()
@ -37,9 +37,9 @@ TestNGCPDlgVar = {} --class
end
function TestNGCPDlgVar:test_dlg_var_get()
sr.pv.sets("$dlg_var(testid)", "value")
KSR.pv.sets("$dlg_var(testid)", "value")
assertEquals(self.var(), "value")
sr.pv.sets("$dlg_var(testid)", "1")
KSR.pv.sets("$dlg_var(testid)", "1")
assertItemsEquals(self.var(), "1")
end

@ -20,8 +20,8 @@
local lemock = require('lemock')
require('luaunit')
local srMock = require 'mocks.sr'
sr = srMock:new()
local ksrMock = require 'mocks.ksr'
KSR = ksrMock:new()
local mc
-- luacheck: ignore TestNGCPDlgCnt

@ -21,8 +21,8 @@
local lemock = require('lemock')
require('luaunit')
local srMock = require 'mocks.sr'
sr = srMock:new()
local ksrMock = require 'mocks.ksr'
KSR = ksrMock:new()
local mc

@ -23,8 +23,10 @@ local utable = utils.table
local lemock = require('lemock')
local DPFetch = require 'tests_v.dp_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local dp_vars = DPFetch:new()
@ -58,15 +60,7 @@ TestNGCPDomainPrefs = {} --class
end
function TestNGCPDomainPrefs:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---cleaned---")
KSR.pv.vars = {}
end
function TestNGCPDomainPrefs:test_init()
@ -106,8 +100,8 @@ TestNGCPDomainPrefs = {} --class
local keys = self.d:caller_load("192.168.51.56")
mc:verify()
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>sst_enable)"),"no")
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>sst_enable)"),"no")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertItemsEquals(keys, TestNGCPDomainPrefs:get_defaults())
end
@ -123,8 +117,8 @@ TestNGCPDomainPrefs = {} --class
local keys = self.d:callee_load("192.168.51.56")
mc:verify()
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>sst_enable)"),"no")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>sst_enable)"),"no")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertItemsEquals(keys, TestNGCPDomainPrefs:get_defaults())
end
@ -132,13 +126,13 @@ TestNGCPDomainPrefs = {} --class
local xavp = NGCPDomainPrefs:xavp('callee')
xavp("testid",1)
xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
self.d:clean()
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertNil(sr.pv.get("$xavp(domain)"))
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertNil(KSR.pv.get("$xavp(domain)"))
end
function TestNGCPDomainPrefs:test_callee_clean()
@ -148,19 +142,19 @@ TestNGCPDomainPrefs = {} --class
local caller_xavp = NGCPDomainPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),'caller')
assertNil(sr.pv.get("$xavp(callee_dom_prefs=>testid)"))
assertNil(sr.pv.get("$xavp(callee_dom_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"),'caller')
assertNil(KSR.pv.get("$xavp(callee_dom_prefs=>testid)"))
assertNil(KSR.pv.get("$xavp(callee_dom_prefs=>foo)"))
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
end
function TestNGCPDomainPrefs:test_caller_clean()
@ -170,19 +164,19 @@ TestNGCPDomainPrefs = {} --class
local caller_xavp = NGCPDomainPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertNil(sr.pv.get("$xavp(caller_dom_prefs=>other)"))
assertNil(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertNil(KSR.pv.get("$xavp(caller_dom_prefs=>other)"))
assertNil(KSR.pv.get("$xavp(caller_dom_prefs=>otherfoo)"))
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
end
function TestNGCPDomainPrefs:test_tostring()

@ -21,8 +21,10 @@ require('luaunit')
local lemock = require('lemock')
local FPFetch = require 'tests_v.fp_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local fp_vars = FPFetch:new()
@ -63,19 +65,7 @@ TestNGCPFaxPrefs = {} --class
end
function TestNGCPFaxPrefs:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_prof_prefs)")
sr.pv.unset("$xavp(callee_prof_prefs)")
sr.pv.unset("$xavp(caller_prof_prefs)")
sr.pv.unset("$xavp(callee_prof_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.pv.unset("$xavp(caller_fax_prefs)")
sr.pv.unset("$xavp(callee_fax_prefs)")
sr.log("info", "---TestNGCPFaxPrefs::cleaned---")
KSR.pv.vars = {}
end
function TestNGCPFaxPrefs:test_init()
@ -108,10 +98,10 @@ TestNGCPFaxPrefs = {} --class
assertEquals(keys[k], v)
end
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"), "caller")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>active)"), 1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>t38)"), 1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>ecm)"), 1)
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>active)"), 1)
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>t38)"), 1)
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>ecm)"), 1)
end
function TestNGCPFaxPrefs:test_callee_load()
@ -129,24 +119,24 @@ TestNGCPFaxPrefs = {} --class
assertEquals(keys[k], v)
end
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>active)"), 1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>t38)"), 0)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>ecm)"), 0)
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>active)"), 1)
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>t38)"), 0)
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>ecm)"), 0)
end
function TestNGCPFaxPrefs:test_clean()
local xavp = NGCPFaxPrefs:xavp('callee')
xavp("testid",1)
xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
self.d:clean()
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
assertNil(sr.pv.get("$xavp(fax)"))
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
assertNil(KSR.pv.get("$xavp(fax)"))
end
function TestNGCPFaxPrefs:test_callee_clean()
@ -156,19 +146,19 @@ TestNGCPFaxPrefs = {} --class
local caller_xavp = NGCPFaxPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),'caller')
assertNil(sr.pv.get("$xavp(callee_fax_prefs=>testid)"))
assertNil(sr.pv.get("$xavp(callee_fax_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>dummy)"),'caller')
assertNil(KSR.pv.get("$xavp(callee_fax_prefs=>testid)"))
assertNil(KSR.pv.get("$xavp(callee_fax_prefs=>foo)"))
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
end
function TestNGCPFaxPrefs:test_caller_clean()
@ -178,19 +168,19 @@ TestNGCPFaxPrefs = {} --class
local caller_xavp = NGCPFaxPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertNil(sr.pv.get("$xavp(caller_fax_prefs=>other)"))
assertNil(sr.pv.get("$xavp(caller_fax_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertNil(KSR.pv.get("$xavp(caller_fax_prefs=>other)"))
assertNil(KSR.pv.get("$xavp(caller_fax_prefs=>otherfoo)"))
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
end
function TestNGCPFaxPrefs:test_tostring()

@ -21,8 +21,8 @@
local lemock = require('lemock')
require('luaunit')
local srMock = require 'mocks.sr'
sr = srMock:new()
local ksrMock = require 'mocks.ksr'
KSR = ksrMock:new()
local mc

@ -24,8 +24,10 @@ local utable = utils.table
local PPFetch = require 'tests_v.pp_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local pp_vars = PPFetch:new()
@ -67,15 +69,7 @@ TestNGCPPeerPrefs = {} --class
end
function TestNGCPPeerPrefs:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---TestNGCPPeerPrefs::cleaned---")
KSR.pv.vars = {}
end
function TestNGCPPeerPrefs:test_init()
@ -90,14 +84,14 @@ TestNGCPPeerPrefs = {} --class
if set then
keys_expected = utable.deepcopy(set)
for _,v in pairs(keys_expected) do
sr.log("dbg", string.format("removed key:%s is been loaded.", v))
KSR.log("dbg", string.format("removed key:%s is been loaded.", v))
defaults[v] = nil
end
end
for k,v in pairs(defaults) do
utable.add(keys_expected, k)
assertEquals(sr.pv.get("$xavp("..level.."_peer_prefs=>"..k..")"), v)
assertEquals(KSR.pv.get("$xavp("..level.."_peer_prefs=>"..k..")"), v)
end
return keys_expected
end
@ -138,10 +132,10 @@ TestNGCPPeerPrefs = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"), "caller")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>sst_enable)"),"no")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>sst_min_timer)"), 90)
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>sst_enable)"),"no")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>sst_min_timer)"), 90)
assertItemsEquals(keys, TestNGCPPeerPrefs:get_defaults("caller", {"sst_enable", "sst_refresh_method"}))
end
@ -171,10 +165,10 @@ TestNGCPPeerPrefs = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>sst_enable)"),"no")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>sst_min_timer)"), 90)
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>sst_enable)"),"no")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>sst_min_timer)"), 90)
assertItemsEquals(keys, TestNGCPPeerPrefs:get_defaults("callee", {"sst_enable", "sst_refresh_method"}))
end
@ -182,14 +176,14 @@ TestNGCPPeerPrefs = {} --class
local xavp = NGCPPeerPrefs:xavp('callee')
xavp("testid",1)
xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
self.d:clean()
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertNil(sr.pv.get("$xavp(peer)"))
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertNil(KSR.pv.get("$xavp(peer)"))
end
function TestNGCPPeerPrefs:test_callee_clean()
@ -199,19 +193,19 @@ TestNGCPPeerPrefs = {} --class
local caller_xavp = NGCPPeerPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),'caller')
assertNil(sr.pv.get("$xavp(callee_peer_prefs=>testid)"))
assertNil(sr.pv.get("$xavp(callee_peer_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),'caller')
assertNil(KSR.pv.get("$xavp(callee_peer_prefs=>testid)"))
assertNil(KSR.pv.get("$xavp(callee_peer_prefs=>foo)"))
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
end
function TestNGCPPeerPrefs:test_caller_clean()
@ -221,19 +215,19 @@ TestNGCPPeerPrefs = {} --class
local caller_xavp = NGCPPeerPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertNil(sr.pv.get("$xavp(caller_peer_prefs=>other)"))
assertNil(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertNil(KSR.pv.get("$xavp(caller_peer_prefs=>other)"))
assertNil(KSR.pv.get("$xavp(caller_peer_prefs=>otherfoo)"))
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
end
function TestNGCPPeerPrefs:test_tostring()

@ -21,8 +21,10 @@ require('luaunit')
local lemock = require('lemock')
local PProfFetch = require 'tests_v.pprof_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local pprof_vars = PProfFetch:new()
@ -64,17 +66,7 @@ TestNGCPProfilePrefs = {} --class
end
function TestNGCPProfilePrefs:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_prof_prefs)")
sr.pv.unset("$xavp(callee_prof_prefs)")
sr.pv.unset("$xavp(caller_prof_prefs)")
sr.pv.unset("$xavp(callee_prof_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---TestNGCPProfilePrefs::cleaned---")
KSR.pv.vars = {}
end
function TestNGCPProfilePrefs:test_init()
@ -106,10 +98,10 @@ TestNGCPProfilePrefs = {} --class
mc:verify()
assertItemsEquals(keys, {"sst_enable", "sst_refresh_method", "outbound_from_user"})
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"), "caller")
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>sst_enable)"),"yes")
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>outbound_from_user)"), "upn")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>sst_enable)"),"yes")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>outbound_from_user)"), "upn")
end
function TestNGCPProfilePrefs:test_callee_load()
@ -126,24 +118,24 @@ TestNGCPProfilePrefs = {} --class
mc:verify()
assertItemsEquals(keys, {"sst_enable", "sst_refresh_method", "outbound_from_user"})
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>sst_enable)"),"yes")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>outbound_from_user)"), "upn")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>sst_enable)"),"yes")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>outbound_from_user)"), "upn")
end
function TestNGCPProfilePrefs:test_clean()
local xavp = NGCPProfilePrefs:xavp('callee')
xavp("testid",1)
xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
self.d:clean()
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertNil(sr.pv.get("$xavp(prof)"))
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertNil(KSR.pv.get("$xavp(prof)"))
end
function TestNGCPProfilePrefs:test_callee_clean()
@ -153,19 +145,19 @@ TestNGCPProfilePrefs = {} --class
local caller_xavp = NGCPProfilePrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"),'caller')
assertNil(sr.pv.get("$xavp(callee_prof_prefs=>testid)"))
assertNil(sr.pv.get("$xavp(callee_prof_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>dummy)"),'caller')
assertNil(KSR.pv.get("$xavp(callee_prof_prefs=>testid)"))
assertNil(KSR.pv.get("$xavp(callee_prof_prefs=>foo)"))
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
end
function TestNGCPProfilePrefs:test_caller_clean()
@ -175,19 +167,19 @@ TestNGCPProfilePrefs = {} --class
local caller_xavp = NGCPProfilePrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertNil(sr.pv.get("$xavp(caller_prof_prefs=>other)"))
assertNil(sr.pv.get("$xavp(caller_prof_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertNil(KSR.pv.get("$xavp(caller_prof_prefs=>other)"))
assertNil(KSR.pv.get("$xavp(caller_prof_prefs=>otherfoo)"))
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
end
function TestNGCPProfilePrefs:test_tostring()

@ -20,9 +20,9 @@
require('luaunit')
local lemock = require('lemock')
local srMock = require 'mocks.sr'
local ksrMock = require 'mocks.ksr'
sr = srMock:new()
KSR = ksrMock:new()
local mc

@ -23,8 +23,10 @@ local NGCPUserPrefs = require 'ngcp.up'
local NGCPPeerPrefs = require 'ngcp.pp'
local NGCPRealPrefs = require 'ngcp.rp'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
-- luacheck: ignore TestNGCPRealPrefs
TestNGCPRealPrefs = {} --class
@ -34,15 +36,7 @@ TestNGCPRealPrefs = {} --class
end
function TestNGCPRealPrefs:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---cleaned---")
KSR.pv.vars = {}
end
function TestNGCPRealPrefs:test_caller_load_empty()
@ -62,9 +56,9 @@ TestNGCPRealPrefs = {} --class
real = NGCPRealPrefs:xavp("caller")
}
xavp.domain("uno",1)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>uno)"),1)
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>uno)"),1)
xavp.user("uno",2)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>uno)"),2)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>uno)"),2)
xavp.peer("uno",3)
local real_keys = self.real:caller_peer_load(keys)
assertEquals(real_keys, keys)
@ -80,9 +74,9 @@ TestNGCPRealPrefs = {} --class
real = NGCPRealPrefs:xavp("caller")
}
xavp.domain("uno",1)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>uno)"),1)
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>uno)"),1)
xavp.user("uno",2)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>uno)"),2)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>uno)"),2)
local real_keys = self.real:caller_usr_load(keys)
assertEquals(real_keys, keys)
assertEquals(xavp.real("uno"),2)
@ -96,9 +90,9 @@ TestNGCPRealPrefs = {} --class
real = NGCPRealPrefs:xavp("caller")
}
xavp.domain("uno",1)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>uno)"),1)
assertEquals(KSR.pv.get("$xavp(caller_dom_prefs=>uno)"),1)
xavp.user("dos",2)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dos)"),2)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dos)"),2)
local real_keys = self.real:caller_usr_load(keys)
assertItemsEquals(real_keys, keys)
assertEquals(xavp.real("uno"),1)
@ -113,9 +107,9 @@ TestNGCPRealPrefs = {} --class
real = NGCPRealPrefs:xavp("callee")
}
xavp.domain("uno",1)
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>uno)"),1)
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>uno)"),1)
xavp.user("uno",2)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>uno)"),2)
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>uno)"),2)
local real_keys = self.real:callee_usr_load(keys)
assertEquals(real_keys, keys)
assertEquals(xavp.real("uno"),2)
@ -129,9 +123,9 @@ TestNGCPRealPrefs = {} --class
real = NGCPRealPrefs:xavp("callee")
}
xavp.domain("uno",1)
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>uno)"),1)
assertEquals(KSR.pv.get("$xavp(callee_dom_prefs=>uno)"),1)
xavp.user("dos",2)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dos)"),2)
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dos)"),2)
local real_keys = self.real:callee_usr_load(keys)
assertItemsEquals(real_keys, keys)
assertEquals(xavp.real("uno"),1)
@ -139,34 +133,34 @@ TestNGCPRealPrefs = {} --class
end
function TestNGCPRealPrefs:test_set()
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"), "caller")
assertNil(sr.pv.get("$xavp(callee_real_prefs=>testid)"))
assertNil(sr.pv.get("$xavp(callee_real_prefs=>foo)"))
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>dummy)"), "caller")
assertNil(KSR.pv.get("$xavp(callee_real_prefs=>testid)"))
assertNil(KSR.pv.get("$xavp(callee_real_prefs=>foo)"))
local callee_xavp = NGCPRealPrefs:xavp("callee")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),'callee')
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),'callee')
callee_xavp("testid", 1)
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"), 1)
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>testid)"), 1)
callee_xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
end
function TestNGCPRealPrefs:test_clean()
local callee_xavp = NGCPRealPrefs:xavp("callee")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),'callee')
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),'callee')
callee_xavp("testid",1)
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>testid)"),1)
callee_xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
self.real:clean()
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
end
function TestNGCPRealPrefs:test_callee_clean()
@ -179,21 +173,21 @@ TestNGCPRealPrefs = {} --class
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
self.real:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),'caller')
assertNil(sr.pv.get("$xavp(callee_real_prefs=>testid)"))
assertNil(sr.pv.get("$xavp(callee_real_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>dummy)"),'caller')
assertNil(KSR.pv.get("$xavp(callee_real_prefs=>testid)"))
assertNil(KSR.pv.get("$xavp(callee_real_prefs=>foo)"))
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
end
function TestNGCPRealPrefs:test_caller_clean()
@ -206,21 +200,21 @@ TestNGCPRealPrefs = {} --class
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
self.real:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertNil(sr.pv.get("$xavp(caller_real_prefs=>other)"))
assertNil(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertNil(KSR.pv.get("$xavp(caller_real_prefs=>other)"))
assertNil(KSR.pv.get("$xavp(caller_real_prefs=>otherfoo)"))
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
end
function TestNGCPRealPrefs:test_tostring()

@ -23,8 +23,10 @@ local utils = require 'ngcp.utils'
local utable = utils.table
local UPFetch = require 'tests_v.up_vars'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
local mc,env,con
local up_vars = UPFetch:new()
@ -67,15 +69,7 @@ TestNGCPUserPrefs = {} --class
end
function TestNGCPUserPrefs:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---TestNGCPUserPrefs::cleaned---")
KSR.pv.vars = {}
end
function TestNGCPUserPrefs:test_caller_load_empty()
@ -100,14 +94,14 @@ TestNGCPUserPrefs = {} --class
if set then
keys_expected = utable.deepcopy(set)
for _,v in pairs(keys_expected) do
sr.log("dbg", string.format("removed key:%s is been loaded.", v))
KSR.log("dbg", string.format("removed key:%s is been loaded.", v))
defaults[v] = nil
end
end
for k,v in pairs(defaults) do
utable.add(keys_expected, k)
assertEquals(sr.pv.get("$xavp("..level.."_usr_prefs=>"..k..")"), v)
assertEquals(KSR.pv.get("$xavp("..level.."_usr_prefs=>"..k..")"), v)
end
return keys_expected
end
@ -137,11 +131,11 @@ TestNGCPUserPrefs = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>account_id)"),2)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>cli)"),"4311001")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>cc)"),"43")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>ac)"),"1")
--assertEquals(sr.pv.get("$xavp(caller_real_prefs=>ringtimeout)"), self.d.config.default.usr.ringtimeout)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>account_id)"),2)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>cli)"),"4311001")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>cc)"),"43")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>ac)"),"1")
--assertEquals(KSR.pv.get("$xavp(caller_real_prefs=>ringtimeout)"), self.d.config.default.usr.ringtimeout)
assertItemsEquals(keys, TestNGCPUserPrefs:get_defaults("caller", {"account_id", "cli", "cc", "ac", "ringtimeout"}))
end
@ -170,11 +164,11 @@ TestNGCPUserPrefs = {} --class
}
assertItemsEquals(keys, lkeys)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>account_id)"),2)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>cli)"),"4311001")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>cc)"),"43")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>ac)"),"1")
--assertEquals(sr.pv.get("$xavp(callee_real_prefs=>ringtimeout)"), self.d.config.default.usr.ringtimeout)
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>account_id)"),2)
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>cli)"),"4311001")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>cc)"),"43")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>ac)"),"1")
--assertEquals(KSR.pv.get("$xavp(callee_real_prefs=>ringtimeout)"), self.d.config.default.usr.ringtimeout)
assertItemsEquals(keys, TestNGCPUserPrefs:get_defaults("callee", {"account_id", "cli", "cc", "ac", "ringtimeout"}))
end
@ -182,12 +176,12 @@ TestNGCPUserPrefs = {} --class
local xavp = NGCPUserPrefs:xavp('callee')
xavp("testid",1)
xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
self.d:clean()
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"), "callee")
end
function TestNGCPUserPrefs:test_callee_clean()
@ -197,19 +191,19 @@ TestNGCPUserPrefs = {} --class
local caller_xavp = NGCPUserPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),'caller')
assertNil(sr.pv.get("$xavp(callee_usr_prefs=>testid)"))
assertNil(sr.pv.get("$xavp(callee_usr_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"),'caller')
assertNil(KSR.pv.get("$xavp(callee_usr_prefs=>testid)"))
assertNil(KSR.pv.get("$xavp(callee_usr_prefs=>foo)"))
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
end
function TestNGCPUserPrefs:test_caller_clean()
@ -219,19 +213,19 @@ TestNGCPUserPrefs = {} --class
local caller_xavp = NGCPUserPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>other)"),1)
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertNil(sr.pv.get("$xavp(caller_usr_prefs=>other)"))
assertNil(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertNil(KSR.pv.get("$xavp(caller_usr_prefs=>other)"))
assertNil(KSR.pv.get("$xavp(caller_usr_prefs=>otherfoo)"))
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(KSR.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
end
function TestNGCPUserPrefs:test_tostring()

@ -20,8 +20,10 @@
require('luaunit')
local NGCPXAvp = require 'ngcp.xavp'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
local vals = {
{
@ -57,11 +59,15 @@ local vals = {
}
-- luacheck: ignore TestNGCPXAvp
TestNGCPXAvp = {} --class
function TestNGCPXAvp:tearDown()
KSR.pv.vars = {}
end
function TestNGCPXAvp:test_create()
local xavp = NGCPXAvp:new("caller", "peer", {})
assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_peer=>dummy)"),"caller")
xavp = NGCPXAvp:new("callee", "peer", {})
assertEquals(sr.pv.get("$xavp(callee_peer=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_peer=>dummy)"),"callee")
end
function TestNGCPXAvp:test_xavp_id()
@ -74,17 +80,17 @@ TestNGCPXAvp = {} --class
function TestNGCPXAvp:test_xavp_get()
local xavp = NGCPXAvp:new("caller", "peer", vals)
sr.pv.sets("$xavp(caller_peer=>testid)", "value")
KSR.pv.sets("$xavp(caller_peer=>testid)", "value")
assertEquals(xavp("testid"), "value")
sr.pv.sets("$xavp(caller_peer=>testid)", "1")
KSR.pv.sets("$xavp(caller_peer=>testid)", "1")
assertItemsEquals(xavp("testid"), "1")
end
function TestNGCPXAvp:test_xavp_get_all()
local xavp = NGCPXAvp:new("caller", "peer", vals)
sr.pv.sets("$xavp(caller_peer=>testid)", "value")
KSR.pv.sets("$xavp(caller_peer=>testid)", "value")
assertEquals(xavp("testid"), "value")
sr.pv.sets("$xavp(caller_peer[0]=>testid)", "1")
KSR.pv.sets("$xavp(caller_peer[0]=>testid)", "1")
assertItemsEquals(xavp:all("testid"), {"1", "value"})
end
@ -94,34 +100,34 @@ TestNGCPXAvp = {} --class
for i=1,#lvals do
xavp("testid",lvals[i])
assertEquals(xavp("testid"), lvals[i])
assertEquals(sr.pv.get("$xavp(caller_peer=>testid)"),lvals[i])
assertEquals(KSR.pv.get("$xavp(caller_peer=>testid)"),lvals[i])
end
end
function TestNGCPXAvp:test_clean()
local xavp = NGCPXAvp:new("caller", "peer", vals)
xavp("testid", 1)
assertEquals(sr.pv.get("$xavp(caller_peer=>testid)"),1)
assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_peer=>testid)"),1)
assertEquals(KSR.pv.get("$xavp(caller_peer=>dummy)"),"caller")
xavp:clean()
assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_peer=>dummy)"),"caller")
assertNil(xavp("testid"))
assertNil(sr.pv.get("$xavp(caller_peer=>testid)"))
assertNil(KSR.pv.get("$xavp(caller_peer=>testid)"))
end
function TestNGCPXAvp:test_clean_all()
local xavp_caller = NGCPXAvp:new("caller", "peer", {})
assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(caller_peer=>dummy)"),"caller")
local xavp_callee = NGCPXAvp:new("callee", "peer", {})
assertEquals(sr.pv.get("$xavp(callee_peer=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(callee_peer=>dummy)"),"callee")
xavp_caller:clean()
assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_peer=>dummy)"),"callee")
assertEquals(KSR.pv.get("$xavp(caller_peer=>dummy)"),"caller")
assertEquals(KSR.pv.get("$xavp(callee_peer=>dummy)"),"callee")
xavp_callee:clean()
assertEquals(sr.pv.get("$xavp(callee_peer=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"), "caller")
assertEquals(KSR.pv.get("$xavp(callee_peer=>dummy)"), "callee")
assertEquals(KSR.pv.get("$xavp(caller_peer=>dummy)"), "caller")
end
function TestNGCPXAvp:test_clean_key()
@ -130,7 +136,7 @@ TestNGCPXAvp = {} --class
for i=1,#lvals do
xavp("testid",lvals[i])
assertEquals(xavp("testid"), lvals[i])
assertEquals(sr.pv.get("$xavp(caller_peer=>testid)"),lvals[i])
assertEquals(KSR.pv.get("$xavp(caller_peer=>testid)"),lvals[i])
end
xavp("other", 1)
xavp("other", 2)

@ -21,14 +21,16 @@ require('luaunit')
local NGCPXAvp = require 'ngcp.xavp'
local NGCPAvp = require 'ngcp.avp'
local ksrMock = require 'mocks.ksr'
local srMock = require 'mocks.sr'
sr = srMock:new()
KSR = ksrMock.new()
sr = srMock.new(KSR)
-- luacheck: ignore TestUseCases
TestUseCases = {}
function TestUseCases:tearDown()
sr.pv.vars = {}
KSR.pv.vars = {}
end
function TestUseCases:test_copy_avp()

Loading…
Cancel
Save