Exemplo n.º 1
0
  public void printEvents(List<TimedEvent> events) {
    DateTimeFormatter isoLocalDate = DateTimeFormatter.ISO_LOCAL_DATE;
    DateTimeFormatter isoLocalTime = DateTimeFormatter.ISO_LOCAL_TIME;

    ZonedDateTime lastEventTime = ZonedDateTime.of(LocalDateTime.MIN, timeZone);

    for (Iterator<TimedEvent> iterator = events.iterator(); iterator.hasNext(); ) {
      TimedEvent timedEvent = (TimedEvent) iterator.next();
      ZonedDateTime timeCreated = timedEvent.getTimeCreated();

      // print a marker for each new day
      if (!timedEvent.isSameDay(lastEventTime)) {
        ps.print("------------ ");
        ps.print(timeCreated.format(isoLocalDate));
        ps.println(" ------------ ");
      }
      lastEventTime = timeCreated;

      ExtendedEventRecord eventRecord = timedEvent.getEventRecord();
      EventTypes eventType = EventTypes.fromInt(eventRecord.getEventId());
      String formattedTime = timeCreated.format(isoLocalTime);

      ps.println(String.format("%s: %s", formattedTime, eventType));
    }
  }
Exemplo n.º 2
0
 /**
  * Formats a {@link ZonedDateTime} to a string using the {@value #DATE_TIME_FORMATTER} {@link
  * DateTimeFormatter}.
  *
  * @param timestamp the timestamp.
  * @return A String formatted via {@link #DATE_TIME_FORMATTER}.
  */
 static String formatTimestamp(ZonedDateTime timestamp) {
   return timestamp.format(DATE_TIME_FORMATTER);
 }
