def test_1_send_message_to_gateway_instance(self, test_org_user_client):
        """
        <b>Description:</b>
        Check that it's possible to send messages to gateway instance.

        <b>Input data:</b>
        1. gateway app

        <b>Expected results:</b>
        Test passes when message is sent to gateway instance without errors.

        <b>Steps:</b>
        1. Expose service instance url.
        2. Send message to gateway instance.
        3. Check that no error is raised.
        """
        step("Expose service instance url")
        urls = ServiceInstance.expose_urls(service_id=self.gateway_instance.id,
                                           client=test_org_user_client)
        ServiceInstance.ensure_responding(url=urls[0])
        step("Retrieve oauth token")
        http_client = HttpClientFactory.get(ServiceConfigurationProvider.get())
        token = http_client._auth._token_header
        step("Check communication with gateway instance")
        header = {"Authorization": "{}".format(token)}
        ws_url = "{}/ws".format(urls[0].replace("http", WebsocketClient.WS))
        try:
            ws = WebsocketClient(ws_url, headers=header)
            ws.send("test")
            ws.close()
        except Exception as e:
            raise AssertionError(str(e))
    def test_expose_and_unexpose_urls(self, api_service_admin_client, offering_from_python_app):
        """ Verify if is it possible to expose, unexpose service instance URLS, exposed URLS responds.

            Push sample app, create new offering using image of sample app and create service instance of new offering.
            Expose service instance URLS, then tests assert that URLS responds and present in service instance
            credentials. After it unexpose URLS and verify if it is not in service credentials.

            Input data:
                Python application: application which is pushed on platform

            Expected results:
                It is possible to create new offering using image of pushed application. Service instance can be
                 exposed. Exposed URLS responds and present in service instance credentials.

            Steps:
                1. Create instance of new offering
                2. Expose URLS and check if responds
                3. Get credentials and verify if contains exposed URLS
                4. Unexpose URLS and verify if URLS are not in credentials
        """
        step("Create offering from sample_python_app")
        service = offering_from_python_app
        step("Expose urls")
        urls = ServiceInstance.expose_urls(service_id=service.id, client=api_service_admin_client)
        ServiceInstance.ensure_responding(url=urls[0])
        step("Get credentials and check that contains urls")
        credentials = ServiceInstance.get_credentials(service.id, api_service_admin_client)
        assert urls[0] in str(credentials)
        step("Unexpose urls")
        unexpose = ServiceInstance.expose_urls(service_id=service.id, client=api_service_admin_client,
                                               should_expose=False)
        credentials = ServiceInstance.get_credentials(service.id, api_service_admin_client)
        assert urls[0] not in unexpose, str(credentials)
    def test_elasticsearch(self, context, api_service_admin_client, plan):
        """
        <b>Description:</b>
        Verify if it is possible to create instance of Elasticsearch-24 and do some operations on search engine.

        Test creates Elasticsearch-24 instance, expose URLs and check cluster health, insert some data, search in data,
        count inserted data using Elasticsearch-24 REST Api.

        <b>Input data:</b>
        1. Elasticsearch-24 instance
        2. Sample json data

        <b>Expected results:</b>
        It is possible to create Elasticsearch-24 instance, expose its URLs and operations like insert data, search in
        data, count data work properly.

        <b>Steps:</b>
        1. Create Elasticsearch-24 instance
        2. Check Elasticsearch-24 cluster health
        3. Insert sample data
        4. Get inserted data
        5. Search in inserted data
        6. Count inserted data
        7. Insert new data
        8. Count inserted data
        """
        sample_data_1 = {
            "user": "******",
            "post_date": "2009-11-15T14:12:12",
            "message": "trying out Elasticsearch"
        }
        sample_data_2 = {
            "user": "******",
            "post_date": "2009-12-11T22:22:22",
            "message": "inserting new data to Elasticsearch"
        }
        add_data_msg = "\"total\":1,\"successful\":1,\"failed\":0"
        step("Create elasticsearch instance")
        elasticsearch = ServiceInstance.create_with_name(
            context=context,
            offering_label=ServiceLabels.ELASTICSEARCH24,
            plan_name=plan)
        elasticsearch.ensure_running(client=api_service_admin_client)
        urls = ServiceInstance.expose_urls(service_id=elasticsearch.id,
                                           client=api_service_admin_client)
        ServiceInstance.ensure_responding(url=urls[0])
        step("Check cluster health")
        response = requests.get(url="{}/_cluster/health".format(urls[0]))
        assert "\"status\":\"green\"", "\"number_of_nodes\":1" in str(
            response.content)
        step("Insert sample data")
        response = requests.put(url="{}/twitter/tweet/1".format(urls[0]),
                                data=json.dumps(sample_data_1),
                                headers={'Content-Type': 'application/json'})
        assert add_data_msg in str(response.content)
        step("Get inserted data")
        requests.get(url="{}/twitter/_refresh".format(urls[0]))
        response = requests.get(url="{}/twitter/tweet/1".format(urls[0]))
        step("Search in data")
        response_search = requests.get(
            url="{}/twitter/_search?q=user:kimchy".format(urls[0]))
        for value in sample_data_1.values():
            assert value in str(response.content)
            assert value in str(response_search.content)
        step("Count inserted data")
        response = requests.get(url="{}/twitter/_count".format(urls[0]))
        assert "\"count\":1" in str(response.content)
        step("Insert new data")
        requests.put(url="{}/twitter/tweet/2".format(urls[0]),
                     data=json.dumps(sample_data_2),
                     headers={'Content-Type': 'application/json'})
        requests.get(url="{}/twitter/_refresh".format(urls[0]))
        step("Count inserted data")
        response = requests.get(url="{}/twitter/_count".format(urls[0]))
        assert "\"count\":2" in str(response.content)