public final class JSR310DateTimeSerializer extends JsonSerializer<TemporalAccessor> {

  private static final DateTimeFormatter ISOFormatter =
      DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z"));

  public static final JSR310DateTimeSerializer INSTANCE = new JSR310DateTimeSerializer();

  private JSR310DateTimeSerializer() {}

  @Override
  public void serialize(
      TemporalAccessor value, JsonGenerator generator, SerializerProvider serializerProvider)
      throws IOException {
    generator.writeString(ISOFormatter.format(value));
  }
}
/**
 * Test class for the Bill_serviceResource REST controller.
 *
 * @see Bill_serviceResource
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest
public class Bill_serviceResourceIntTest {

  private static final DateTimeFormatter dateTimeFormatter =
      DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z"));

  private static final Integer DEFAULT_QUANTITY = 0;
  private static final Integer UPDATED_QUANTITY = 1;

  private static final BigDecimal DEFAULT_TOTAL = new BigDecimal(0);
  private static final BigDecimal UPDATED_TOTAL = new BigDecimal(1);
  private static final String DEFAULT_DECRIPTION = "AAAAA";
  private static final String UPDATED_DECRIPTION = "BBBBB";

  private static final ZonedDateTime DEFAULT_CREATE_DATE =
      ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault());
  private static final ZonedDateTime UPDATED_CREATE_DATE =
      ZonedDateTime.now(ZoneId.systemDefault()).withNano(0);
  private static final String DEFAULT_CREATE_DATE_STR =
      dateTimeFormatter.format(DEFAULT_CREATE_DATE);

  @Inject private Bill_serviceRepository bill_serviceRepository;

  @Inject private Bill_serviceService bill_serviceService;

  @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter;

  @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver;

  private MockMvc restBill_serviceMockMvc;

  private Bill_service bill_service;

  @PostConstruct
  public void setup() {
    MockitoAnnotations.initMocks(this);
    Bill_serviceResource bill_serviceResource = new Bill_serviceResource();
    ReflectionTestUtils.setField(bill_serviceResource, "bill_serviceService", bill_serviceService);
    this.restBill_serviceMockMvc =
        MockMvcBuilders.standaloneSetup(bill_serviceResource)
            .setCustomArgumentResolvers(pageableArgumentResolver)
            .setMessageConverters(jacksonMessageConverter)
            .build();
  }

  @Before
  public void initTest() {
    bill_service = new Bill_service();
    bill_service.setQuantity(DEFAULT_QUANTITY);
    bill_service.setTotal(DEFAULT_TOTAL);
    bill_service.setDecription(DEFAULT_DECRIPTION);
    bill_service.setCreate_date(DEFAULT_CREATE_DATE);
  }

  @Test
  @Transactional
  public void createBill_service() throws Exception {
    int databaseSizeBeforeCreate = bill_serviceRepository.findAll().size();

    // Create the Bill_service

    restBill_serviceMockMvc
        .perform(
            post("/api/bill_services")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(bill_service)))
        .andExpect(status().isCreated());

    // Validate the Bill_service in the database
    List<Bill_service> bill_services = bill_serviceRepository.findAll();
    assertThat(bill_services).hasSize(databaseSizeBeforeCreate + 1);
    Bill_service testBill_service = bill_services.get(bill_services.size() - 1);
    assertThat(testBill_service.getQuantity()).isEqualTo(DEFAULT_QUANTITY);
    assertThat(testBill_service.getTotal()).isEqualTo(DEFAULT_TOTAL);
    assertThat(testBill_service.getDecription()).isEqualTo(DEFAULT_DECRIPTION);
    assertThat(testBill_service.getCreate_date()).isEqualTo(DEFAULT_CREATE_DATE);
  }

  @Test
  @Transactional
  public void checkQuantityIsRequired() throws Exception {
    int databaseSizeBeforeTest = bill_serviceRepository.findAll().size();
    // set the field null
    bill_service.setQuantity(null);

    // Create the Bill_service, which fails.

    restBill_serviceMockMvc
        .perform(
            post("/api/bill_services")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(bill_service)))
        .andExpect(status().isBadRequest());

    List<Bill_service> bill_services = bill_serviceRepository.findAll();
    assertThat(bill_services).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void checkTotalIsRequired() throws Exception {
    int databaseSizeBeforeTest = bill_serviceRepository.findAll().size();
    // set the field null
    bill_service.setTotal(null);

    // Create the Bill_service, which fails.

    restBill_serviceMockMvc
        .perform(
            post("/api/bill_services")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(bill_service)))
        .andExpect(status().isBadRequest());

    List<Bill_service> bill_services = bill_serviceRepository.findAll();
    assertThat(bill_services).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void checkCreate_dateIsRequired() throws Exception {
    int databaseSizeBeforeTest = bill_serviceRepository.findAll().size();
    // set the field null
    bill_service.setCreate_date(null);

    // Create the Bill_service, which fails.

    restBill_serviceMockMvc
        .perform(
            post("/api/bill_services")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(bill_service)))
        .andExpect(status().isBadRequest());

    List<Bill_service> bill_services = bill_serviceRepository.findAll();
    assertThat(bill_services).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void getAllBill_services() throws Exception {
    // Initialize the database
    bill_serviceRepository.saveAndFlush(bill_service);

    // Get all the bill_services
    restBill_serviceMockMvc
        .perform(get("/api/bill_services?sort=id,desc"))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.[*].id").value(hasItem(bill_service.getId().intValue())))
        .andExpect(jsonPath("$.[*].quantity").value(hasItem(DEFAULT_QUANTITY)))
        .andExpect(jsonPath("$.[*].total").value(hasItem(DEFAULT_TOTAL.intValue())))
        .andExpect(jsonPath("$.[*].decription").value(hasItem(DEFAULT_DECRIPTION.toString())))
        .andExpect(jsonPath("$.[*].create_date").value(hasItem(DEFAULT_CREATE_DATE_STR)));
  }

  @Test
  @Transactional
  public void getBill_service() throws Exception {
    // Initialize the database
    bill_serviceRepository.saveAndFlush(bill_service);

    // Get the bill_service
    restBill_serviceMockMvc
        .perform(get("/api/bill_services/{id}", bill_service.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(bill_service.getId().intValue()))
        .andExpect(jsonPath("$.quantity").value(DEFAULT_QUANTITY))
        .andExpect(jsonPath("$.total").value(DEFAULT_TOTAL.intValue()))
        .andExpect(jsonPath("$.decription").value(DEFAULT_DECRIPTION.toString()))
        .andExpect(jsonPath("$.create_date").value(DEFAULT_CREATE_DATE_STR));
  }

  @Test
  @Transactional
  public void getNonExistingBill_service() throws Exception {
    // Get the bill_service
    restBill_serviceMockMvc
        .perform(get("/api/bill_services/{id}", Long.MAX_VALUE))
        .andExpect(status().isNotFound());
  }

  @Test
  @Transactional
  public void updateBill_service() throws Exception {
    // Initialize the database
    bill_serviceRepository.saveAndFlush(bill_service);

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

    // Update the bill_service
    bill_service.setQuantity(UPDATED_QUANTITY);
    bill_service.setTotal(UPDATED_TOTAL);
    bill_service.setDecription(UPDATED_DECRIPTION);
    bill_service.setCreate_date(UPDATED_CREATE_DATE);

    restBill_serviceMockMvc
        .perform(
            put("/api/bill_services")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(bill_service)))
        .andExpect(status().isOk());

    // Validate the Bill_service in the database
    List<Bill_service> bill_services = bill_serviceRepository.findAll();
    assertThat(bill_services).hasSize(databaseSizeBeforeUpdate);
    Bill_service testBill_service = bill_services.get(bill_services.size() - 1);
    assertThat(testBill_service.getQuantity()).isEqualTo(UPDATED_QUANTITY);
    assertThat(testBill_service.getTotal()).isEqualTo(UPDATED_TOTAL);
    assertThat(testBill_service.getDecription()).isEqualTo(UPDATED_DECRIPTION);
    assertThat(testBill_service.getCreate_date()).isEqualTo(UPDATED_CREATE_DATE);
  }

  @Test
  @Transactional
  public void deleteBill_service() throws Exception {
    // Initialize the database
    bill_serviceRepository.saveAndFlush(bill_service);

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

    // Get the bill_service
    restBill_serviceMockMvc
        .perform(
            delete("/api/bill_services/{id}", bill_service.getId())
                .accept(TestUtil.APPLICATION_JSON_UTF8))
        .andExpect(status().isOk());

    // Validate the database is empty
    List<Bill_service> bill_services = bill_serviceRepository.findAll();
    assertThat(bill_services).hasSize(databaseSizeBeforeDelete - 1);
  }
}
Example #3
0
 public String getTimestampElastic() {
   DateTimeFormatter dateTimeFormatter =
       DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z"));
   return dateTimeFormatter.format(timestamp);
 }
/**
 * Test class for the Register_infoResource REST controller.
 *
 * @see Register_infoResource
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest
public class Register_infoResourceIntTest {

  private static final DateTimeFormatter dateTimeFormatter =
      DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z"));

  private static final LocalDate DEFAULT_DATE_CHECKIN = LocalDate.ofEpochDay(0L);
  private static final LocalDate UPDATED_DATE_CHECKIN = LocalDate.now(ZoneId.systemDefault());

  private static final LocalDate DEFAULT_DATE_CHECKOUT = LocalDate.ofEpochDay(0L);
  private static final LocalDate UPDATED_DATE_CHECKOUT = LocalDate.now(ZoneId.systemDefault());

  private static final Integer DEFAULT_NUMBER_OF_ADULT = 0;
  private static final Integer UPDATED_NUMBER_OF_ADULT = 1;

  private static final Integer DEFAULT_NUMBER_OF_KID = 0;
  private static final Integer UPDATED_NUMBER_OF_KID = 1;
  private static final String DEFAULT_OTHER_REQUEST = "AAAAA";
  private static final String UPDATED_OTHER_REQUEST = "BBBBB";

  private static final BigDecimal DEFAULT_DEPOSIT_VALUE = new BigDecimal(0);
  private static final BigDecimal UPDATED_DEPOSIT_VALUE = new BigDecimal(1);

  private static final ZonedDateTime DEFAULT_CREATE_DATE =
      ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault());
  private static final ZonedDateTime UPDATED_CREATE_DATE =
      ZonedDateTime.now(ZoneId.systemDefault()).withNano(0);
  private static final String DEFAULT_CREATE_DATE_STR =
      dateTimeFormatter.format(DEFAULT_CREATE_DATE);

  private static final ZonedDateTime DEFAULT_LAST_MODIFIED_DATE =
      ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault());
  private static final ZonedDateTime UPDATED_LAST_MODIFIED_DATE =
      ZonedDateTime.now(ZoneId.systemDefault()).withNano(0);
  private static final String DEFAULT_LAST_MODIFIED_DATE_STR =
      dateTimeFormatter.format(DEFAULT_LAST_MODIFIED_DATE);

  @Inject private Register_infoRepository register_infoRepository;

  @Inject private Register_infoService register_infoService;

  @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter;

  @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver;

  private MockMvc restRegister_infoMockMvc;

  private Register_info register_info;

  @PostConstruct
  public void setup() {
    MockitoAnnotations.initMocks(this);
    Register_infoResource register_infoResource = new Register_infoResource();
    ReflectionTestUtils.setField(
        register_infoResource, "register_infoService", register_infoService);
    this.restRegister_infoMockMvc =
        MockMvcBuilders.standaloneSetup(register_infoResource)
            .setCustomArgumentResolvers(pageableArgumentResolver)
            .setMessageConverters(jacksonMessageConverter)
            .build();
  }

  @Before
  public void initTest() {
    register_info = new Register_info();
    register_info.setDate_checkin(DEFAULT_DATE_CHECKIN);
    register_info.setDate_checkout(DEFAULT_DATE_CHECKOUT);
    register_info.setNumber_of_adult(DEFAULT_NUMBER_OF_ADULT);
    register_info.setNumber_of_kid(DEFAULT_NUMBER_OF_KID);
    register_info.setOther_request(DEFAULT_OTHER_REQUEST);
    register_info.setDeposit_value(DEFAULT_DEPOSIT_VALUE);
    register_info.setCreate_date(DEFAULT_CREATE_DATE);
    register_info.setLast_modified_date(DEFAULT_LAST_MODIFIED_DATE);
  }

  @Test
  @Transactional
  public void createRegister_info() throws Exception {
    int databaseSizeBeforeCreate = register_infoRepository.findAll().size();

    // Create the Register_info

    restRegister_infoMockMvc
        .perform(
            post("/api/register_infos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(register_info)))
        .andExpect(status().isCreated());

    // Validate the Register_info in the database
    List<Register_info> register_infos = register_infoRepository.findAll();
    assertThat(register_infos).hasSize(databaseSizeBeforeCreate + 1);
    Register_info testRegister_info = register_infos.get(register_infos.size() - 1);
    assertThat(testRegister_info.getDate_checkin()).isEqualTo(DEFAULT_DATE_CHECKIN);
    assertThat(testRegister_info.getDate_checkout()).isEqualTo(DEFAULT_DATE_CHECKOUT);
    assertThat(testRegister_info.getNumber_of_adult()).isEqualTo(DEFAULT_NUMBER_OF_ADULT);
    assertThat(testRegister_info.getNumber_of_kid()).isEqualTo(DEFAULT_NUMBER_OF_KID);
    assertThat(testRegister_info.getOther_request()).isEqualTo(DEFAULT_OTHER_REQUEST);
    assertThat(testRegister_info.getDeposit_value()).isEqualTo(DEFAULT_DEPOSIT_VALUE);
    assertThat(testRegister_info.getCreate_date()).isEqualTo(DEFAULT_CREATE_DATE);
    assertThat(testRegister_info.getLast_modified_date()).isEqualTo(DEFAULT_LAST_MODIFIED_DATE);
  }

  @Test
  @Transactional
  public void checkDate_checkinIsRequired() throws Exception {
    int databaseSizeBeforeTest = register_infoRepository.findAll().size();
    // set the field null
    register_info.setDate_checkin(null);

    // Create the Register_info, which fails.

    restRegister_infoMockMvc
        .perform(
            post("/api/register_infos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(register_info)))
        .andExpect(status().isBadRequest());

    List<Register_info> register_infos = register_infoRepository.findAll();
    assertThat(register_infos).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void checkDate_checkoutIsRequired() throws Exception {
    int databaseSizeBeforeTest = register_infoRepository.findAll().size();
    // set the field null
    register_info.setDate_checkout(null);

    // Create the Register_info, which fails.

    restRegister_infoMockMvc
        .perform(
            post("/api/register_infos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(register_info)))
        .andExpect(status().isBadRequest());

    List<Register_info> register_infos = register_infoRepository.findAll();
    assertThat(register_infos).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void checkNumber_of_adultIsRequired() throws Exception {
    int databaseSizeBeforeTest = register_infoRepository.findAll().size();
    // set the field null
    register_info.setNumber_of_adult(null);

    // Create the Register_info, which fails.

    restRegister_infoMockMvc
        .perform(
            post("/api/register_infos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(register_info)))
        .andExpect(status().isBadRequest());

    List<Register_info> register_infos = register_infoRepository.findAll();
    assertThat(register_infos).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void checkNumber_of_kidIsRequired() throws Exception {
    int databaseSizeBeforeTest = register_infoRepository.findAll().size();
    // set the field null
    register_info.setNumber_of_kid(null);

    // Create the Register_info, which fails.

    restRegister_infoMockMvc
        .perform(
            post("/api/register_infos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(register_info)))
        .andExpect(status().isBadRequest());

    List<Register_info> register_infos = register_infoRepository.findAll();
    assertThat(register_infos).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void checkDeposit_valueIsRequired() throws Exception {
    int databaseSizeBeforeTest = register_infoRepository.findAll().size();
    // set the field null
    register_info.setDeposit_value(null);

    // Create the Register_info, which fails.

    restRegister_infoMockMvc
        .perform(
            post("/api/register_infos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(register_info)))
        .andExpect(status().isBadRequest());

    List<Register_info> register_infos = register_infoRepository.findAll();
    assertThat(register_infos).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void checkCreate_dateIsRequired() throws Exception {
    int databaseSizeBeforeTest = register_infoRepository.findAll().size();
    // set the field null
    register_info.setCreate_date(null);

    // Create the Register_info, which fails.

    restRegister_infoMockMvc
        .perform(
            post("/api/register_infos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(register_info)))
        .andExpect(status().isBadRequest());

    List<Register_info> register_infos = register_infoRepository.findAll();
    assertThat(register_infos).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void getAllRegister_infos() throws Exception {
    // Initialize the database
    register_infoRepository.saveAndFlush(register_info);

    // Get all the register_infos
    restRegister_infoMockMvc
        .perform(get("/api/register_infos?sort=id,desc"))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.[*].id").value(hasItem(register_info.getId().intValue())))
        .andExpect(jsonPath("$.[*].date_checkin").value(hasItem(DEFAULT_DATE_CHECKIN.toString())))
        .andExpect(jsonPath("$.[*].date_checkout").value(hasItem(DEFAULT_DATE_CHECKOUT.toString())))
        .andExpect(jsonPath("$.[*].number_of_adult").value(hasItem(DEFAULT_NUMBER_OF_ADULT)))
        .andExpect(jsonPath("$.[*].number_of_kid").value(hasItem(DEFAULT_NUMBER_OF_KID)))
        .andExpect(jsonPath("$.[*].other_request").value(hasItem(DEFAULT_OTHER_REQUEST.toString())))
        .andExpect(jsonPath("$.[*].deposit_value").value(hasItem(DEFAULT_DEPOSIT_VALUE.intValue())))
        .andExpect(jsonPath("$.[*].create_date").value(hasItem(DEFAULT_CREATE_DATE_STR)))
        .andExpect(
            jsonPath("$.[*].last_modified_date").value(hasItem(DEFAULT_LAST_MODIFIED_DATE_STR)));
  }

  @Test
  @Transactional
  public void getRegister_info() throws Exception {
    // Initialize the database
    register_infoRepository.saveAndFlush(register_info);

    // Get the register_info
    restRegister_infoMockMvc
        .perform(get("/api/register_infos/{id}", register_info.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(register_info.getId().intValue()))
        .andExpect(jsonPath("$.date_checkin").value(DEFAULT_DATE_CHECKIN.toString()))
        .andExpect(jsonPath("$.date_checkout").value(DEFAULT_DATE_CHECKOUT.toString()))
        .andExpect(jsonPath("$.number_of_adult").value(DEFAULT_NUMBER_OF_ADULT))
        .andExpect(jsonPath("$.number_of_kid").value(DEFAULT_NUMBER_OF_KID))
        .andExpect(jsonPath("$.other_request").value(DEFAULT_OTHER_REQUEST.toString()))
        .andExpect(jsonPath("$.deposit_value").value(DEFAULT_DEPOSIT_VALUE.intValue()))
        .andExpect(jsonPath("$.create_date").value(DEFAULT_CREATE_DATE_STR))
        .andExpect(jsonPath("$.last_modified_date").value(DEFAULT_LAST_MODIFIED_DATE_STR));
  }

  @Test
  @Transactional
  public void getNonExistingRegister_info() throws Exception {
    // Get the register_info
    restRegister_infoMockMvc
        .perform(get("/api/register_infos/{id}", Long.MAX_VALUE))
        .andExpect(status().isNotFound());
  }

  @Test
  @Transactional
  public void updateRegister_info() throws Exception {
    // Initialize the database
    register_infoRepository.saveAndFlush(register_info);

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

    // Update the register_info
    register_info.setDate_checkin(UPDATED_DATE_CHECKIN);
    register_info.setDate_checkout(UPDATED_DATE_CHECKOUT);
    register_info.setNumber_of_adult(UPDATED_NUMBER_OF_ADULT);
    register_info.setNumber_of_kid(UPDATED_NUMBER_OF_KID);
    register_info.setOther_request(UPDATED_OTHER_REQUEST);
    register_info.setDeposit_value(UPDATED_DEPOSIT_VALUE);
    register_info.setCreate_date(UPDATED_CREATE_DATE);
    register_info.setLast_modified_date(UPDATED_LAST_MODIFIED_DATE);

    restRegister_infoMockMvc
        .perform(
            put("/api/register_infos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(register_info)))
        .andExpect(status().isOk());

    // Validate the Register_info in the database
    List<Register_info> register_infos = register_infoRepository.findAll();
    assertThat(register_infos).hasSize(databaseSizeBeforeUpdate);
    Register_info testRegister_info = register_infos.get(register_infos.size() - 1);
    assertThat(testRegister_info.getDate_checkin()).isEqualTo(UPDATED_DATE_CHECKIN);
    assertThat(testRegister_info.getDate_checkout()).isEqualTo(UPDATED_DATE_CHECKOUT);
    assertThat(testRegister_info.getNumber_of_adult()).isEqualTo(UPDATED_NUMBER_OF_ADULT);
    assertThat(testRegister_info.getNumber_of_kid()).isEqualTo(UPDATED_NUMBER_OF_KID);
    assertThat(testRegister_info.getOther_request()).isEqualTo(UPDATED_OTHER_REQUEST);
    assertThat(testRegister_info.getDeposit_value()).isEqualTo(UPDATED_DEPOSIT_VALUE);
    assertThat(testRegister_info.getCreate_date()).isEqualTo(UPDATED_CREATE_DATE);
    assertThat(testRegister_info.getLast_modified_date()).isEqualTo(UPDATED_LAST_MODIFIED_DATE);
  }

  @Test
  @Transactional
  public void deleteRegister_info() throws Exception {
    // Initialize the database
    register_infoRepository.saveAndFlush(register_info);

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

    // Get the register_info
    restRegister_infoMockMvc
        .perform(
            delete("/api/register_infos/{id}", register_info.getId())
                .accept(TestUtil.APPLICATION_JSON_UTF8))
        .andExpect(status().isOk());

    // Validate the database is empty
    List<Register_info> register_infos = register_infoRepository.findAll();
    assertThat(register_infos).hasSize(databaseSizeBeforeDelete - 1);
  }
}
/**
 * Test class for the ApartmentResource REST controller.
 *
 * @see ApartmentResource
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest
public class ApartmentResourceIntTest {

  private static final DateTimeFormatter dateTimeFormatter =
      DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z"));

  private static final Long DEFAULT_APARTMENT_ID = 0L;
  private static final Long UPDATED_APARTMENT_ID = 1L;

  private static final ZonedDateTime DEFAULT_CREATED =
      ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault());
  private static final ZonedDateTime UPDATED_CREATED =
      ZonedDateTime.now(ZoneId.systemDefault()).withNano(0);
  private static final String DEFAULT_CREATED_STR = dateTimeFormatter.format(DEFAULT_CREATED);

  private static final ZonedDateTime DEFAULT_UPDATED =
      ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault());
  private static final ZonedDateTime UPDATED_UPDATED =
      ZonedDateTime.now(ZoneId.systemDefault()).withNano(0);
  private static final String DEFAULT_UPDATED_STR = dateTimeFormatter.format(DEFAULT_UPDATED);
  private static final String DEFAULT_URL = "AAAAA";
  private static final String UPDATED_URL = "BBBBB";

  @Inject private ApartmentRepository apartmentRepository;

  @Inject private ApartmentSearchRepository apartmentSearchRepository;

  @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter;

  @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver;

  private MockMvc restApartmentMockMvc;

  private Apartment apartment;

  @PostConstruct
  public void setup() {
    MockitoAnnotations.initMocks(this);
    ApartmentResource apartmentResource = new ApartmentResource();
    ReflectionTestUtils.setField(
        apartmentResource, "apartmentSearchRepository", apartmentSearchRepository);
    ReflectionTestUtils.setField(apartmentResource, "apartmentRepository", apartmentRepository);
    this.restApartmentMockMvc =
        MockMvcBuilders.standaloneSetup(apartmentResource)
            .setCustomArgumentResolvers(pageableArgumentResolver)
            .setMessageConverters(jacksonMessageConverter)
            .build();
  }

  @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 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 checkApartmentIdIsRequired() throws Exception {
    int databaseSizeBeforeTest = apartmentRepository.findAll().size();
    // set the field null
    apartment.setApartmentId(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);
  }

  @Test
  @Transactional
  public void checkCreatedIsRequired() throws Exception {
    int databaseSizeBeforeTest = apartmentRepository.findAll().size();
    // set the field null
    apartment.setCreated(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);
  }

  @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);
  }

  @Test
  @Transactional
  public void getAllApartments() throws Exception {
    // Initialize the database
    apartmentRepository.saveAndFlush(apartment);

    // Get all the apartments
    restApartmentMockMvc
        .perform(get("/api/apartments?sort=id,desc"))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.[*].id").value(hasItem(apartment.getId().intValue())))
        .andExpect(jsonPath("$.[*].apartmentId").value(hasItem(DEFAULT_APARTMENT_ID.intValue())))
        .andExpect(jsonPath("$.[*].created").value(hasItem(DEFAULT_CREATED_STR)))
        .andExpect(jsonPath("$.[*].updated").value(hasItem(DEFAULT_UPDATED_STR)))
        .andExpect(jsonPath("$.[*].url").value(hasItem(DEFAULT_URL.toString())));
  }

  @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 getNonExistingApartment() throws Exception {
    // Get the apartment
    restApartmentMockMvc
        .perform(get("/api/apartments/{id}", Long.MAX_VALUE))
        .andExpect(status().isNotFound());
  }

  @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 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);
  }
}
Example #6
0
/**
 * Test class for the NewsResource REST controller.
 *
 * @see NewsResource
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest
public class NewsResourceIntTest {

  private static final DateTimeFormatter dateTimeFormatter =
      DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z"));

  private static final String DEFAULT_TITLE = "A";
  private static final String UPDATED_TITLE = "B";

  private static final ZonedDateTime DEFAULT_DATE =
      ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault());
  private static final ZonedDateTime UPDATED_DATE =
      ZonedDateTime.now(ZoneId.systemDefault()).withNano(0);
  private static final String DEFAULT_DATE_STR = dateTimeFormatter.format(DEFAULT_DATE);
  private static final String DEFAULT_CONTENT = "A";
  private static final String UPDATED_CONTENT = "B";

  @Inject private NewsRepository newsRepository;

  @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter;

  @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver;

  private MockMvc restNewsMockMvc;

  private News news;

  @PostConstruct
  public void setup() {
    MockitoAnnotations.initMocks(this);
    NewsResource newsResource = new NewsResource();
    ReflectionTestUtils.setField(newsResource, "newsRepository", newsRepository);
    this.restNewsMockMvc =
        MockMvcBuilders.standaloneSetup(newsResource)
            .setCustomArgumentResolvers(pageableArgumentResolver)
            .setMessageConverters(jacksonMessageConverter)
            .build();
  }

  @Before
  public void initTest() {
    news = new News();
    news.setTitle(DEFAULT_TITLE);
    news.setDate(DEFAULT_DATE);
    news.setContent(DEFAULT_CONTENT);
  }

  @Test
  @Transactional
  public void createNews() throws Exception {
    int databaseSizeBeforeCreate = newsRepository.findAll().size();

    // Create the News

    restNewsMockMvc
        .perform(
            post("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isCreated());

    // Validate the News in the database
    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeCreate + 1);
    News testNews = newss.get(newss.size() - 1);
    assertThat(testNews.getTitle()).isEqualTo(DEFAULT_TITLE);
    assertThat(testNews.getDate()).isEqualTo(DEFAULT_DATE);
    assertThat(testNews.getContent()).isEqualTo(DEFAULT_CONTENT);
  }

  @Test
  @Transactional
  public void checkTitleIsRequired() throws Exception {
    int databaseSizeBeforeTest = newsRepository.findAll().size();
    // set the field null
    news.setTitle(null);

    // Create the News, which fails.

    restNewsMockMvc
        .perform(
            post("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isBadRequest());

    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void checkDateIsRequired() throws Exception {
    int databaseSizeBeforeTest = newsRepository.findAll().size();
    // set the field null
    news.setDate(null);

    // Create the News, which fails.

    restNewsMockMvc
        .perform(
            post("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isBadRequest());

    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void checkContentIsRequired() throws Exception {
    int databaseSizeBeforeTest = newsRepository.findAll().size();
    // set the field null
    news.setContent(null);

    // Create the News, which fails.

    restNewsMockMvc
        .perform(
            post("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isBadRequest());

    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeTest);
  }

  @Test
  @Transactional
  public void getAllNewss() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

    // Get all the newss
    restNewsMockMvc
        .perform(get("/api/newss?sort=id,desc"))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.[*].id").value(hasItem(news.getId().intValue())))
        .andExpect(jsonPath("$.[*].title").value(hasItem(DEFAULT_TITLE.toString())))
        .andExpect(jsonPath("$.[*].date").value(hasItem(DEFAULT_DATE_STR)))
        .andExpect(jsonPath("$.[*].content").value(hasItem(DEFAULT_CONTENT.toString())));
  }

  @Test
  @Transactional
  public void getNews() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

    // Get the news
    restNewsMockMvc
        .perform(get("/api/newss/{id}", news.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(news.getId().intValue()))
        .andExpect(jsonPath("$.title").value(DEFAULT_TITLE.toString()))
        .andExpect(jsonPath("$.date").value(DEFAULT_DATE_STR))
        .andExpect(jsonPath("$.content").value(DEFAULT_CONTENT.toString()));
  }

  @Test
  @Transactional
  public void getNonExistingNews() throws Exception {
    // Get the news
    restNewsMockMvc
        .perform(get("/api/newss/{id}", Long.MAX_VALUE))
        .andExpect(status().isNotFound());
  }

  @Test
  @Transactional
  public void updateNews() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

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

    // Update the news
    news.setTitle(UPDATED_TITLE);
    news.setDate(UPDATED_DATE);
    news.setContent(UPDATED_CONTENT);

    restNewsMockMvc
        .perform(
            put("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isOk());

    // Validate the News in the database
    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeUpdate);
    News testNews = newss.get(newss.size() - 1);
    assertThat(testNews.getTitle()).isEqualTo(UPDATED_TITLE);
    assertThat(testNews.getDate()).isEqualTo(UPDATED_DATE);
    assertThat(testNews.getContent()).isEqualTo(UPDATED_CONTENT);
  }

  @Test
  @Transactional
  public void deleteNews() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

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

    // Get the news
    restNewsMockMvc
        .perform(delete("/api/newss/{id}", news.getId()).accept(TestUtil.APPLICATION_JSON_UTF8))
        .andExpect(status().isOk());

    // Validate the database is empty
    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeDelete - 1);
  }
}