Beispiel #1
0
  // Test comentado porque no podemos cambiar las fechas de una oferta reservada para que se reclame
  // y tampoco antes de reservarse porque iniReserva <= limReserva <= limOferta
  // En resumen para comprobarlo habria que esperar a que en la oferta caducara su limite para
  // disfrutarla
  // @Test(expected = OfertaReclamaDateException.class)
  public void testReclamaDateException()
      throws InstanceNotFoundException, InputValidationException, OfertaEmailException,
          OfertaMaxPersonasException, OfertaReservaDateException, OfertaEstadoException,
          OfertaReclamaDateException {

    Oferta oferta = createOferta(getValidOferta());
    Reserva reserva = null;

    try {

      reserva =
          ofertaService.findReserva(
              ofertaService.reservarOferta(
                  oferta.getOfertaId(), USER_EMAIL, VALID_CREDIT_CARD_NUMBER));

      Calendar before = Calendar.getInstance();
      before.add(Calendar.DAY_OF_MONTH, -4);
      oferta.setIniReserva(before);

      Calendar after = Calendar.getInstance();
      after.add(Calendar.DAY_OF_MONTH, -3);
      oferta.setLimReserva(after);

      Calendar lim = Calendar.getInstance();
      lim.add(Calendar.DAY_OF_MONTH, -2);
      oferta.setLimOferta(lim);

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

      ofertaService.reclamarOferta(reserva.getReservaId());
      removeReserva(reserva.getReservaId());
    } finally {
      /* Clear database. */
      removeOferta(oferta.getOfertaId());
    }
  }
Beispiel #2
0
  // limOferta > limReserva
  @Test(expected = InputValidationException.class)
  public void testSetDatesWrong3()
      throws InstanceNotFoundException, InputValidationException, OfertaEmailException,
          OfertaMaxPersonasException, OfertaReservaDateException, OfertaEstadoException,
          OfertaReclamaDateException {

    Oferta oferta = createOferta(getValidOferta());

    try {

      Calendar before = Calendar.getInstance();
      before.add(Calendar.DAY_OF_MONTH, 1);
      oferta.setIniReserva(before);

      Calendar after = Calendar.getInstance();
      after.add(Calendar.DAY_OF_MONTH, 3);
      oferta.setLimReserva(after);

      Calendar lim = Calendar.getInstance();
      lim.add(Calendar.DAY_OF_MONTH, 2);
      oferta.setLimOferta(lim);

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

    } finally {
      /* Clear database. */
      removeOferta(oferta.getOfertaId());
    }
  }
Beispiel #3
0
  @Test(expected = OfertaReservaDateException.class)
  public void testReservaDateException()
      throws InstanceNotFoundException, InputValidationException, OfertaEmailException,
          OfertaMaxPersonasException, OfertaReservaDateException, OfertaEstadoException,
          OfertaReclamaDateException {

    Oferta oferta = createOferta(getValidOferta());
    Oferta oferta2 = null;

    try {

      //
      Calendar before = Calendar.getInstance();
      before.add(Calendar.DAY_OF_MONTH, 2);
      oferta.setIniReserva(before);

      // Estos dos Calendar para que tenga coherencia y no salten excepciones al añadir la oferta
      Calendar after = Calendar.getInstance();
      after.add(Calendar.DAY_OF_MONTH, 3);
      oferta.setLimReserva(after);

      Calendar lim = Calendar.getInstance();
      lim.add(Calendar.DAY_OF_MONTH, 4);
      oferta.setLimOferta(lim);
      oferta2 = ofertaService.addOferta(oferta);

      ofertaService.reservarOferta(oferta2.getOfertaId(), USER_EMAIL, VALID_CREDIT_CARD_NUMBER);
      // Vamos a limpiar la segunda oferta en el siguiente metodo donde solo se reclama

      /* Clear database. */
    } finally {

      removeOferta(oferta.getOfertaId());
      removeOferta(oferta2.getOfertaId());
    }
  }
Beispiel #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());
      }
    }
  }