Skip to content

Commit

Permalink
SONAR-6572 WS metrics/update fix error message when updating with an …
Browse files Browse the repository at this point in the history
…existing key
  • Loading branch information
teryk committed Jun 8, 2015
1 parent 9e731cf commit 5696333
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Expand Up @@ -183,9 +183,10 @@ private void checkMetricInDbAndTemplate(DbSession dbSession, @Nullable MetricDto
}

private void checkNoOtherMetricWithTargetKey(DbSession dbSession, MetricDto metricInDb, MetricDto template) {
MetricDto metricWithTargetKey = dbClient.metricDao().selectNullableByKey(dbSession, template.getKey());
String targetKey = template.getKey();
MetricDto metricWithTargetKey = dbClient.metricDao().selectNullableByKey(dbSession, targetKey);
if (isMetricFoundInDb(metricWithTargetKey) && !metricInDb.getId().equals(metricWithTargetKey.getId())) {
throw new ServerException(HttpURLConnection.HTTP_CONFLICT, "A me metric exists with the key: " + metricInDb.getKey());
throw new ServerException(HttpURLConnection.HTTP_CONFLICT, String.format("The key '%s' is already used by an existing metric.", targetKey));
}
}

Expand Down
Expand Up @@ -143,6 +143,7 @@ public void update_return_the_full_object_with_id() throws Exception {
@Test
public void fail_when_changing_key_for_an_existing_one() throws Exception {
expectedException.expect(ServerException.class);
expectedException.expectMessage("The key 'metric-key' is already used by an existing metric.");
insertMetric(newDefaultMetric().setKey("metric-key"));
int id = insertMetric(newDefaultMetric().setKey("another-key"));

Expand Down

0 comments on commit 5696333

Please sign in to comment.