/**
 * Test class for the BloodPressureResource REST controller.
 *
 * @see BloodPressureResource
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest
public class BloodPressureResourceIntTest {

  private static final ZonedDateTime DEFAULT_TIMESTAMP =
      ZonedDateTime.of(LocalDate.ofEpochDay(0L).atStartOfDay(), ZoneId.of("UTC"));
  private static final ZonedDateTime UPDATED_TIMESTAMP = ZonedDateTime.now(ZoneId.of("UTC"));
  private static final String DEFAULT_TIMESTAMP_STR =
      DEFAULT_TIMESTAMP.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"));

  private static final Integer DEFAULT_SYSTOLIC = 1;
  private static final Integer UPDATED_SYSTOLIC = 2;

  private static final Integer DEFAULT_DIASTOLIC = 1;
  private static final Integer UPDATED_DIASTOLIC = 2;

  @Inject private BloodPressureRepository bloodPressureRepository;

  @Inject private BloodPressureSearchRepository bloodPressureSearchRepository;

  @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter;

  @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver;

  @Inject private UserRepository userRepository;

  private MockMvc restBloodPressureMockMvc;

  private BloodPressure bloodPressure;

  @Autowired private WebApplicationContext context;

  @PostConstruct
  public void setup() {
    MockitoAnnotations.initMocks(this);
    BloodPressureResource bloodPressureResource = new BloodPressureResource();
    ReflectionTestUtils.setField(
        bloodPressureResource, "bloodPressureSearchRepository", bloodPressureSearchRepository);
    ReflectionTestUtils.setField(
        bloodPressureResource, "bloodPressureRepository", bloodPressureRepository);
    this.restBloodPressureMockMvc =
        MockMvcBuilders.standaloneSetup(bloodPressureResource)
            .setCustomArgumentResolvers(pageableArgumentResolver)
            .setMessageConverters(jacksonMessageConverter)
            .build();
  }

  @Before
  public void initTest() {
    bloodPressure = new BloodPressure();
    bloodPressure.setTimestamp(DEFAULT_TIMESTAMP);
    bloodPressure.setSystolic(DEFAULT_SYSTOLIC);
    bloodPressure.setDiastolic(DEFAULT_DIASTOLIC);
  }

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

    // Create the BloodPressure

    restBloodPressureMockMvc
        .perform(
            post("/api/bloodPressures")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(bloodPressure)))
        .andExpect(status().isCreated());

    // Validate the BloodPressure in the database
    List<BloodPressure> bloodPressures = bloodPressureRepository.findAll();
    assertThat(bloodPressures).hasSize(databaseSizeBeforeCreate + 1);
    BloodPressure testBloodPressure = bloodPressures.get(bloodPressures.size() - 1);
    assertThat(testBloodPressure.getTimestamp()).isEqualTo(DEFAULT_TIMESTAMP);
    assertThat(testBloodPressure.getSystolic()).isEqualTo(DEFAULT_SYSTOLIC);
    assertThat(testBloodPressure.getDiastolic()).isEqualTo(DEFAULT_DIASTOLIC);
  }

  @Test
  @Transactional
  public void getAllBloodPressures() throws Exception {
    // Initialize the database
    bloodPressureRepository.saveAndFlush(bloodPressure);

    // Get all the bloodPressures
    restBloodPressureMockMvc
        .perform(get("/api/bloodPressures?sort=id,desc"))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.[*].id").value(hasItem(bloodPressure.getId().intValue())))
        .andExpect(jsonPath("$.[*].timestamp").value(hasItem(DEFAULT_TIMESTAMP_STR)))
        .andExpect(jsonPath("$.[*].systolic").value(hasItem(DEFAULT_SYSTOLIC)))
        .andExpect(jsonPath("$.[*].diastolic").value(hasItem(DEFAULT_DIASTOLIC)));
  }

  @Test
  @Transactional
  public void getBloodPressure() throws Exception {
    // Initialize the database
    bloodPressureRepository.saveAndFlush(bloodPressure);

    // Get the bloodPressure
    restBloodPressureMockMvc
        .perform(get("/api/bloodPressures/{id}", bloodPressure.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(bloodPressure.getId().intValue()))
        .andExpect(jsonPath("$.timestamp").value(DEFAULT_TIMESTAMP_STR))
        .andExpect(jsonPath("$.systolic").value(DEFAULT_SYSTOLIC))
        .andExpect(jsonPath("$.diastolic").value(DEFAULT_DIASTOLIC));
  }

  @Test
  @Transactional
  public void getNonExistingBloodPressure() throws Exception {
    // Get the bloodPressure
    restBloodPressureMockMvc
        .perform(get("/api/bloodPressures/{id}", Long.MAX_VALUE))
        .andExpect(status().isNotFound());
  }

  @Test
  @Transactional
  public void updateBloodPressure() throws Exception {
    // Initialize the database
    bloodPressureRepository.saveAndFlush(bloodPressure);

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

    // Update the bloodPressure
    bloodPressure.setTimestamp(UPDATED_TIMESTAMP);
    bloodPressure.setSystolic(UPDATED_SYSTOLIC);
    bloodPressure.setDiastolic(UPDATED_DIASTOLIC);

    restBloodPressureMockMvc
        .perform(
            put("/api/bloodPressures")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(bloodPressure)))
        .andExpect(status().isOk());

    // Validate the BloodPressure in the database
    List<BloodPressure> bloodPressures = bloodPressureRepository.findAll();
    assertThat(bloodPressures).hasSize(databaseSizeBeforeUpdate);
    BloodPressure testBloodPressure = bloodPressures.get(bloodPressures.size() - 1);
    assertThat(testBloodPressure.getTimestamp()).isEqualTo(UPDATED_TIMESTAMP);
    assertThat(testBloodPressure.getSystolic()).isEqualTo(UPDATED_SYSTOLIC);
    assertThat(testBloodPressure.getDiastolic()).isEqualTo(UPDATED_DIASTOLIC);
  }

  @Test
  @Transactional
  public void deleteBloodPressure() throws Exception {
    // Initialize the database
    bloodPressureRepository.saveAndFlush(bloodPressure);

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

    // Get the bloodPressure
    restBloodPressureMockMvc
        .perform(
            delete("/api/bloodPressures/{id}", bloodPressure.getId())
                .accept(TestUtil.APPLICATION_JSON_UTF8))
        .andExpect(status().isOk());

    // Validate the database is empty
    List<BloodPressure> bloodPressures = bloodPressureRepository.findAll();
    assertThat(bloodPressures).hasSize(databaseSizeBeforeDelete - 1);
  }

  private void createBloodPressureByMonth(
      ZonedDateTime firstOfMonth, ZonedDateTime firstDayOfLastMonth) {
    User user = userRepository.findOneByLogin("user").get();
    // this month
    bloodPressure = new BloodPressure(firstOfMonth, 120, 80, user);
    bloodPressureRepository.saveAndFlush(bloodPressure);
    bloodPressure = new BloodPressure(firstOfMonth.plusDays(10), 125, 75, user);
    bloodPressureRepository.saveAndFlush(bloodPressure);
    bloodPressure = new BloodPressure(firstOfMonth.plusDays(20), 100, 69, user);
    bloodPressureRepository.saveAndFlush(bloodPressure);

    // last month
    bloodPressure = new BloodPressure(firstDayOfLastMonth, 130, 90, user);
    bloodPressureRepository.saveAndFlush(bloodPressure);
    bloodPressure = new BloodPressure(firstDayOfLastMonth.plusDays(11), 135, 85, user);
    bloodPressureRepository.saveAndFlush(bloodPressure);
    bloodPressure = new BloodPressure(firstDayOfLastMonth.plusDays(23), 130, 75, user);
    bloodPressureRepository.saveAndFlush(bloodPressure);
  }

  @Test
  @Transactional
  public void getBloodPressureForLast30Days() throws Exception {
    ZonedDateTime now = ZonedDateTime.now();
    ZonedDateTime firstOfMonth = now.withDayOfMonth(1);
    ZonedDateTime firstDayOfLastMonth = firstOfMonth.minusMonths(1);
    createBloodPressureByMonth(firstOfMonth, firstDayOfLastMonth);

    // create security-aware mockMvc
    restBloodPressureMockMvc =
        MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build();

    // Get all the blood pressure readings
    restBloodPressureMockMvc
        .perform(get("/api/bloodPressures").with(user("user").roles("USER")))
        .andExpect(status().isOk())
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$", hasSize(6)));

    // Get the blood pressure readings for the last 30 days
    restBloodPressureMockMvc
        .perform(get("/api/bp-by-days/{days}", 30).with(user("user").roles("USER")))
        .andDo(print())
        .andExpect(status().isOk())
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.period").value("Last 30 Days"))
        .andExpect(jsonPath("$.readings.[*].systolic").value(hasItem(120)))
        .andExpect(jsonPath("$.readings.[*].diastolic").value(hasItem(75)));
  }
}