1 # ============LICENSE_START=======================================================
2 # csit-dcaegen2-collectors-hv-ves
3 # ================================================================================
4 # Copyright (C) 2018 NOKIA
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
19 from robot.api import logger
21 DCAE_APP_NAME = "DCAE App"
24 class DcaeAppSimulatorLibrary:
26 def configure_dcae_app_simulator_to_consume_messages_from_topics(self, app_url, topics):
27 logger.info("PUT at: " + app_url)
28 resp = HttpRequests.session_without_env().put(app_url, data={'topics': topics}, timeout=10)
29 HttpRequests.checkStatusCode(resp.status_code, DCAE_APP_NAME)
31 def assert_DCAE_app_consumed(self, app_url, expected_messages_amount):
32 logger.info("GET at: " + app_url)
33 resp = HttpRequests.session_without_env().get(app_url, timeout=10)
34 HttpRequests.checkStatusCode(resp.status_code, DCAE_APP_NAME)
36 assert resp.content == expected_messages_amount, \
37 "Messages consumed by simulator: " + resp.content + " expecting: " + expected_messages_amount
39 def assert_DCAE_app_consumed_less_equal_than(self, app_url, messages_threshold):
40 logger.info("GET at: " + app_url)
41 resp = HttpRequests.session_without_env().get(app_url, timeout=10)
42 HttpRequests.checkStatusCode(resp.status_code, DCAE_APP_NAME)
44 logger.debug("Messages consumed by simulator: " + resp.content +
45 " expecting more than 0 and less/equal than " + messages_threshold)
47 assert 0 < int(resp.content) <= int(messages_threshold), \
48 "Messages consumed by simulator: " + resp.content + \
49 " expecting more than 0 and less/equal than " + messages_threshold
51 def reset_DCAE_app_simulator(self, app_url):
52 logger.info("DELETE at: " + app_url)
53 resp = HttpRequests.session_without_env().delete(app_url, timeout=10)
54 HttpRequests.checkStatusCode(resp.status_code, DCAE_APP_NAME)
56 def assert_DCAE_app_consumed_proper_messages(self, app_url, message_filepath):
57 logger.info("POST at: " + app_url)
58 file = open(message_filepath, "rb")
62 resp = HttpRequests.session_without_env().post(app_url, data=data, timeout=10)
63 HttpRequests.checkStatusCode(resp.status_code, DCAE_APP_NAME)