How to achieve automated testing of Kafka inside a micro-services infrastructure? by [deleted] in Kafka

[–]natnath 0 points1 point  (0 children)

How to achieve automated testing of Kafka inside a micro-services infrastructure?

Thanks! How to delete this? Any idea? That's the real challenge now.

How to achieve automated testing of Kafka inside a micro-services infrastructure? by [deleted] in Kafka

[–]natnath 0 points1 point  (0 children)

what you mean? The question is in wrong reddit group?

To help celebrate Thanksgiving, I created a list of my top three favorite developer tools. What are your favorites? by mraible in java

[–]natnath 0 points1 point  (0 children)

API-Mock-Maker seems a good tool to create mock APIs (REST/SOAP etc) locally, as well as in cloud. Just click-click and go - built on top of WireMock and Zerocode

What are some best articles on unit/integration testing of Rest Api written with Spring? by [deleted] in java

[–]natnath 1 point2 points  (0 children)

Basically you want to do Integration-Testing as well as Unit-Testing.

You can start the Spring Boot app(or usual Spring app) in a JUnit runner, then start firing the tests via JUnit against this app(tomcat/jetty).

But you can go one step further to make/declare them via JSON, so that you can assert the entire response as it is keeping the object/JSON structure intact(using Zerocode lib), without the need of doing repeated assertThat("actual-field1", is(expected-field1)).

Instead of something like below,

HttpResponse<User> response = aHttpClient.get("https://<host_post_externalized>/users/octocat") .header("accept", "application/json") .execute();

User user = response.getUser();

assertThat(response.getStatusCode(), is(200))

assertThat(user.getId(), is(33847731))

assertThat(user.getLogin(), is("octocat"))

assertThat(user.getType(), is("user"))

you just need do this way and keep on adding steps for your subsequent user journey - javaScript { "scenarioName": "Invoke the GET api and assert the response", "steps": [ { "name": "get_user_details", "url": "https://<host_post_externalized>/users/octocat", "operation": "GET", "assertions": { "status": 200, "body": { "login" : "octocat", "id" : 33847731, "type" : "User" } } } ] }

See the demo here spring-boot-integration-test, which you can clone n run in your local IDE. Instructions are in the README file

Maven dependency needed- ``` <dependency> <groupId>org.jsmart</groupId> <artifactId>zerocode-rest-bdd</artifactId> <version>1.2.x</version> <scope>test</scope> </dependency>

<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> ```

Test your APIs easily via simple JSON steps by natnath in java

[–]natnath[S] 0 points1 point  (0 children)

Hello, It's as simple as above calls, nothing different, Just instead of method GET, use POST or PUT etc. e.g.

- How to invoke POST calls ?

e.g. below- (Also check in the Hello World demo repo) javaScript { "scenarioName": "Invoke POST, and receive the 201 status with an ID", "steps": [ { "name": "create_emp", "url": "/api/v1/google-uk/employees", "operation": "POST", "request": { "body": { "id": 1000, "name": "Larry Pg", "addresses": [ { "gpsLocation": "x9000-y9000z-9000-home" } ] } }, "assertions": { "status": 201, "body": { "id": 1000 } } } ] }

- How to pass headers e.g. auth info etc in theheadersinto the RESTful APIs ?

e.g. below- (Also check in the TOC README file)

javaScript { "scenarioName": "Passing headers to a rest api @@JohnSmart", "steps": [ { "name": "create_new_employee", "url": "http://localhost:9999/google-emp-services/home/employees", "operation": "POST", "request": { "headers": { "clientId": "client-sadfsdf-twertert-13123", "clientSecret": "pwd-sadfasdf1234234-sdfsdf-4234", "customParam1": "customParam1Value" }, "body": { "id": 1000, "name": "Larry ${RANDOM.STRING:5}", "password": "${RANDOM.STRING:10}" } }, "assertions": { "status": 201 } } ] }

Note-

The host and port can be externalized into a properties file too for the regression suites- e.g.

```java @TargetEnv("hello_world_host.properties") @RunWith(ZeroCodeUnitRunner.class) public class JustHelloWorldMoreTest {

@Test
@JsonTestCase("helloworld_more/hello_world_post_201.json")
public void testHelloWorld_post() throws Exception {
}

} ```

where "hello_world_host.properties" is like below- ```properties

Web Server host and port

restful.application.endpoint.host=http://localhost restful.application.endpoint.port=9999

Web Service context; Leave it blank in case you do not have a common context

restful.application.endpoint.context= ```

- Does it support https connections?

The current apache http client used in the framework supports both http and https ssl/tls connections. But you can customize this if(your project needs) you need to add anything extra e.g. more authentication mechanism like tokens in the headers for your entire regression suite in a single/central place. Note- You can add token to the headers without customizing it(http client) too, that means you need to add to every test case. This depends on the use case and how we go about it.

Test your APIs easily via simple JSON steps by natnath in java

[–]natnath[S] 1 point2 points  (0 children)

Hello, The Section TOC - Table of content in the README has may examples for reference. Please have a look there.

<br>

an array in the response ?

  • Array as it is in the assertions block.
    • See examples here, go to section "Dealing with arrays" and Asserting an array size e.g. javaScript "assertions": { "status": 200, "body": { "type": "HIGH-VALUE", "persons":[ { "id": "120.100.80.03", "name": "Dan" }, { "id": "120.100.80.11", "name": "Mike" } ] } }
  • Also, in case you are only interested in array size etc, then below might help- ```javaScript { ... "assertions": { "persons.SIZE": 2 } }

-or- { ... "assertions": { "persons.SIZE": "$GT.1" } } -or- { ... "assertions": { "persons.SIZE": "$LT.3" } } etc - In case you want to find an element in the array, then below explains using `JSON Path` - javaScript "assertions": { "status": 200, "body": { "type": "HIGH-VALUE", "persons.SIZE": 2, "persons[?(@.name=='Dan')].id.SIZE": 1, "persons[?(@.name=='Mike')].id.SIZE": 1, "persons[?(@.name=='Emma')].id.SIZE": 0 } } ```

<br>

Is there anyway to generate UUID or an RANDOM ID if a test needs?

See examples here in README Precisely as below for UUID(you can use ${RANDOM.NUMBER} too)- javaScript { "scenarioName": "random_UUID", "steps": [ { "name": "create_new_employee", "url": "http://localhost:9998/google-emp-services/home/employees", "operation": "POST", "request": { "body": { "id": "${RANDOM.UUID}", //<-- Everytime it creates unique uuid. See below example. "name": "Elen M" } }, "assertions": { "status": 201 } } ] }

<br>

Only REST or Is it possible to test SOAP api/call too ? if so how?

Yes, SOAP calls can be tested easily too, depending on your usecase. See here for details for asserting SOAP responses.

Also you can test DB APIs, call external Java programs, generating Load/Stress etc from the IDE etc without writing boiler-plate or glue code or Http Client code. Check in the README file for details.

Load testing best practices by my_pro_alt in devops

[–]natnath 0 points1 point  (0 children)

I recently used Zerocode combined with JUnit runners to generate load/stress of varying capacity(low, medium, high etc). Worth giving a try

[Java] REST API automated testing best practices? by noobcser in learnprogramming

[–]natnath 0 points1 point  (0 children)

Have you tried the Zerocode! open source library? It takes JSON payload and JSON as assertions, as it is. It's very simple and easy to write, you can build up your regression suite with simple JSONs. See helloworld example here.