Example #1
0
  @Test
  public void update_description_only() throws Exception {
    MetricDto metric = insertNewMetric(ValueType.STRING);
    ComponentDto component = insertNewProject("project-uuid");
    CustomMeasureDto customMeasure =
        newCustomMeasure(component, metric)
            .setMetricId(metric.getId())
            .setComponentUuid(component.uuid())
            .setCreatedAt(system.now())
            .setDescription("custom-measure-description")
            .setTextValue("text-measure-value");
    dbClient.customMeasureDao().insert(dbSession, customMeasure);
    dbSession.commit();
    when(system.now()).thenReturn(123_456_789L);

    ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION)
        .setParam(PARAM_ID, String.valueOf(customMeasure.getId()))
        .setParam(PARAM_VALUE, "new-text-measure-value")
        .execute();

    CustomMeasureDto updatedCustomMeasure =
        dbClient.customMeasureDao().selectOrFail(dbSession, customMeasure.getId());
    assertThat(updatedCustomMeasure.getTextValue()).isEqualTo("new-text-measure-value");
    assertThat(updatedCustomMeasure.getDescription()).isEqualTo("custom-measure-description");
    assertThat(updatedCustomMeasure.getUpdatedAt()).isEqualTo(123_456_789L);
    assertThat(customMeasure.getCreatedAt()).isEqualTo(updatedCustomMeasure.getCreatedAt());
  }
Example #2
0
  @Test
  public void update_double_value_and_description_in_db() throws Exception {
    MetricDto metric = insertNewMetric(ValueType.INT);
    ComponentDto component = insertNewProject("project-uuid");
    CustomMeasureDto customMeasure =
        newCustomMeasure(component, metric)
            .setDescription("custom-measure-description")
            .setValue(42d);
    dbClient.customMeasureDao().insert(dbSession, customMeasure);
    dbSession.commit();

    ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION)
        .setParam(PARAM_ID, String.valueOf(customMeasure.getId()))
        .setParam(PARAM_DESCRIPTION, "new-custom-measure-description")
        .setParam(PARAM_VALUE, "1984")
        .execute();

    CustomMeasureDto updatedCustomMeasure =
        dbClient.customMeasureDao().selectOrFail(dbSession, customMeasure.getId());
    assertThat(updatedCustomMeasure.getValue()).isCloseTo(1984d, offset(0.01d));
    assertThat(updatedCustomMeasure.getDescription()).isEqualTo("new-custom-measure-description");
    assertThat(customMeasure.getCreatedAt()).isEqualTo(updatedCustomMeasure.getCreatedAt());
  }