aboutsummaryrefslogtreecommitdiffstats
path: root/.gitreview
blob: 496884445efb5a1ec564aaf690fc87c58c26ea21 (plain)
1
2
3
4
[gerrit]
host=gerrit.onap.org
port=29418
project=dcaegen2/platform/blueprints.git
ape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# -------------------------------------------------------------------------
#   Copyright (c) 2017-2018 AT&T Intellectual Property
#
#   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 osdf.adapters.dcae.message_router as MR
import unittest

from osdf.operation.exceptions import MessageBusConfigurationException
from unittest.mock import patch


class TestMessageRouter(unittest.TestCase):

    def test_valid_MR(self):
        mr = MR.MessageRouterClient(dmaap_url="https://MYHOST:3905")

    def test_valid_MR_with_base_urls(self):
        base_urls = ["https://MYHOST1:3905/","https://MYHOST2:3905/"]
        mr = MR.MessageRouterClient(mr_host_base_urls=base_urls, topic="MY-TOPIC")

    def test_invalid_valid_MR_with_base_urls(self):
        """Topic missing"""
        base_urls = ["https://MYHOST1:3905/","https://MYHOST2:3905/"]
        try:
            mr = MR.MessageRouterClient(mr_host_base_urls=base_urls)
        except MessageBusConfigurationException:
            return

        raise Exception("Allows invalid MR configuration") # if it failed to error out

    @patch('osdf.adapters.dcae.message_router.MessageRouterClient.http_request', return_value={})
    def test_mr_http_request_mocked(self, http_request):
        mr = MR.MessageRouterClient(dmaap_url="https://MYHOST:3905")
        mr.http_request = http_request
        assert mr.get() == {} 
        assert mr.post("Hello") == {} 

    def test_mr_http_request_non_existent_host(self):
        mr = MR.MessageRouterClient(dmaap_url="https://MYHOST:3905")
        try:
            mr.get()
        except:
            return

        raise Exception("Allows invalid host") # if it failed to error out
if __name__ == "__main__":
    unittest.main()