Beispiel #1
0
  @Test
  public void testFindOfertas() throws InputValidationException, OfertaEstadoException {

    // Add ofertas
    List<Oferta> ofertas = new LinkedList<Oferta>();
    Oferta oferta1 = createOferta(getValidOferta("oferta patata 1"));
    ofertas.add(oferta1);
    Oferta oferta2 = createOferta(getValidOferta("oferta patata 2"));
    ofertas.add(oferta2);
    Oferta oferta3 = getValidOferta("oferta patata 3");
    oferta3.setDescripcion("prueba de fuego");
    oferta3.setEstado(Oferta.ESTADO_LIBERADA);
    Calendar date = Calendar.getInstance();
    date.set(1990, 11, 1);
    oferta3.setIniReserva(date);
    oferta3 = ofertaService.addOferta(oferta3);
    ofertas.add(oferta3);

    try {
      List<Oferta> foundOfertas = ofertaService.findOfertas("patAta", null, null);
      assertEquals(3, foundOfertas.size());
      assertEquals(ofertas, foundOfertas);

      foundOfertas = ofertaService.findOfertas();
      assertEquals(3, foundOfertas.size());
      assertEquals(ofertas, foundOfertas);

      foundOfertas = ofertaService.findOfertas("patAta 2", null, null);
      assertEquals(1, foundOfertas.size());
      assertEquals(ofertas.get(1), foundOfertas.get(0));

      foundOfertas = ofertaService.findOfertas("patata 5", null, null);
      assertEquals(0, foundOfertas.size());

      foundOfertas = ofertaService.findOfertas("fuEgo", null, null);
      assertEquals(1, foundOfertas.size());
      assertEquals(ofertas.get(2), foundOfertas.get(0));

      Calendar date1 = Calendar.getInstance();
      date1.set(1990, 11, 7);
      foundOfertas = ofertaService.findOfertas(null, null, date1);
      assertEquals(1, foundOfertas.size());
      assertEquals(ofertas.get(2), foundOfertas.get(0));

      date1.set(1990, 10, 7);
      foundOfertas = ofertaService.findOfertas(null, null, date1);
      assertEquals(0, foundOfertas.size());

      foundOfertas = ofertaService.findOfertas("fuego", Oferta.ESTADO_LIBERADA, null);
      assertEquals(1, foundOfertas.size());
    } finally {
      // Clear Database
      for (Oferta oferta : ofertas) {
        removeOferta(oferta.getOfertaId());
      }
    }
  }
Beispiel #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());
    }
  }
Beispiel #3
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());
      }
    }
  }