@Test
  public void updateBook() throws Exception {
    // Initialize the database
    bookRepository.save(book);

    int databaseSizeBeforeUpdate = bookRepository.findAll().size();

    // Update the book
    book.setTitle(UPDATED_TITLE);
    book.setDescription(UPDATED_DESCRIPTION);
    book.setPublisher(UPDATED_PUBLISHER);
    book.setPublicationDate(UPDATED_PUBLICATION_DATE);
    book.setPrice(UPDATED_PRICE);

    restBookMockMvc
        .perform(
            put("/api/books")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(book)))
        .andExpect(status().isOk());

    // Validate the Book in the database
    List<Book> books = bookRepository.findAll();
    assertThat(books).hasSize(databaseSizeBeforeUpdate);
    Book testBook = books.get(books.size() - 1);
    assertThat(testBook.getTitle()).isEqualTo(UPDATED_TITLE);
    assertThat(testBook.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
    assertThat(testBook.getPublisher()).isEqualTo(UPDATED_PUBLISHER);
    assertThat(testBook.getPublicationDate()).isEqualTo(UPDATED_PUBLICATION_DATE);
    assertThat(testBook.getPrice()).isEqualTo(UPDATED_PRICE);
  }
  @Test
  @Transactional
  public void testRegisterAdminIsIgnored() throws Exception {
    UserDTO u =
        new UserDTO(
            "badguy", // login
            "password", // password
            "Bad", // firstName
            "Guy", // lastName
            "*****@*****.**", // e-mail
            true, // activated
            "en", // langKey
            new HashSet<>(
                Arrays.asList(
                    AuthoritiesConstants.ADMIN)) // <-- only admin should be able to do that
            );

    restMvc
        .perform(
            post("/api/register")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(u)))
        .andExpect(status().isCreated());

    Optional<User> userDup = userRepository.findOneByLogin("badguy");
    assertThat(userDup.isPresent()).isTrue();
    assertThat(userDup.get().getAuthorities())
        .hasSize(1)
        .containsExactly(authorityRepository.findOne(AuthoritiesConstants.USER));
  }
  @Test
  @Transactional
  public void updateHotel() throws Exception {
    // Initialize the database
    hotelRepository.saveAndFlush(hotel);

    int databaseSizeBeforeUpdate = hotelRepository.findAll().size();

    // Update the hotel
    hotel.setName(UPDATED_NAME);
    hotel.setCode(UPDATED_CODE);

    restHotelMockMvc
        .perform(
            put("/api/hotels")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(hotel)))
        .andExpect(status().isOk());

    // Validate the Hotel in the database
    List<Hotel> hotels = hotelRepository.findAll();
    assertThat(hotels).hasSize(databaseSizeBeforeUpdate);
    Hotel testHotel = hotels.get(hotels.size() - 1);
    assertThat(testHotel.getName()).isEqualTo(UPDATED_NAME);
    assertThat(testHotel.getCode()).isEqualTo(UPDATED_CODE);
  }
  @Test
  @Transactional
  public void updateSocio() throws Exception {
    // Initialize the database
    socioRepository.saveAndFlush(socio);

    int databaseSizeBeforeUpdate = socioRepository.findAll().size();

    // Update the socio
    socio.setNombre(UPDATED_NOMBRE);
    socio.setFechaNacimiento(UPDATED_FECHA_NACIMIENTO);
    socio.setEquipo(UPDATED_EQUIPO);

    restSocioMockMvc
        .perform(
            put("/api/socios")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(socio)))
        .andExpect(status().isOk());

    // Validate the Socio in the database
    List<Socio> socios = socioRepository.findAll();
    assertThat(socios).hasSize(databaseSizeBeforeUpdate);
    Socio testSocio = socios.get(socios.size() - 1);
    assertThat(testSocio.getNombre()).isEqualTo(UPDATED_NOMBRE);
    assertThat(testSocio.getFechaNacimiento()).isEqualTo(UPDATED_FECHA_NACIMIENTO);
    assertThat(testSocio.getEquipo()).isEqualTo(UPDATED_EQUIPO);
  }
  @Test
  @Transactional
  public void updateSession() throws Exception {
    // Initialize the database
    sessionRepository.saveAndFlush(session);

    int databaseSizeBeforeUpdate = sessionRepository.findAll().size();

    // Update the session
    session.setSessionName(UPDATED_SESSION_NAME);
    session.setStartTime(UPDATED_START_TIME);
    session.setEndTime(UPDATED_END_TIME);
    session.setIsBreak(UPDATED_IS_BREAK);

    restSessionMockMvc
        .perform(
            put("/api/sessions")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(session)))
        .andExpect(status().isOk());

    // Validate the Session in the database
    List<Session> sessions = sessionRepository.findAll();
    assertThat(sessions).hasSize(databaseSizeBeforeUpdate);
    Session testSession = sessions.get(sessions.size() - 1);
    assertThat(testSession.getSessionName()).isEqualTo(UPDATED_SESSION_NAME);
    assertThat(testSession.getStartTime()).isEqualTo(UPDATED_START_TIME);
    assertThat(testSession.getEndTime()).isEqualTo(UPDATED_END_TIME);
    assertThat(testSession.getIsBreak()).isEqualTo(UPDATED_IS_BREAK);
  }
  @Test
  @Transactional
  public void testRegisterDuplicateEmail() throws Exception {
    // Good
    UserDTO u =
        new UserDTO(
            "john", // login
            "password", // password
            "John", // firstName
            "Doe", // lastName
            "*****@*****.**", // e-mail
            true, // activated
            "en", // langKey
            new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)));

    // Duplicate e-mail, different login
    UserDTO dup =
        new UserDTO(
            "johnjr",
            u.getPassword(),
            u.getLogin(),
            u.getLastName(),
            u.getEmail(),
            true,
            u.getLangKey(),
            u.getAuthorities());

    // Good user
    restMvc
        .perform(
            post("/api/register")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(u)))
        .andExpect(status().isCreated());

    // Duplicate e-mail
    restMvc
        .perform(
            post("/api/register")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(dup)))
        .andExpect(status().is4xxClientError());

    Optional<User> userDup = userRepository.findOneByLogin("johnjr");
    assertThat(userDup.isPresent()).isFalse();
  }
  @Test
  public void checkTitleIsRequired() throws Exception {
    int databaseSizeBeforeTest = bookRepository.findAll().size();
    // set the field null
    book.setTitle(null);

    // Create the Book, which fails.

    restBookMockMvc
        .perform(
            post("/api/books")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(book)))
        .andExpect(status().isBadRequest());

    List<Book> books = bookRepository.findAll();
    assertThat(books).hasSize(databaseSizeBeforeTest);
  }
  @Test
  @Transactional
  public void createBuilding() throws Exception {
    int databaseSizeBeforeCreate = buildingRepository.findAll().size();

    // Create the Building

    restBuildingMockMvc
        .perform(
            post("/api/buildings")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(building)))
        .andExpect(status().isCreated());

    // Validate the Building in the database
    List<Building> buildings = buildingRepository.findAll();
    assertThat(buildings).hasSize(databaseSizeBeforeCreate + 1);
    Building testBuilding = buildings.get(buildings.size() - 1);
    assertThat(testBuilding.getName()).isEqualTo(DEFAULT_NAME);
  }
  @Test
  @Transactional
  public void createHotel() throws Exception {
    int databaseSizeBeforeCreate = hotelRepository.findAll().size();

    // Create the Hotel

    restHotelMockMvc
        .perform(
            post("/api/hotels")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(hotel)))
        .andExpect(status().isCreated());

    // Validate the Hotel in the database
    List<Hotel> hotels = hotelRepository.findAll();
    assertThat(hotels).hasSize(databaseSizeBeforeCreate + 1);
    Hotel testHotel = hotels.get(hotels.size() - 1);
    assertThat(testHotel.getName()).isEqualTo(DEFAULT_NAME);
    assertThat(testHotel.getCode()).isEqualTo(DEFAULT_CODE);
  }
  @Test
  @Transactional
  public void createSocio() throws Exception {
    int databaseSizeBeforeCreate = socioRepository.findAll().size();

    // Create the Socio

    restSocioMockMvc
        .perform(
            post("/api/socios")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(socio)))
        .andExpect(status().isCreated());

    // Validate the Socio in the database
    List<Socio> socios = socioRepository.findAll();
    assertThat(socios).hasSize(databaseSizeBeforeCreate + 1);
    Socio testSocio = socios.get(socios.size() - 1);
    assertThat(testSocio.getNombre()).isEqualTo(DEFAULT_NOMBRE);
    assertThat(testSocio.getFechaNacimiento()).isEqualTo(DEFAULT_FECHA_NACIMIENTO);
    assertThat(testSocio.getEquipo()).isEqualTo(DEFAULT_EQUIPO);
  }
  @Test
  public void createBook() throws Exception {
    int databaseSizeBeforeCreate = bookRepository.findAll().size();

    // Create the Book

    restBookMockMvc
        .perform(
            post("/api/books")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(book)))
        .andExpect(status().isCreated());

    // Validate the Book in the database
    List<Book> books = bookRepository.findAll();
    assertThat(books).hasSize(databaseSizeBeforeCreate + 1);
    Book testBook = books.get(books.size() - 1);
    assertThat(testBook.getTitle()).isEqualTo(DEFAULT_TITLE);
    assertThat(testBook.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
    assertThat(testBook.getPublisher()).isEqualTo(DEFAULT_PUBLISHER);
    assertThat(testBook.getPublicationDate()).isEqualTo(DEFAULT_PUBLICATION_DATE);
    assertThat(testBook.getPrice()).isEqualTo(DEFAULT_PRICE);
  }
  @Test
  @Transactional
  public void createSession() throws Exception {
    int databaseSizeBeforeCreate = sessionRepository.findAll().size();

    // Create the Session

    restSessionMockMvc
        .perform(
            post("/api/sessions")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(session)))
        .andExpect(status().isCreated());

    // Validate the Session in the database
    List<Session> sessions = sessionRepository.findAll();
    assertThat(sessions).hasSize(databaseSizeBeforeCreate + 1);
    Session testSession = sessions.get(sessions.size() - 1);
    assertThat(testSession.getSessionName()).isEqualTo(DEFAULT_SESSION_NAME);
    assertThat(testSession.getStartTime()).isEqualTo(DEFAULT_START_TIME);
    assertThat(testSession.getEndTime()).isEqualTo(DEFAULT_END_TIME);
    assertThat(testSession.getIsBreak()).isEqualTo(DEFAULT_IS_BREAK);
  }
  @Test
  @Transactional
  public void testRegisterInvalidEmail() throws Exception {
    UserDTO u =
        new UserDTO(
            "bob", // login
            "password", // password
            "Bob", // firstName
            "Green", // lastName
            "invalid", // e-mail <-- invalid
            true, // activated
            "en", // langKey
            new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)));

    restUserMockMvc
        .perform(
            post("/api/register")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(u)))
        .andExpect(status().isBadRequest());

    Optional<User> user = userRepository.findOneByLogin("bob");
    assertThat(user.isPresent()).isFalse();
  }
  @Test
  @Transactional
  public void testRegisterValid() throws Exception {
    UserDTO u =
        new UserDTO(
            "joe", // login
            "password", // password
            "Joe", // firstName
            "Shmoe", // lastName
            "*****@*****.**", // e-mail
            true, // activated
            "en", // langKey
            new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)));

    restMvc
        .perform(
            post("/api/register")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(u)))
        .andExpect(status().isCreated());

    Optional<User> user = userRepository.findOneByLogin("joe");
    assertThat(user.isPresent()).isTrue();
  }
  @Test
  @Transactional
  public void updateBuilding() throws Exception {
    // Initialize the database
    buildingRepository.saveAndFlush(building);

    int databaseSizeBeforeUpdate = buildingRepository.findAll().size();

    // Update the building
    building.setName(UPDATED_NAME);

    restBuildingMockMvc
        .perform(
            put("/api/buildings")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(building)))
        .andExpect(status().isOk());

    // Validate the Building in the database
    List<Building> buildings = buildingRepository.findAll();
    assertThat(buildings).hasSize(databaseSizeBeforeUpdate);
    Building testBuilding = buildings.get(buildings.size() - 1);
    assertThat(testBuilding.getName()).isEqualTo(UPDATED_NAME);
  }