Exemplo n.º 1
0
  @Test
  public void returns_full_object_in_response() throws Exception {
    MetricDto metric =
        MetricTesting.newMetricDto()
            .setEnabled(true)
            .setValueType(ValueType.STRING.name())
            .setKey("metric-key");
    dbClient.metricDao().insert(dbSession, metric);
    ComponentDto component = ComponentTesting.newProjectDto("project-uuid").setKey("project-key");
    dbClient.componentDao().insert(dbSession, component);
    CustomMeasureDto customMeasure =
        newCustomMeasure(component, metric)
            .setCreatedAt(100_000_000L)
            .setDescription("custom-measure-description")
            .setTextValue("text-measure-value");
    dbClient.customMeasureDao().insert(dbSession, customMeasure);
    dbSession.commit();
    when(system.now()).thenReturn(123_456_789L);

    WsTester.Result response =
        ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION)
            .setParam(PARAM_ID, String.valueOf(customMeasure.getId()))
            .setParam(PARAM_DESCRIPTION, "new-custom-measure-description")
            .setParam(PARAM_VALUE, "new-text-measure-value")
            .execute();

    response.assertJson(getClass(), "custom-measure.json");
    String responseAsString = response.outputAsString();
    assertThat(responseAsString)
        .matches(String.format(".*\"id\"\\s*:\\s*\"%s\".*", customMeasure.getId()));
    assertThat(responseAsString)
        .matches(String.format(".*\"id\"\\s*:\\s*\"%s\".*", metric.getId()));
    assertThat(responseAsString).matches(".*createdAt.*updatedAt.*");
  }
Exemplo n.º 2
0
  @Test
  public void web_service_returns_204() throws Exception {
    insertNewProjectInDbAndReturnSnapshotId(1);

    WsTester.Result result = newRequest().setParam(PARAM_ID, "project-uuid-1").execute();

    result.assertNoContent();
  }
  @Test
  public void search() throws Exception {
    Activity activity = new Activity();
    activity.setType(Activity.Type.ANALYSIS_REPORT);
    activity.setAction("THE_ACTION");
    activity.setMessage("THE_MSG");
    activity.setData("foo", "bar");
    service.save(activity);

    WsTester.TestRequest request = tester.wsTester().newGetRequest("api/activities", "search");
    WsTester.Result result = request.execute();
    assertThat(result.outputAsString()).contains("\"total\":1");
    assertThat(result.outputAsString()).contains("\"type\":\"ANALYSIS_REPORT\"");
    assertThat(result.outputAsString()).contains("\"details\":{\"foo\":\"bar\"}");
  }
  @Test
  public void json_example_validated() throws Exception {
    insertNewMetricDto(newEnabledMetric("API Compatibility"));
    insertNewMetricDto(newEnabledMetric("Issues"));
    insertNewMetricDto(newEnabledMetric("Rules"));
    insertNewMetricDto(newEnabledMetric("Tests"));
    insertNewMetricDto(newEnabledMetric("Documentation"));
    insertNewMetricDto(newEnabledMetric(null));
    insertNewMetricDto(newEnabledMetric(""));
    insertNewMetricDto(newMetricDto().setDomain("Domain of Deactivated Metric").setEnabled(false));

    WsTester.Result result = ws.newGetRequest(MetricsWs.ENDPOINT, "domains").execute();

    JsonAssert.assertJson(result.outputAsString())
        .isSimilarTo(getClass().getResource("example-domains.json"));
  }