Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-autograde
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CS-107
moodle-autograde
Commits
55e1fa42
Commit
55e1fa42
authored
4 months ago
by
Hamza Remmal
Browse files
Options
Downloads
Patches
Plain Diff
Polish the testing for '/api/v1/ping'
parent
bbf7a0fc
No related branches found
No related tags found
1 merge request
!308
Polish the testing for '/api/v1/ping'
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
autograde-service/src/test/java/ch/epfl/autograde/controller/api/v1/PingControllerIntegrationTests.java
+13
-9
13 additions, 9 deletions
...ade/controller/api/v1/PingControllerIntegrationTests.java
with
13 additions
and
9 deletions
autograde-service/src/test/java/ch/epfl/autograde/controller/api/v1/PingControllerTest.java
→
autograde-service/src/test/java/ch/epfl/autograde/controller/api/v1/PingController
Integration
Test
s
.java
+
13
−
9
View file @
55e1fa42
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
PingController
Integration
Test
s
{
/** 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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment