示例#1
0
  @Test(expected = OfertaEstadoException.class)
  public void testEstadoException()
      throws InstanceNotFoundException, InputValidationException, OfertaMaxPersonasException,
          OfertaEmailException, OfertaReservaDateException, OfertaEstadoException,
          OfertaReclamaDateException {
    Oferta oferta = createOferta(getValidOferta());
    Reserva reserva = null;
    try {
      reserva =
          ofertaService.findReserva(
              ofertaService.reservarOferta(
                  oferta.getOfertaId(), USER_EMAIL, VALID_CREDIT_CARD_NUMBER));

      oferta.setMaxPersonas((short) 2);
      ofertaService.updateOferta(
          oferta.getOfertaId(),
          oferta.getTitulo(),
          oferta.getDescripcion(),
          oferta.getIniReserva(),
          oferta.getLimReserva(),
          oferta.getLimOferta(),
          oferta.getPrecioReal(),
          oferta.getPrecioRebajado(),
          oferta.getMaxPersonas());
      /* Clear database. */
    } finally {
      ofertaService.reclamarOferta(reserva.getReservaId());
      removeReserva(reserva.getReservaId());
      removeOferta(oferta.getOfertaId());
    }
  }
示例#2
0
  @Test
  public void testUpdateOferta()
      throws InputValidationException, InstanceNotFoundException, OfertaEstadoException {

    Oferta oferta = createOferta(getValidOferta());

    // Asi es mas legible que poniendo el valor de los parametros directamente en el
    // ofertaService.updateOferta
    oferta.setTitulo("new titulo");
    oferta.setMaxPersonas((short) 5);
    oferta.setDescripcion("new description");
    oferta.setPrecioReal(20);

    try {

      ofertaService.updateOferta(
          oferta.getOfertaId(),
          oferta.getTitulo(),
          oferta.getDescripcion(),
          oferta.getIniReserva(),
          oferta.getLimReserva(),
          oferta.getLimOferta(),
          oferta.getPrecioReal(),
          oferta.getPrecioRebajado(),
          oferta.getMaxPersonas());

      Oferta updatedOferta = ofertaService.findOferta(oferta.getOfertaId());
      assertEquals(oferta, updatedOferta);

      // Mas abajo probamos en otro metodo(testEstadoException) otro caso de update reservando una
      // oferta e intentando actualizarla

    } finally {
      // Clear Database
      removeOferta(oferta.getOfertaId());
    }
  }
示例#3
0
  @Test
  public void testAddNullMaxPersonasOferta()
      throws InputValidationException, InstanceNotFoundException, OfertaEstadoException {

    Oferta oferta = createOferta(getValidOferta());
    oferta.setMaxPersonas(
        null); // Esta linea es porque no podemos pasar un null al ofertaService.update como
               // parametro
    ofertaService.updateOferta(
        oferta.getOfertaId(),
        oferta.getTitulo(),
        oferta.getDescripcion(),
        oferta.getIniReserva(),
        oferta.getLimReserva(),
        oferta.getLimOferta(),
        oferta.getPrecioReal(),
        oferta.getPrecioRebajado(),
        oferta.getMaxPersonas());
    Oferta foundOferta = ofertaService.findOferta(oferta.getOfertaId());
    assertEquals(oferta, foundOferta);

    // Clear Database
    removeOferta(oferta.getOfertaId());
  }
示例#4
0
  @Test
  public void testAddInvalidOferta() throws InputValidationException, OfertaEstadoException {

    Oferta oferta = getValidOferta();
    Oferta addedOferta = null;
    boolean exceptionCatched = false;

    try {
      // Check oferta titulo not null
      oferta.setTitulo(null);
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta titulo not empty
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setTitulo("");
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta descripcion not null
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setDescripcion(null);
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta description not null
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setDescripcion("");
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta iniReserva not null
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setIniReserva(null);
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta limReserva not null
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setLimReserva(null);
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta limOferta not null
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setLimOferta(null);
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta precioReal >= 0
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setPrecioReal((short) -1);
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta precioRebajado >= 0
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setPrecioRebajado((short) -1);
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta maxPersonas >= 0
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setMaxPersonas((short) -1);
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta Estados
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setEstado((short) -1);
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);

      // Check oferta Estados <= NUM_ESTADOS
      exceptionCatched = false;
      oferta = getValidOferta();
      oferta.setEstado((short) (NUM_ESTADOS + 1));
      try {
        addedOferta = ofertaService.addOferta(oferta);
      } catch (InputValidationException e) {
        exceptionCatched = true;
      }
      assertTrue(exceptionCatched);
    } finally {
      if (!exceptionCatched) {
        // Clear Database
        removeOferta(addedOferta.getOfertaId());
      }
    }
  }