Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security unit tests #49

Merged
merged 6 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class EncomendaDTOPatchRequest {

@NotNull
@Positive
private Long encomendaId;

@Min(value = 1, message = "Número de refeiçáes por semana invÑlido")
Expand All @@ -31,8 +32,10 @@ public class EncomendaDTOPatchRequest {
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime dataEncomenda;
@NotNull
@Positive
private Long pacoteId;
@NotNull
@Positive
private Long userId;

private Estado estado;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

public class EncomendaDTOResponse {

@NotNull
@Positive
private Long encomendaId;
@Min(value = 1, message = "Número de refeiçáes por semana invÑlido")
@Max(value = 7, message = "Número de refeiçáes por semana invÑlido")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public class EncomendaDTOSaveRequest {
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime dataEncomenda;
@NotNull
@Positive
private Long pacoteId;
@NotNull
@Positive
private Long userId;

private Estado estado;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class EncomendaDTOServicePatchRequest {
@NotNull
@Positive
private Long encomendaId;

@Min(value = 1, message = "Número de refeiçáes por semana invÑlido")
Expand All @@ -28,8 +29,10 @@ public class EncomendaDTOServicePatchRequest {
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime dataEncomenda;
@NotNull
@Positive
private Long pacoteId;
@NotNull
@Positive
private Long userId;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public class EncomendaDTOServiceRequest {
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime dataEncomenda;
@NotNull
@Positive
private Long pacoteId;
@NotNull
@Positive
private Long userId;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class EncomendaDTOServiceResponse {

@NotNull
@Positive
private Long encomendaId;
@Min(value = 1, message = "Número de refeiçáes por semana invÑlido")
@Max(value = 7, message = "Número de refeiçáes por semana invÑlido")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class EncomendaPatchDTOService {
@NotNull
@Positive
private Long encomendaId;

@Min(value = 1, message = "Número de refeiçáes por semana invÑlido")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class PacoteDTOPatchRequest {

@NotNull
@Positive
private final Long pacoteId;


Expand All @@ -14,7 +15,6 @@ public class PacoteDTOPatchRequest {
@Size(max = 16, message = "Nome do pacote invΓ‘lido")
private final String nome;

@NotBlank
@Min(value = 0, message = "Preço base do pacote invÑlido")
@Max(value = 500, message = "Preço base do pacote invÑlido")
private final double pacoteBasePrice;
Expand All @@ -25,6 +25,8 @@ public class PacoteDTOPatchRequest {
private final String pacoteDescription;

private final boolean disabled;
@Positive
@NotNull
private final Long tipoPacote;

public PacoteDTOPatchRequest(Long pacoteId,String nome, double pacoteBasePrice, String pacoteDescription, boolean disabled, Long tipoPacote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class PacoteDTOSaveRequest {
private final String pacoteDescription;

private final boolean disabled;
@NotNull
@Positive
private final Long tipoPacote;

public PacoteDTOSaveRequest(String nome, double pacoteBasePrice, String pacoteDescription, boolean disabled, Long tipoPacote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class PacoteDTOServicePatchRequest {
@NotNull
@Positive
private final Long pacoteId;


Expand All @@ -24,6 +25,8 @@ public class PacoteDTOServicePatchRequest {
private final String pacoteDescription;

private final boolean disabled;
@Positive
@NotNull
private final Long tipoPacote;

public PacoteDTOServicePatchRequest(Long pacoteId,String nome, double pacoteBasePrice, String pacoteDescription, boolean disabled, Long tipoPacote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class PacoteDTOServiceRequest {
private final String pacoteDescription;

private final boolean disabled;
@Positive
@NotNull
private final Long tipoPacote;

public PacoteDTOServiceRequest(String nome, double pacoteBasePrice, String pacoteDescription, boolean disabled, Long tipoPacote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class PacotePatchDTOService {

@NotNull
@Positive
private final Long pacoteId;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class ReviewDTOPatchRequest {
private final int rating;

@NotNull
@Positive
private final Long user;
@NotNull
@Positive
private final Long pacote;

public ReviewDTOPatchRequest(Long reviewId,String reviewText, int rating, Long user, Long pacote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public class ReviewDTOSaveRequest {
private final int rating;

@NotNull
@Positive
private final Long user;
@NotNull
@Positive
private final Long pacote;

public ReviewDTOSaveRequest(String reviewText, int rating, Long user, Long pacote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class ReviewDTOServicePatchRequest {
private final int rating;

@NotNull
@Positive
private final Long user;
@NotNull
@Positive
private final Long pacote;

public ReviewDTOServicePatchRequest(Long reviewId,String reviewText, int rating, Long user, Long pacote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import isep.ipp.pt.api.desofs.Model.TipoPacote;
import isep.ipp.pt.api.desofs.Model.UserModel.Role;
import isep.ipp.pt.api.desofs.Model.UserModel.User;
import isep.ipp.pt.api.desofs.Repository.Interface.EncomendaServiceRepo;
import isep.ipp.pt.api.desofs.Repository.Interface.PacoteServiceRepo;
import isep.ipp.pt.api.desofs.Repository.Interface.TipoPacoteServiceRepo;
import isep.ipp.pt.api.desofs.Repository.Interface.UserServiceRepo;
import isep.ipp.pt.api.desofs.Repository.Interface.*;
import isep.ipp.pt.api.desofs.Service.EncomendaService.EncomendaService;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -41,9 +38,15 @@ class EncomendaControllerTest {

@Autowired
private UserServiceRepo userRepo;
@Autowired
private ReviewServiceRepo reviewServiceRepo;
@Autowired
private ReceitaServiceRepo receitaServiceRepo;

@BeforeEach
public void populate() {
receitaServiceRepo.deleteAll();
reviewServiceRepo.deleteAll();
encomendaRepo.deleteAll();
pacoteRepo.deleteAll();
userRepo.deleteAll();
Expand All @@ -60,6 +63,8 @@ public void populate() {

@AfterEach
public void clean() {
receitaServiceRepo.deleteAll();
reviewServiceRepo.deleteAll();
encomendaRepo.deleteAll();
pacoteRepo.deleteAll();
userRepo.deleteAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import isep.ipp.pt.api.desofs.Dto.PacoteDTO.ControllerLayer.PacoteDTOSaveRequest;
import isep.ipp.pt.api.desofs.Model.Pacote;
import isep.ipp.pt.api.desofs.Model.TipoPacote;
import isep.ipp.pt.api.desofs.Repository.Interface.PacoteServiceRepo;
import isep.ipp.pt.api.desofs.Repository.Interface.ReviewServiceRepo;
import isep.ipp.pt.api.desofs.Repository.Interface.TipoPacoteServiceRepo;
import isep.ipp.pt.api.desofs.Repository.Interface.*;
import isep.ipp.pt.api.desofs.Service.PacoteService.PacoteService;
import org.apache.catalina.core.ApplicationContext;
import org.junit.jupiter.api.*;
Expand All @@ -32,10 +30,16 @@ class PacoteControllerTest {
private TipoPacoteServiceRepo tipoPacoteServiceRepo;
@Autowired
private ReviewServiceRepo reviewServiceRepo;
@Autowired
private EncomendaServiceRepo encomendaServiceRepo;

@Autowired
private ReceitaServiceRepo receitaServiceRepo;

@BeforeEach
public void setUp() {
receitaServiceRepo.deleteAll();
encomendaServiceRepo.deleteAll();
reviewServiceRepo.deleteAll();
pacoteServiceRepo.deleteAll();
TipoPacote tp1 = new TipoPacote(1L, "TugaTube");
Expand All @@ -45,6 +49,9 @@ public void setUp() {

@AfterEach
public void tearDown() {
receitaServiceRepo.deleteAll();
encomendaServiceRepo.deleteAll();
reviewServiceRepo.deleteAll();
pacoteServiceRepo.deleteAll();
tipoPacoteServiceRepo.deleteAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.Mockito;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Collections;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;

@SpringBootTest
class PersonalValidationTest {

private PersonalValidation personalValidation;
Expand Down
Loading