Ejemplo n.º 1
0
  @Nullable
  public PastSnapshot find(Snapshot projectSnapshot, int index, String property) {
    if (StringUtils.isBlank(property)) {
      return null;
    }

    PastSnapshot result = findByDays(projectSnapshot, property);
    if (result == null) {
      result = findByDate(projectSnapshot, property);
      if (result == null) {
        result = findByPreviousAnalysis(projectSnapshot, property);
        if (result == null) {
          result = findByPreviousVersion(projectSnapshot, property);
          if (result == null) {
            result = findByVersion(projectSnapshot, property);
          }
        }
      }
    }

    if (result != null) {
      result.setIndex(index);
    }

    return result;
  }
Ejemplo n.º 2
0
  @Test
  public void shouldFindByVersion() {
    when(finderByVersion.findByVersion(null, "1.2"))
        .thenReturn(new PastSnapshot("version", new Snapshot()));

    PastSnapshot variationSnapshot = finder.find(null, 2, "1.2");

    verify(finderByVersion).findByVersion(null, "1.2");
    assertThat(variationSnapshot.getIndex(), is(2));
    assertThat(variationSnapshot.getMode(), is("version"));
    assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
  }
Ejemplo n.º 3
0
  @Test
  public void shouldFindByNumberOfDays() {
    when(finderByDays.findFromDays(null, 30))
        .thenReturn(new PastSnapshot("days", null).setModeParameter("30"));

    PastSnapshot variationSnapshot = finder.find(null, 1, "30");

    verify(finderByDays).findFromDays(null, 30);
    assertNotNull(variationSnapshot);
    assertThat(variationSnapshot.getIndex(), is(1));
    assertThat(variationSnapshot.getMode(), is("days"));
    assertThat(variationSnapshot.getModeParameter(), is("30"));
  }
Ejemplo n.º 4
0
  @Test
  public void shouldFindByPreviousAnalysis() throws ParseException {
    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    final Date date = format.parse("2010-05-18");
    Snapshot snapshot = new Snapshot();
    snapshot.setCreatedAt(date);
    when(finderByPreviousAnalysis.findByPreviousAnalysis(null))
        .thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, snapshot));

    PastSnapshot variationSnapshot =
        finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);

    verify(finderByPreviousAnalysis).findByPreviousAnalysis(null);
    assertThat(variationSnapshot.getIndex(), is(2));
    assertThat(variationSnapshot.getMode(), is(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS));
    assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
  }
Ejemplo n.º 5
0
  @Test
  public void shouldFindByDate() throws ParseException {
    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    final Date date = format.parse("2010-05-18");
    when(finderByDate.findByDate(null, date)).thenReturn(new PastSnapshot("date", new Snapshot()));

    PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18");

    verify(finderByDate)
        .findByDate(
            (Snapshot) anyObject(),
            argThat(
                new BaseMatcher<Date>() {
                  public boolean matches(Object o) {
                    return o.equals(date);
                  }

                  public void describeTo(Description description) {}
                }));
    assertThat(variationSnapshot.getIndex(), is(2));
    assertThat(variationSnapshot.getMode(), is("date"));
    assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
  }
  private void initModulePastSnapshots() {
    periods = newLinkedList();
    modulePastSnapshots = newLinkedList();
    for (PastSnapshot projectPastSnapshot : periodsDefinition.getRootProjectPastSnapshots()) {
      Snapshot snapshot = findSnapshot(projectPastSnapshot.getProjectSnapshot());

      PastSnapshot pastSnapshot = projectPastSnapshot.clonePastSnapshot();
      modulePastSnapshots.add(pastSnapshot);
      // When no snapshot is found, date of the period is null
      periods.add(
          new Period(
              pastSnapshot.getIndex(),
              snapshot != null ? longToDate(snapshot.getCreatedAtMs()) : null));
      LOG.info(pastSnapshot.toString());
    }
  }