...
Use API calls to verify behavior
Always verify positive flow using integration tests
All integrations with outside applications/databases performed using https://testcontainers.com/
Real-service injections to the method are prohibited
In exceptional cases, they can be injected using
@Authowired ProductionComponent component
notation at class level
Asserts must be as simple as possible
Code Block language java mockMvc.perform(get("/entities") .header(TENANT, TENANT_ID) .andExpect(status().isOk()) .andExpect(content().json(asJsonString(readTemplate("/json/responses/entity.json")), true)));
Code Block language java mockMvc.perform(post("/entities") .content(capabilityToCreateAsJson) .header(TENANT, TENANT_ID) .contentType(APPLICATION_JSON)) .andExpect(status().isCreated()) .andExpect(content().json(asJsonString(readTemplate("/json/responses/entity.json")))) .andExpect(jsonPath("$.id").value(notNullValue())) .andExpect(jsonPath("$.metadata.createdBy").value(equalTo(USER_ID))) .andExpect(jsonPath("$.metadata.createdDate").value(notNullValue())) .andExpect(jsonPath("$.metadata.modifiedBy").doesNotExist()) .andExpect(jsonPath("$.metadata.modifiedDate").doesNotExist());
Verify that external data is created in outside service
Java HTTP client can be used to verify data in Keycloak
JDBC Helpers classes to verify database data performing native SQL requests, if it cannot be checked using API
Kong created routes can be verified using wiremock and keycloak native functionality mgr-tenant-entitlements: EntitilementRoutesIT