Skip to content

Commit 12045be

Browse files
committedAug 18, 2024
tests: criando testes para a tabela de decisoes para o estado dos ingressos
1 parent 52ba168 commit 12045be

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package br.edu.ufcg.ccc.vv.functionalTests;
2+
3+
import br.edu.ufcg.ccc.vv.models.IngressoModel;
4+
import br.edu.ufcg.ccc.vv.models.LoteModel;
5+
import br.edu.ufcg.ccc.vv.models.ShowModel;
6+
import br.edu.ufcg.ccc.vv.models.TipoIngressoEnum;
7+
import br.edu.ufcg.ccc.vv.repository.ShowRepository;
8+
import br.edu.ufcg.ccc.vv.services.ShowServices;
9+
import br.edu.ufcg.ccc.vv.utils.InMemoryShowRepository;
10+
import org.junit.jupiter.api.BeforeEach;
11+
import org.junit.jupiter.api.Test;
12+
13+
import java.util.Date;
14+
15+
import static org.junit.jupiter.api.Assertions.*;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
17+
18+
public class TabelaDecisoesEstadoIngresso {
19+
private ShowRepository showRepository;
20+
private ShowServices showServices;
21+
22+
@BeforeEach
23+
public void setUp() {
24+
// Instanciando o repositório em memória
25+
showRepository = new InMemoryShowRepository();
26+
showServices = new ShowServices(showRepository);
27+
}
28+
29+
@Test
30+
public void testComprarIngressoComLoteTodosComprados() {
31+
Date data = new Date();
32+
String artista = "Artista Teste";
33+
Double cache = 1000.0;
34+
Double totalDespesas = 2000.0;
35+
Integer quantLotes = 1;
36+
Integer quantIngressosPorLote = 34;
37+
Double precoNormal = 10.0;
38+
Boolean isDataEspecial = false;
39+
Double descontoLote = 0.;
40+
double vip = 30;
41+
42+
// Cria o show
43+
showServices.criarShow(data, artista, cache, totalDespesas, quantLotes, quantIngressosPorLote, precoNormal, isDataEspecial, descontoLote, vip);
44+
45+
// Recupera o show salvo
46+
ShowModel show = showRepository.findById(data, artista).get();
47+
LoteModel lote = show.getLotes().getFirst();
48+
for (int i = 0; i < 10; i++) {
49+
// Compra um ingresso
50+
showServices.comprarIngresso(data, artista, lote.getId(), TipoIngressoEnum.VIP);
51+
}
52+
53+
54+
// Tenta comprar um ingresso
55+
Exception exception = assertThrows(IllegalStateException.class, () -> showServices.comprarIngresso(data, artista, lote.getId(), TipoIngressoEnum.VIP));
56+
57+
assertEquals("Nenhum ingresso disponível para o lote", exception.getMessage());
58+
}
59+
60+
@Test
61+
public void testComprarIngressoComLoteDisponivel() {
62+
Date data = new Date();
63+
String artista = "Artista Teste";
64+
Double cache = 1000.0;
65+
Double totalDespesas = 2000.0;
66+
Integer quantLotes = 1;
67+
Integer quantIngressosPorLote = 10;
68+
Double precoNormal = 10.0;
69+
Boolean isDataEspecial = false;
70+
Double descontoLote = 0.;
71+
double vip = 30;
72+
73+
// Cria o show
74+
showServices.criarShow(data, artista, cache, totalDespesas, quantLotes, quantIngressosPorLote, precoNormal, isDataEspecial, descontoLote, vip);
75+
76+
// Recupera o show salvo
77+
ShowModel show = showRepository.findById(data, artista).get();
78+
LoteModel lote = show.getLotes().getFirst();
79+
IngressoModel ingresso = lote.getIngressos().getFirst();
80+
81+
// Compra um ingresso
82+
IngressoModel comprado = showServices.comprarIngresso(data, artista, lote.getId(), TipoIngressoEnum.VIP);
83+
84+
assertNotNull(comprado);
85+
assertEquals(ingresso, comprado);
86+
assertTrue(lote.getIngressos().getFirst().isVendido());
87+
}
88+
89+
}

0 commit comments

Comments
 (0)