示例#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(expected = InstanceNotFoundException.class)
  public void testUpdateNonExistentOferta()
      throws InputValidationException, InstanceNotFoundException, OfertaEstadoException {

    Oferta oferta = getValidOferta();
    oferta.setOfertaId(NON_EXISTENT_OFERTA_ID);
    ofertaService.updateOferta(
        oferta.getOfertaId(),
        oferta.getTitulo(),
        oferta.getDescripcion(),
        oferta.getIniReserva(),
        oferta.getLimReserva(),
        oferta.getLimOferta(),
        oferta.getPrecioReal(),
        oferta.getPrecioRebajado(),
        oferta.getMaxPersonas());
  }
示例#3
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());
    }
  }
示例#4
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());
    }
  }
示例#5
0
  @Test(expected = InputValidationException.class)
  public void testUpdateInvalidOferta()
      throws InputValidationException, InstanceNotFoundException, OfertaEstadoException {

    Oferta oferta = createOferta(getValidOferta());
    try {
      // Check oferta titulo not null
      oferta = ofertaService.findOferta(oferta.getOfertaId());
      ofertaService.updateOferta(
          oferta.getOfertaId(),
          null,
          oferta.getDescripcion(),
          oferta.getIniReserva(),
          oferta.getLimReserva(),
          oferta.getLimOferta(),
          oferta.getPrecioReal(),
          oferta.getPrecioRebajado(),
          oferta.getMaxPersonas());
    } finally {
      // Clear Database
      removeOferta(oferta.getOfertaId());
    }
  }
示例#6
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());
    }
  }
示例#7
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());
  }