question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Asset a specific message when multiple messages flowing through the brokers or topics

See original GitHub issue

Created from #220

2. When testing in real environment, there will be multiple messages flowing through the brokers/topics. How can zerocode validate/asset a specific response? Ans: Use Json Path to look for a perticular message or a record key or value. Very easy! e.g.

When you have consume multiple records from a topic, that means you receive an array of records as the response. Then you can assert this way explained in the readme-file.

Where is this JSON path is applied ? In JUNIT or within Zerocode JSON config ?

For example, my test below keeps on failing. In the log, instead of just consuming the messages with the ids I have specified below. It consumes the whole array of 10 messages.

{
    "scenarioName": "consume a JSON message with id_5 & id_9 out of 10 messages produced on topic_A",
    "steps": [

        {
            "name": "consume_step",
            "url": "kafka-topic:topic_A",
            "operation": "consume",
            "request": {
                "consumerLocalConfigs": {
                    "recordType": "JSON",
                    "commitSync": true,
                    "showRecordsConsumed": true,
                    "maxNoOfRetryPollsOrTimeouts": 3
                }
            },
            "assertions": {
                "records": [
                    {
                        "key": "id_5",
                        "value": {

                            "TEST": "Test Val0"
                        }
                    },
                    {
                        "key": "id_9",
                        "value": {

                            "TEST": "Test Val9"
                        }
                    }
                ]
            }
        }
    ]
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tghani93commented, Mar 31, 2019

@authorjapps , very grateful for your responses and pointers. Will have keep you posted on the blog! 😃

1reaction
authorjappscommented, Mar 29, 2019

Yes secure APIs as you mentioned and in general as well 😃 I am planning on doing a blog about Zerocode also, so wanted to obtain a deeper understanding as well.

That sounds cool. 👍

  • For Oauth2 one of our contributor(and user) has shared a very short and precise blog in the DZone Security Zone. I am tagging him(@santhoshTpixler ) here in case you need more details on this.

  • For Corporate Proxy configuration, you can follow the README section here

    • This is for any Http api invocation, for instance REST, SOAP etc
  • SAML/JWT are very straight forward - working examples are here - HelloWorld repo

  • If tokens are dynamic, it’s still easy to inject them into header in runtime.

  • If you use OpenAM or RedHat SSO or Simple Basic Auth

    • You can refer the examples in readme-file here
    • You can manually use per test-case wise or embed it to the HttpClient which is oneoff( and less maintenance overhead)
  • Zerocode’s Http Client supports Http and Https connections anyways.

    • But you can override and add/remove security features to match your project requirement.
    • See example here - in HelloWorld
    @Override
    public CloseableHttpClient createHttpClient() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
        LOGGER.info("###Used SSL Enabled Http Client for http/https/TLS connections");

       // Add your own security flavour and return the client, 
       // then all test-cases will start using this client.
       // That's it really!

        return HttpClients.custom()
                .setSSLContext(sslContext)
                .setSSLHostnameVerifier(new NoopHostnameVerifier())
                .setDefaultCookieStore(cookieStore)
                .build();
    }
  • Then it’s very simple and straight forward to use like below-

Just annotate your test class or suite class.

@UseHttpClient(CustomHttpClient.class)
  • In similar fashion, you can inject any custom headers you need. Explained here e.g.
    @Override
    public Map<String, Object> amendRequestHeaders(Map<String, Object> headers) {
        // ----------------------------------------------------
        // Add your custom headers here(if any).
        // e.g. Your auth tokens, client_id or client_secret etc
        // ----------------------------------------------------
        if (headers != null) {
            addCustomHeaders(headers);
        } else {
            headers = new HashMap<>();
            addCustomHeaders(headers);
        }

        return headers;
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is a Message Broker? How It Helps You Scale for Success
Message brokers act as a bridge between different message queues (MQs) and enable distributed processing of messages across multiple cluster ...
Read more >
Apache Kafka Queue 101: Messaging Made Easy - Learn | Hevo
Messages are saved as topics in each broker. Topics are separated into divisions, and each message is assigned to one of these partitions....
Read more >
Message routing, filtering, ordering - Solace vs. Kafka
PubSub+ message brokers match messages against subscriptions in real-time as messages enter the broker and queue them to consumers without involvement from the ......
Read more >
Lessons Learned From Running Kafka at Datadog
Kafka stores data across partitions in each topic, and each partition has a leader and zero or more followers that fetch and replicate...
Read more >
What is MQTT and How Does it Work? - TechTarget
The broker pushes information to subscribers. The broker's job is to push information out to clients that have subscribed to a topic. Most...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found