-
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.
feat: Update Spring Boot version, add H2 dependency, and adjust Objec…
…tMapper - Update Spring Boot version in pom.xml from 3.2.1 to 3.2.2. - Add H2 database dependency in pom.xml. - Adjust ObjectMapper interface with null value handling strategies. - Refactor SchoolController with RequiredArgsConstructor annotation. - Remove AlreadyExistException class. - Modify SchoolService update method parameter names for clarity. Signed-off-by: pierresomny <[email protected]>
- Loading branch information
1 parent
80df494
commit 17e2338
Showing
13 changed files
with
992 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Test | ||
|
||
on: [ workflow_dispatch, push ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
- name: Run the Maven verify phase | ||
run: mvn --batch-mode --update-snapshots verify |
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
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
7 changes: 0 additions & 7 deletions
7
src/main/java/com/sfeiropensource/schoolapp/exception/AlreadyExistException.java
This file was deleted.
Oops, something went wrong.
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
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
110 changes: 110 additions & 0 deletions
110
src/test/java/com/sfeiropensource/schoolapp/controller/SchoolControllerTest.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,110 @@ | ||
package com.sfeiropensource.schoolapp.controller; | ||
|
||
import com.sfeiropensource.schoolapp.exception.NotFoundException; | ||
import com.sfeiropensource.schoolapp.model.CreateSchoolDTO; | ||
import com.sfeiropensource.schoolapp.model.SchoolDTO; | ||
import com.sfeiropensource.schoolapp.model.SearchSchoolDTO; | ||
import com.sfeiropensource.schoolapp.service.SchoolService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.util.List; | ||
|
||
import static com.sfeiropensource.schoolapp.utils.Objects.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
class SchoolControllerTest { | ||
|
||
@Mock | ||
private SchoolService schoolService; | ||
|
||
@InjectMocks | ||
private SchoolController schoolController; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
void getAll() { | ||
ResponseEntity<List<SchoolDTO>> expectedResult = ResponseEntity.ok(List.of()); | ||
|
||
when(schoolService.getAll()).thenReturn(expectedResult); | ||
|
||
ResponseEntity<List<SchoolDTO>> result = schoolController.getAll(); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void search() { | ||
int pageNumber = 0; | ||
int pageSize = 10; | ||
SearchSchoolDTO searchSchoolDTO = generateSearchSchoolDTO(); | ||
ResponseEntity<Page<SchoolDTO>> expectedResult = ResponseEntity.ok(new PageImpl<>(List.of())); | ||
|
||
when(schoolService.search(pageNumber, pageSize, searchSchoolDTO)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<Page<SchoolDTO>> result = schoolController.search(searchSchoolDTO, pageNumber, pageSize); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void add() { | ||
CreateSchoolDTO createSchoolDTO = generateCreateSchoolDTO(); | ||
ResponseEntity<SchoolDTO> expectedResult = ResponseEntity.ok(generateSchoolDTO()); | ||
|
||
when(schoolService.saveSchool(createSchoolDTO)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<SchoolDTO> result = schoolController.add(createSchoolDTO); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void get() throws NotFoundException { | ||
String id = "id"; | ||
ResponseEntity<SchoolDTO> expectedResult = ResponseEntity.ok(generateSchoolDTO()); | ||
|
||
when(schoolService.get(id)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<SchoolDTO> result = schoolController.get(id); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void update() throws NotFoundException { | ||
String id = "id"; | ||
CreateSchoolDTO createSchoolDTO = generateCreateSchoolDTO(); | ||
ResponseEntity<SchoolDTO> expectedResult = ResponseEntity.ok(generateSchoolDTO()); | ||
|
||
when(schoolService.update(id, createSchoolDTO)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<SchoolDTO> result = schoolController.update(id, createSchoolDTO); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void delete() { | ||
String id = "id"; | ||
ResponseEntity<HttpStatus> expectedResult = new ResponseEntity<>(HttpStatus.NO_CONTENT); | ||
|
||
when(schoolService.delete(id)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<HttpStatus> result = schoolController.delete(id); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/test/java/com/sfeiropensource/schoolapp/controller/UserControllerTest.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,110 @@ | ||
package com.sfeiropensource.schoolapp.controller; | ||
|
||
import com.sfeiropensource.schoolapp.exception.NotFoundException; | ||
import com.sfeiropensource.schoolapp.model.CreateUserDTO; | ||
import com.sfeiropensource.schoolapp.model.SearchUserDTO; | ||
import com.sfeiropensource.schoolapp.model.UserDTO; | ||
import com.sfeiropensource.schoolapp.service.UserService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.util.List; | ||
|
||
import static com.sfeiropensource.schoolapp.utils.Objects.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
class UserControllerTest { | ||
|
||
@Mock | ||
private UserService schoolService; | ||
|
||
@InjectMocks | ||
private UserController schoolController; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
void getAll() { | ||
ResponseEntity<List<UserDTO>> expectedResult = ResponseEntity.ok(List.of()); | ||
|
||
when(schoolService.getAll()).thenReturn(expectedResult); | ||
|
||
ResponseEntity<List<UserDTO>> result = schoolController.getAll(); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void search() { | ||
int pageNumber = 0; | ||
int pageSize = 10; | ||
SearchUserDTO searchUserDTO = generateSearchUserDTO(); | ||
ResponseEntity<Page<UserDTO>> expectedResult = ResponseEntity.ok(new PageImpl<>(List.of())); | ||
|
||
when(schoolService.search(pageNumber, pageSize, searchUserDTO)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<Page<UserDTO>> result = schoolController.search(searchUserDTO, pageNumber, pageSize); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void add() { | ||
CreateUserDTO createUserDTO = generateCreateUserDTO(); | ||
ResponseEntity<UserDTO> expectedResult = ResponseEntity.ok(generateUserDTO()); | ||
|
||
when(schoolService.add(createUserDTO)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<UserDTO> result = schoolController.add(createUserDTO); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void get() throws NotFoundException { | ||
String id = "id"; | ||
ResponseEntity<UserDTO> expectedResult = ResponseEntity.ok(generateUserDTO()); | ||
|
||
when(schoolService.get(id)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<UserDTO> result = schoolController.get(id); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void update() throws NotFoundException { | ||
String id = "id"; | ||
CreateUserDTO createUserDTO = generateCreateUserDTO(); | ||
ResponseEntity<UserDTO> expectedResult = ResponseEntity.ok(generateUserDTO()); | ||
|
||
when(schoolService.update(id, createUserDTO)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<UserDTO> result = schoolController.update(id, createUserDTO); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void delete() { | ||
String id = "id"; | ||
ResponseEntity<HttpStatus> expectedResult = new ResponseEntity<>(HttpStatus.NO_CONTENT); | ||
|
||
when(schoolService.delete(id)).thenReturn(expectedResult); | ||
|
||
ResponseEntity<HttpStatus> result = schoolController.delete(id); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
} |
Oops, something went wrong.