@Before
 public void initTest() {
   apartment = new Apartment();
   apartment.setApartmentId(DEFAULT_APARTMENT_ID);
   apartment.setCreated(DEFAULT_CREATED);
   apartment.setUpdated(DEFAULT_UPDATED);
   apartment.setUrl(DEFAULT_URL);
 }
  @Test
  @Transactional
  public void updateApartment() throws Exception {
    // Initialize the database
    apartmentRepository.saveAndFlush(apartment);

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

    // Update the apartment
    apartment.setApartmentId(UPDATED_APARTMENT_ID);
    apartment.setCreated(UPDATED_CREATED);
    apartment.setUpdated(UPDATED_UPDATED);
    apartment.setUrl(UPDATED_URL);

    restApartmentMockMvc
        .perform(
            put("/api/apartments")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(apartment)))
        .andExpect(status().isOk());

    // Validate the Apartment in the database
    List<Apartment> apartments = apartmentRepository.findAll();
    assertThat(apartments).hasSize(databaseSizeBeforeUpdate);
    Apartment testApartment = apartments.get(apartments.size() - 1);
    assertThat(testApartment.getApartmentId()).isEqualTo(UPDATED_APARTMENT_ID);
    assertThat(testApartment.getCreated()).isEqualTo(UPDATED_CREATED);
    assertThat(testApartment.getUpdated()).isEqualTo(UPDATED_UPDATED);
    assertThat(testApartment.getUrl()).isEqualTo(UPDATED_URL);
  }
  @Test
  @Transactional
  public void getApartment() throws Exception {
    // Initialize the database
    apartmentRepository.saveAndFlush(apartment);

    // Get the apartment
    restApartmentMockMvc
        .perform(get("/api/apartments/{id}", apartment.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(apartment.getId().intValue()))
        .andExpect(jsonPath("$.apartmentId").value(DEFAULT_APARTMENT_ID.intValue()))
        .andExpect(jsonPath("$.created").value(DEFAULT_CREATED_STR))
        .andExpect(jsonPath("$.updated").value(DEFAULT_UPDATED_STR))
        .andExpect(jsonPath("$.url").value(DEFAULT_URL.toString()));
  }
  @Test
  @Transactional
  public void createApartment() throws Exception {
    int databaseSizeBeforeCreate = apartmentRepository.findAll().size();

    // Create the Apartment

    restApartmentMockMvc
        .perform(
            post("/api/apartments")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(apartment)))
        .andExpect(status().isCreated());

    // Validate the Apartment in the database
    List<Apartment> apartments = apartmentRepository.findAll();
    assertThat(apartments).hasSize(databaseSizeBeforeCreate + 1);
    Apartment testApartment = apartments.get(apartments.size() - 1);
    assertThat(testApartment.getApartmentId()).isEqualTo(DEFAULT_APARTMENT_ID);
    assertThat(testApartment.getCreated()).isEqualTo(DEFAULT_CREATED);
    assertThat(testApartment.getUpdated()).isEqualTo(DEFAULT_UPDATED);
    assertThat(testApartment.getUrl()).isEqualTo(DEFAULT_URL);
  }
  @Test
  @Transactional
  public void deleteApartment() throws Exception {
    // Initialize the database
    apartmentRepository.saveAndFlush(apartment);

    int databaseSizeBeforeDelete = apartmentRepository.findAll().size();

    // Get the apartment
    restApartmentMockMvc
        .perform(
            delete("/api/apartments/{id}", apartment.getId())
                .accept(TestUtil.APPLICATION_JSON_UTF8))
        .andExpect(status().isOk());

    // Validate the database is empty
    List<Apartment> apartments = apartmentRepository.findAll();
    assertThat(apartments).hasSize(databaseSizeBeforeDelete - 1);
  }
  @Test
  @Transactional
  public void checkUpdatedIsRequired() throws Exception {
    int databaseSizeBeforeTest = apartmentRepository.findAll().size();
    // set the field null
    apartment.setUpdated(null);

    // Create the Apartment, which fails.

    restApartmentMockMvc
        .perform(
            post("/api/apartments")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(apartment)))
        .andExpect(status().isBadRequest());

    List<Apartment> apartments = apartmentRepository.findAll();
    assertThat(apartments).hasSize(databaseSizeBeforeTest);
  }