generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Admin cabinet] Fix Position and PositionDTOs, Add tests to all Posit…
…ion DTOs (#1147) * Added test for Position DTOS * Changed fields from nameEN to nameEn * Change annotation to @DaTa * Replaced lombok.* * deleted unnecessary import
- Loading branch information
Showing
20 changed files
with
215 additions
and
63 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
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
12 changes: 4 additions & 8 deletions
12
service-api/src/main/java/greencity/dto/position/AddingPositionDto.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 |
---|---|---|
@@ -1,20 +1,16 @@ | ||
package greencity.dto.position; | ||
|
||
import lombok.*; | ||
|
||
import lombok.Data; | ||
import lombok.Builder; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Pattern; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@ToString | ||
@Data | ||
public class AddingPositionDto { | ||
@NotNull | ||
@Pattern(regexp = "[ЁёІіЇїҐґЄєА-Яа-яA-Za-z-'\\s.]{1,30}") | ||
private String name; | ||
@Pattern(regexp = "[A-Za-z-'\\s.]{1,30}") | ||
private String nameEN; | ||
private String nameEn; | ||
} |
15 changes: 2 additions & 13 deletions
15
service-api/src/main/java/greencity/dto/position/PositionAuthoritiesDto.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
13 changes: 4 additions & 9 deletions
13
service-api/src/main/java/greencity/dto/position/PositionDto.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 |
---|---|---|
@@ -1,22 +1,17 @@ | ||
package greencity.dto.position; | ||
|
||
import lombok.*; | ||
|
||
import lombok.Data; | ||
import lombok.Builder; | ||
import javax.validation.constraints.Min; | ||
import javax.validation.constraints.Pattern; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
@Data | ||
public class PositionDto { | ||
@Min(1) | ||
private Long id; | ||
@Pattern(regexp = "[ЁёІіЇїҐґЄєА-Яа-яA-Za-z-'\\s.]{1,30}") | ||
private String name; | ||
@Pattern(regexp = "[A-Za-z-'\\s.]{1,30}") | ||
private String nameEN; | ||
private String nameEn; | ||
} |
11 changes: 3 additions & 8 deletions
11
service-api/src/main/java/greencity/dto/position/PositionWithTranslateDto.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
54 changes: 54 additions & 0 deletions
54
service-api/src/test/java/greencity/dto/position/AddingPositionDtoTest.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,54 @@ | ||
package greencity.dto.position; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class AddingPositionDtoTest { | ||
void nameRegex(String name, boolean validates) throws NoSuchFieldException { | ||
Field field = AddingPositionDto.class.getDeclaredField("name"); | ||
javax.validation.constraints.Pattern[] annotations = | ||
field.getAnnotationsByType(javax.validation.constraints.Pattern.class); | ||
assertEquals(name.matches(annotations[0].regexp()), validates); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource( | ||
strings = {"John Doe", "абвгґіїьяюєАБВГҐІЇЬЯЮЄ", "John-Doe", "John Doe", "John'Doe", | ||
"SymbolsIsValidNameLength"}) | ||
void testValidName(String name) throws NoSuchFieldException { | ||
nameRegex(name, true); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource( | ||
strings = {"", "31SymbolsIsInvalidNameLengthForAddingPosition"}) | ||
void testInvalidName(String name) throws NoSuchFieldException { | ||
nameRegex(name, false); | ||
} | ||
|
||
void nameEnRegex(String nameEn, boolean validates) throws NoSuchFieldException { | ||
Field field = AddingPositionDto.class.getDeclaredField("nameEn"); | ||
javax.validation.constraints.Pattern[] annotations = | ||
field.getAnnotationsByType(javax.validation.constraints.Pattern.class); | ||
assertEquals(nameEn.matches(annotations[0].regexp()), validates); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource( | ||
strings = {"John Doe", "John-Doe", "John Doe", "John'Doe", | ||
"SymbolsIsValidNameLengthForAdd"}) | ||
void testValidNameEn(String nameEn) throws NoSuchFieldException { | ||
nameEnRegex(nameEn, true); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource( | ||
strings = {"", "31SymbolsIsInvalidNameLengthForAddingPosition"}) | ||
void testInvalidNameEn(String nameEn) throws NoSuchFieldException { | ||
nameEnRegex(nameEn, false); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
service-api/src/test/java/greencity/dto/position/PositionDtoTest.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,74 @@ | ||
package greencity.dto.position; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class PositionDtoTest { | ||
|
||
void nameRegex(String name, boolean validates) throws NoSuchFieldException { | ||
Field field = PositionDto.class.getDeclaredField("name"); | ||
javax.validation.constraints.Pattern[] annotations = | ||
field.getAnnotationsByType(javax.validation.constraints.Pattern.class); | ||
assertEquals(name.matches(annotations[0].regexp()), validates); | ||
} | ||
|
||
void nameEnRegex(String nameEn, boolean validates) throws NoSuchFieldException { | ||
Field field = PositionDto.class.getDeclaredField("nameEn"); | ||
javax.validation.constraints.Pattern[] annotations = | ||
field.getAnnotationsByType(javax.validation.constraints.Pattern.class); | ||
assertEquals(nameEn.matches(annotations[0].regexp()), validates); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(longs = {1, 2, 3, 1000, 10000}) | ||
void testValidId(Long id) throws NoSuchFieldException { | ||
Field field = PositionDto.class.getDeclaredField("id"); | ||
javax.validation.constraints.Min[] annotations = | ||
field.getAnnotationsByType(javax.validation.constraints.Min.class); | ||
assertTrue(id >= annotations[0].value()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(longs = {0, -1, -100, -1000}) | ||
void testInvalidId(Long id) throws NoSuchFieldException { | ||
Field field = PositionDto.class.getDeclaredField("id"); | ||
javax.validation.constraints.Min[] annotations = | ||
field.getAnnotationsByType(javax.validation.constraints.Min.class); | ||
assertTrue(id < annotations[0].value()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource( | ||
strings = {"John Doe", "абвгґіїьяюєАБВГҐІЇЬЯЮЄ", "John-Doe", "John Doe", "John'Doe", | ||
"SymbolsIsValidNameLength"}) | ||
void testValidName(String name) throws NoSuchFieldException { | ||
nameRegex(name, true); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource( | ||
strings = {"", "31SymbolsIsInvalidNameLengthForAddingPosition"}) | ||
void testInvalidName(String name) throws NoSuchFieldException { | ||
nameRegex(name, false); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource( | ||
strings = {"John Doe", "John-Doe", "John Doe", "John'Doe", | ||
"SymbolsIsValidNameLengthForAdd"}) | ||
void testValidNameEn(String nameEn) throws NoSuchFieldException { | ||
nameEnRegex(nameEn, true); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource( | ||
strings = {"", "31SymbolsIsInvalidNameLengthForAddingPosition"}) | ||
void testInvalidNameEn(String nameEn) throws NoSuchFieldException { | ||
nameEnRegex(nameEn, false); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
service-api/src/test/java/greencity/dto/position/PositionWithTranslateDtoTest.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,50 @@ | ||
package greencity.dto.position; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class PositionWithTranslateDtoTest { | ||
|
||
void idValidation(Long id, boolean validates) throws NoSuchFieldException { | ||
Field field = PositionWithTranslateDto.class.getDeclaredField("id"); | ||
javax.validation.constraints.Min[] annotations = | ||
field.getAnnotationsByType(javax.validation.constraints.Min.class); | ||
assertEquals(id >= annotations[0].value(), validates); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(longs = {1, 2, 3, 1000, 10000}) | ||
void testValidId(Long id) throws NoSuchFieldException { | ||
idValidation(id, true); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(longs = {0, -1, -100, -1000}) | ||
void testInvalidId(Long id) throws NoSuchFieldException { | ||
idValidation(id, false); | ||
} | ||
|
||
@Test | ||
void testValidNameMap() { | ||
PositionWithTranslateDto dto = | ||
new PositionWithTranslateDto(1L, Map.of("en", "Valid Name", "ua", "Дійсне ім'я")); | ||
assertEquals("Valid Name", dto.getName().get("en")); | ||
assertEquals("Дійсне ім'я", dto.getName().get("ua")); | ||
} | ||
|
||
@Test | ||
void testInvalidNameMap() { | ||
PositionWithTranslateDto dto = new PositionWithTranslateDto(1L, Map.of("", "Name")); | ||
assertTrue(dto.getName().containsKey("")); | ||
dto = new PositionWithTranslateDto(1L, Map.of("en", "")); | ||
assertTrue(dto.getName().containsValue("")); | ||
dto = new PositionWithTranslateDto(1L, null); | ||
assertNull(dto.getName()); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.