Skip to content
Snippets Groups Projects
Commit 55e1fa42 authored by Hamza Remmal's avatar Hamza Remmal
Browse files

Polish the testing for '/api/v1/ping'

parent bbf7a0fc
No related branches found
No related tags found
1 merge request!308Polish the testing for '/api/v1/ping'
package ch.epfl.autograde.controller.api.v1;
import ch.epfl.autograde.filters.AssignRequestIdFilter;
import ch.epfl.autograde.utils.context.WithSharedSecretAuthentication;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
......@@ -29,9 +31,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*
* @author Hamza REMMAL (hamza.remmal@epfl.ch)
*/
@AutoConfigureMockMvc
@SpringBootTest
public final class PingControllerTest {
@SpringBootTest @AutoConfigureMockMvc
@DisplayName("[Integration Tests] '/api/v1/ping'")
public final class PingControllerIntegrationTests {
/** The endpoint to perform a ping */
private final static String PING_END_POINT = "/api/v1/ping";
......@@ -40,7 +42,7 @@ public final class PingControllerTest {
private MockMvc mockMvc;
/**
* If <b>not</b> authenticated with the shared secret, the request to `/api/v1/ping`
* If <b>not</b> authenticated with the shared secret, the request to `GET:/api/v1/ping`
* should be <b>successful</b>
* <p>
* The following test will verify that:
......@@ -49,21 +51,23 @@ public final class PingControllerTest {
* <li>The {@link HttpHeaders.CONTENT_TYPE} is {@link MediaType.APPLICATION_JSON}</li>
* <li>The request will not generate cookies</li>
* <li>The {@code $.auth} field in the response's body is {@code false}</li>
* <li>A `X-Request-Id` header was set in the response</li>
* </ul>
*/
@Test
@Test @DisplayName("'GET:/api/v1/ping' without authentication works as expected")
void successPingWithoutKey() throws Exception {
mockMvc.perform(get(PING_END_POINT))
.andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON),
header().doesNotExist(HttpHeaders.SET_COOKIE),
header().exists(AssignRequestIdFilter.REQUEST_ID_HEADER),
jsonPath("$.auth").value(false)
);
}
/**
* If authenticated with the shared secret, the request to `/api/v1/ping`
* If authenticated with the shared secret, the request to `GET:/api/v1/ping`
* should be <b>successful</b>
* <p>
* The following test will verify that:
......@@ -72,9 +76,10 @@ public final class PingControllerTest {
* <li>The {@link HttpHeaders.CONTENT_TYPE} is {@link MediaType.APPLICATION_JSON}</li>
* <li>The request will not generate cookies</li>
* <li>The {@code $.auth} field in the response's body is {@code true}</li>
* <li>A `X-Request-Id` header was set in the response</li>
* </ul>
*/
@Test
@Test @DisplayName("'GET:/api/v1/ping' with authentication works as expected")
@WithSharedSecretAuthentication
void successPingWithKey() throws Exception {
mockMvc.perform(get(PING_END_POINT))
......@@ -82,10 +87,9 @@ public final class PingControllerTest {
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON),
header().doesNotExist(HttpHeaders.SET_COOKIE),
header().exists(AssignRequestIdFilter.REQUEST_ID_HEADER),
jsonPath("$.auth").value(true)
);
}
// TODO: We need to test authorization here when we implement it
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment