-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
api/quiz-api/src/test/java/com/c4soft/quiz/web/QuizControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.c4soft.quiz.web; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import com.c4_soft.springaddons.security.oauth2.test.annotations.WithJwt; | ||
import com.c4_soft.springaddons.security.oauth2.test.webmvc.AutoConfigureAddonsWebmvcResourceServerSecurity; | ||
import com.c4_soft.springaddons.security.oauth2.test.webmvc.MockMvcSupport; | ||
import com.c4soft.quiz.EnableSpringDataWebSupportTestConf; | ||
import com.c4soft.quiz.SecurityConfig; | ||
import com.c4soft.quiz.web.dto.QuizUpdateDto; | ||
|
||
@WebMvcTest(controllers = QuizController.class) | ||
@ActiveProfiles("h2") | ||
@Import({ EnableSpringDataWebSupportTestConf.class, ExceptionHandlers.class, SecurityConfig.class }) | ||
@AutoConfigureAddonsWebmvcResourceServerSecurity | ||
class QuizControllerTest { | ||
@Autowired | ||
MockMvcSupport api; | ||
|
||
@Test | ||
@WithJwt("ch4mp.json") | ||
void givenUserIsCh4mp_whenPayloadIsInvalid_then422WithValidationExceptionsInProblemDetails() throws Exception { | ||
api | ||
.post(new QuizUpdateDto("", null, null, null, null), "/quizzes") | ||
.andExpect(status().isUnprocessableEntity()) | ||
.andExpect(jsonPath("$.invalidFields.title", is("NotEmpty"))) | ||
.andExpect(jsonPath("$.invalidFields.isChoicesShuffled", is("NotNull"))) | ||
.andExpect(jsonPath("$.invalidFields.isReplayEnabled", is("NotNull"))) | ||
.andExpect(jsonPath("$.invalidFields.isPerQuestionResult", is("NotNull"))) | ||
.andExpect(jsonPath("$.invalidFields.isTrainerNotifiedOfNewTests", is("NotNull"))); | ||
} | ||
} |