Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
Testing the Public APIs - How To

The good things about the Public APIs is that you can automate testing :-)

I have seen a Project "co-public-rest-api-test" showing how to do tests based on http Skripts. In the supersonic archetype there are also Tests (GreetingRestServiceRestTest) using RESTassured and the given, when, then convention - which I really like- but implementing the Authorisation/Authentication seems quite complex.

Any suggestions how to move on?

1
1
Posted one year ago
Votes Newest

Answers 2


Hi Angelo, ich glaube das wir hier gut weiterkommen sind. Bitte Frage schießen, lg zoni

  
  
Posted one year ago

Hallo Angelo,

Ja du hast Recht, testen geht mit der public-rest-api super.

(1)
Ursprünglich haben wir tatsächlich mit IntelliJ http File getestet,
welche nicht nur in IntelliJ exekutiert werden konnten,
sondern auch mittels maven.
Das war im Repo https://gitlab.com/CoCommunity/coco-projects/co-public-rest-api-test/

Ein Beispiel findest du hier:
https://gitlab.com/CoCommunity/coco-projects/co-public-rest-api-test/-/blob/develop/co-rest-tests/src/desktop/desktop-identities.http

Wie du sehen kannst wird in den ersten 12 Zeilen vom Keycloak ein access-token abgeholt
und in einer Javascript Variable access_token gespeichert.

Welche dann beim ersten Test in den Zeile 14-24 als Authorization Header übergeben wird.

Damit du einen Token vom Keycloak bekommst, brauchst du die

  1. auth-server-url (bei euch: https://campus.tum.de/tumonline/co/public/sec/auth/realms/CAMPUSonline)
  2. einen Testclient, den man im Keycloak anlegen muss, und dem man die entsprechenden Scopes geben muss
    => client_id, client_secret

(2)
Wir sind dann aber dazu übergegangen, nicht die HTTP Files zu verwenden,
sondern Quarkus als Testframework zu nutzen.

Hier findest du im der Public REST API anleihen, wie man das machen kann.
https://gitlab.com/CoCommunity/co-public-rest-api/-/tree/develop/pub-rest-api-testing

z.B. ein Test für Semester API:
https://gitlab.com/CoCommunity/co-public-rest-api/-/blob/develop/pub-rest-api-testing/pub-rest-test-semester/src/main/java/at/campusonline/pub/rest/test/semester/semesters/SemestersTestSuite.java

welcher wiederum von RestAssured angestoßen wird.

https://gitlab.com/CoCommunity/co-public-rest-api/-/blob/develop/pub-rest-api-testing/pub-rest-test-semester/src/test/java/at/campusonline/pub/rest/test/semester/semesters/SemestersTestSuiteTest.java

Man muss nur den Quarkus im Folder
https://gitlab.com/CoCommunity/co-public-rest-api/-/tree/develop/pub-rest-api-testing/pub-rest-test-semester
starten.
Das .env-template kopieren cp .env-template .env
https://gitlab.com/CoCommunity/co-public-rest-api/-/blob/develop/pub-rest-api-testing/pub-rest-test-semester/.env-template

Und die Werte in der .env Datei anpassen.

Wenn du willst kann ich dir in einer VK das mal zeigen :-)

lg zoni

1
1
Posted one year ago
1K Views
2 Answers
one year ago
one year ago
Tags