Search in sources :

Example 1 with Sessao

use of br.com.caelum.agiletickets.models.Sessao in project agiletickets by caelum.

the class EspetaculosController method cadastraSessoes.

@Post
@Path("/espetaculo/{espetaculoId}/sessoes")
public void cadastraSessoes(Long espetaculoId, LocalDate inicio, LocalDate fim, LocalTime horario, Periodicidade periodicidade) {
    Espetaculo espetaculo = carregaEspetaculo(espetaculoId);
    // aqui faz a magica!
    // cria sessoes baseado no periodo de inicio e fim passados pelo usuario
    List<Sessao> sessoes = espetaculo.criaSessoes(inicio, fim, horario, periodicidade);
    agenda.agende(sessoes);
    result.include("message", sessoes.size() + " sessões criadas com sucesso");
    result.redirectTo(this).lista();
}
Also used : Sessao(br.com.caelum.agiletickets.models.Sessao) Espetaculo(br.com.caelum.agiletickets.models.Espetaculo) Path(br.com.caelum.vraptor.Path) Post(br.com.caelum.vraptor.Post)

Example 2 with Sessao

use of br.com.caelum.agiletickets.models.Sessao in project agiletickets by caelum.

the class EspetaculosControllerTest method naoDeveReservarZeroIngressos.

@Test(expected = ValidationException.class)
public void naoDeveReservarZeroIngressos() throws Exception {
    when(agenda.sessao(1234l)).thenReturn(new Sessao());
    controller.reserva(1234l, 0);
    verifyZeroInteractions(result);
}
Also used : Sessao(br.com.caelum.agiletickets.models.Sessao) Test(org.junit.Test)

Example 3 with Sessao

use of br.com.caelum.agiletickets.models.Sessao in project agiletickets by caelum.

the class EspetaculosControllerTest method deveReservarSeASessaoTemIngressosSuficientes.

@Test
public void deveReservarSeASessaoTemIngressosSuficientes() throws Exception {
    Espetaculo espetaculo = new Espetaculo();
    espetaculo.setTipo(TipoDeEspetaculo.TEATRO);
    Sessao sessao = new Sessao();
    sessao.setPreco(new BigDecimal("10.00"));
    sessao.setTotalIngressos(5);
    sessao.setEspetaculo(espetaculo);
    when(agenda.sessao(1234l)).thenReturn(sessao);
    controller.reserva(1234l, 3);
    assertThat(sessao.getIngressosDisponiveis(), is(2));
}
Also used : Sessao(br.com.caelum.agiletickets.models.Sessao) BigDecimal(java.math.BigDecimal) Espetaculo(br.com.caelum.agiletickets.models.Espetaculo) TipoDeEspetaculo(br.com.caelum.agiletickets.models.TipoDeEspetaculo) Test(org.junit.Test)

Example 4 with Sessao

use of br.com.caelum.agiletickets.models.Sessao in project agiletickets by caelum.

the class EspetaculosControllerTest method naoDeveReservarMaisIngressosQueASessaoPermite.

@Test(expected = ValidationException.class)
public void naoDeveReservarMaisIngressosQueASessaoPermite() throws Exception {
    Sessao sessao = new Sessao();
    sessao.setTotalIngressos(3);
    when(agenda.sessao(1234l)).thenReturn(sessao);
    controller.reserva(1234l, 5);
    verifyZeroInteractions(result);
}
Also used : Sessao(br.com.caelum.agiletickets.models.Sessao) Test(org.junit.Test)

Example 5 with Sessao

use of br.com.caelum.agiletickets.models.Sessao in project agiletickets by caelum.

the class CalculadoraDePrecosTest method deveAplicar20PorCentoAMaisNosUltimosIngressosQuandoForOrquestra.

@Test
public void deveAplicar20PorCentoAMaisNosUltimosIngressosQuandoForOrquestra() {
    Sessao sessao = SessaoTestDataBuilder.umaSessao().deUmEspetaculoDoTipo(TipoDeEspetaculo.ORQUESTRA).comTotalIngressos(70).comIngressoReservados(40).comOPreco(1000.0).comDuracaoEmMinutos(60).build();
    BigDecimal precoTotal = CalculadoraDePrecos.calcula(sessao, 1);
    assertEquals(0, BigDecimal.valueOf(1200.0).compareTo(precoTotal));
}
Also used : Sessao(br.com.caelum.agiletickets.models.Sessao) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Sessao (br.com.caelum.agiletickets.models.Sessao)20 BigDecimal (java.math.BigDecimal)15 Test (org.junit.Test)15 Espetaculo (br.com.caelum.agiletickets.models.Espetaculo)3 Path (br.com.caelum.vraptor.Path)3 TipoDeEspetaculo (br.com.caelum.agiletickets.models.TipoDeEspetaculo)2 Post (br.com.caelum.vraptor.Post)2 Estabelecimento (br.com.caelum.agiletickets.models.Estabelecimento)1 Get (br.com.caelum.vraptor.Get)1 EntityManagerCreator (br.com.caelum.vraptor.util.jpa.EntityManagerCreator)1 EntityManagerFactoryCreator (br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator)1 ValidationMessage (br.com.caelum.vraptor.validator.ValidationMessage)1 EntityManager (javax.persistence.EntityManager)1 DateTime (org.joda.time.DateTime)1