Template for InfraSight Labs code test. Includes kodtest-server as a bundled jar. Kodtest API which is a JSON REST API with data for the tests is provided by kodtest-server.
Building is driven by Maven (https://maven.apache.org) Use Java 11 (https://adoptium.net/temurin/releases/?version=11) when building with maven. Use JAVA_HOME to override which Java maven will use. Example in Windows:
set JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-11.0.17.8-hotspot
First run validate to install bundled kodtest-server jar into local maven repository. Do this in the kodtest-template folder where pom.xml exists.
mvn validate
Then compile and run tests:
mvn test
This will spin up Kodtest API accessible default on http:https://localhost:8080 and execute tests located in package com.infrasight.kodtest
annotated with @Test
.
You will notice that one test (com.infrasight.kodtest.Tests.assigment2
) fails. This is part of the assignments that you are expected to solve. It fails because of this snippet:
int groupCount = 0;
assertEquals(3, groupCount);
We expect the value to be 3 so in order to solve this you will need to use the Kodtest API to find groups requested and count them. Read more about writing tests under "Writing JUnit Tests".
To view the API documentation (OpenAPI3 generated by Swagger) you can run start Kodtest API manually from the kodtest-template folder.
First install bundled kodtest-server jar into local maven repository and compile the source:
mvn validate compile
Then start Kodtest API:
mvn exec:java -D"exec.args"="--port=8081 --apiUser=apiUser --apiPassword=apiPassword!"
The above syntax should work in Windows cmd/powershell and bash.
Access the API documentation by browsing to http:https://localhost:port. When running Kodtest API manually it may interfere with the server started by the tests so make sure you run them on different ports. You can change the port with option port.
Swagger also allows you to test the endpoints by clicking 'Try it out' and then 'Execute'.
Kodtest API is protected and requires authentication. Use values of options apiUser and apiPassword and authenticate towards http:https://localhost:8080/api/auth. The auth endpoint will return a token for a successful authentication. This token should then be set in the Authorization
header for requests to the accounts, groups and relationship endpoints.
Kodtest API uses simple bearer token authentication with the syntax:
Bearer mytoken
When entering the token in the Swagger-UI do not include "Bearer ". Only enter the token. Swagger automatically adds the Bearer prefix. When you add the header manually you will need to include the Bearer prefix yourself.
JUnit tests are placed in package com.infrasight.kodtest
. Every class containing test methods must extend com.infrasight.kodtest.TestsSetup
and every test method must be annotated with @Test
to be run by JUnit during mvn test
. By doing this, a Kodtest API is started on the configured port (default 8080) and access is enabled for anyone who authenticates with 'apiUser' and 'apiPassword!'.
If needed, change the default parameters used for tests in com.infrasight.kodtest.TestVariables
.
- API_PORT
- Which port the API server will listen on (default: 8080)
- API_USER
- The API user used for auth (default: apiUser)
- API_PASSWORD
- The API password used for auth (default: apiPassword!)
We expect that you submit your solutions as JUnit tests which we can evaluate by running mvn test
. In com.infrasight.kodtest.Tests
we have prepared methods 'assignmentX' which correspond to the assignments you are expected to solve. These are already annotated with @Test and will be run by mvn test
.
You are free to implement your solutions as you want but please provide instructions on how to run them.
Submit your maven project with your solutions either through a git-repository to which we have access or just mail us the zipped project.
Good luck!