X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=inline;f=rwlaunchpad%2Fplugins%2Frwmonparam%2Ftest%2Futest_aggregator.py;fp=rwlaunchpad%2Fplugins%2Frwmonparam%2Ftest%2Futest_aggregator.py;h=f7b8e882ddc28dcb40e451e8ce4bd3c1dd8fbdd7;hb=6f07e6f33f751ab4ffe624f6037f887b243bece2;hp=0000000000000000000000000000000000000000;hpb=72a563886272088feb7cb52e4aafbe6d2c580ff9;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwmonparam/test/utest_aggregator.py b/rwlaunchpad/plugins/rwmonparam/test/utest_aggregator.py new file mode 100644 index 00000000..f7b8e882 --- /dev/null +++ b/rwlaunchpad/plugins/rwmonparam/test/utest_aggregator.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 + +# +# Copyright 2016 RIFT.IO Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import asyncio +import base64 +import logging +import os +import sys +import tornado.escape +import tornado.platform.asyncio +import tornado.testing +import tornado.web +import unittest +import xmlrunner + +import rift.tasklets.rwmonparam.aggregator as aggregator + + +from gi.repository import VnfrYang + +logger = logging.getLogger("mon_params_test.py") + + +class TestAggregator(unittest.TestCase): + + def test_int_aggregator(self): + int_agg = aggregator.IntValueAggregator("SUM", [1, 2, 3]) + self.assertEqual(int_agg.aggregate(), ("value_integer", 6)) + + int_agg = aggregator.IntValueAggregator("AVERAGE", [1, 2, 3]) + self.assertEqual(int_agg.aggregate(), ("value_integer", 2)) + + int_agg = aggregator.IntValueAggregator("MAXIMUM", [1, 2, 3]) + self.assertEqual(int_agg.aggregate(), ("value_integer", 3)) + + int_agg = aggregator.IntValueAggregator("MINIMUM", [1, 2, 3]) + self.assertEqual(int_agg.aggregate(), ("value_integer", 1)) + + int_agg = aggregator.IntValueAggregator("COUNT", [1, 2, 3]) + self.assertEqual(int_agg.aggregate(), ("value_integer", 3)) + + def test_decimal_aggregator(self): + int_agg = aggregator.DecimalValueAggregator("SUM", [1.1, 2, 3]) + self.assertEqual(int_agg.aggregate(), ("value_decimal", 6.1)) + + int_agg = aggregator.DecimalValueAggregator("AVERAGE", [1, 2, 3]) + self.assertEqual(int_agg.aggregate(), ("value_decimal", 2.0)) + + int_agg = aggregator.DecimalValueAggregator("MAXIMUM", [1, 2, 3.3]) + self.assertEqual(int_agg.aggregate(), ("value_decimal", 3.3)) + + int_agg = aggregator.DecimalValueAggregator("MINIMUM", [1.1, 2, 3.3]) + self.assertEqual(int_agg.aggregate(), ("value_decimal", 1.1)) + + int_agg = aggregator.DecimalValueAggregator("COUNT", [1.1, 2, 3.3]) + self.assertEqual(int_agg.aggregate(), ("value_decimal", 3)) + + +def main(argv=sys.argv[1:]): + + # The unittest framework requires a program name, so use the name of this + # file instead (we do not want to have to pass a fake program name to main + # when this is called from the interpreter). + unittest.main( + argv=[__file__] + argv, + testRunner=xmlrunner.XMLTestRunner(output=os.environ["RIFT_MODULE_TEST"]) + ) + +if __name__ == '__main__': + main() +