diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-07-27 10:59:00 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-07-27 12:12:01 +0200 |
commit | 58a8a74c05def9176479b2cf951c49f398cb72f8 (patch) | |
tree | 336eabec56e974a6668c3547c1ee64c12dca5a66 /sonar-ws-client | |
parent | ea0fb362a7dd6188973c0cb27291720ae71c29ca (diff) | |
download | sonarqube-58a8a74c05def9176479b2cf951c49f398cb72f8.tar.gz sonarqube-58a8a74c05def9176479b2cf951c49f398cb72f8.zip |
SONAR-2648 New web service /api/manual_measures
Diffstat (limited to 'sonar-ws-client')
8 files changed, 377 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasure.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasure.java new file mode 100644 index 00000000000..a755dfbf438 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasure.java @@ -0,0 +1,133 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.wsclient.services; + +import java.util.Date; + +/** + * @since 2.10 + */ +public class ManualMeasure extends Model { + + private long id; + private String metricKey; + private String resourceKey; + private Double value; + private String textValue; + private Date createdAt; + private Date updatedAt; + private String userLogin; + private String userName; + + public ManualMeasure() { + } + + public long getId() { + return id; + } + + public ManualMeasure setId(long id) { + this.id = id; + return this; + } + + public String getMetricKey() { + return metricKey; + } + + public ManualMeasure setMetricKey(String metricKey) { + this.metricKey = metricKey; + return this; + } + + public Double getValue() { + return value; + } + + public ManualMeasure setValue(Double value) { + this.value = value; + return this; + } + + public String getTextValue() { + return textValue; + } + + public ManualMeasure setTextValue(String textValue) { + this.textValue = textValue; + return this; + } + + public Date getCreatedAt() { + return createdAt; + } + + public ManualMeasure setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + return this; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public ManualMeasure setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + public String getUserLogin() { + return userLogin; + } + + public ManualMeasure setUserLogin(String userLogin) { + this.userLogin = userLogin; + return this; + } + + public String getUserName() { + return userName; + } + + public ManualMeasure setUserName(String userName) { + this.userName = userName; + return this; + } + + public String getResourceKey() { + return resourceKey; + } + + public ManualMeasure setResourceKey(String resourceKey) { + this.resourceKey = resourceKey; + return this; + } + + @Override + public String toString() { + return new StringBuilder().append("Measure{") + .append("id='").append(id).append('\'') + .append("resourceKey='").append(resourceKey).append('\'') + .append("metricKey='").append(metricKey).append('\'') + .append(", value=").append(value) + .append(", textValue='").append(textValue).append('\'') + .append('}').toString(); + } +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasureQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasureQuery.java new file mode 100644 index 00000000000..e2db6c2a192 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasureQuery.java @@ -0,0 +1,64 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.wsclient.services; + +/** + * @since 2.10 + */ +public final class ManualMeasureQuery extends Query<ManualMeasure> { + public static final String BASE_URL = "/api/manual_measures?"; + + private String resourceKey; + private String metricKey; + + private ManualMeasureQuery(String resourceKey) { + this.resourceKey = resourceKey; + } + + public String getResourceKey() { + return resourceKey; + } + + public String getMetricKey() { + return metricKey; + } + + public ManualMeasureQuery setMetricKey(String s) { + this.metricKey = s; + return this; + } + + @Override + public String getUrl() { + StringBuilder sb = new StringBuilder(BASE_URL); + appendUrlParameter(sb, "resource", resourceKey); + appendUrlParameter(sb, "metric", metricKey); + return sb.toString(); + } + + @Override + public Class<ManualMeasure> getModelClass() { + return ManualMeasure.class; + } + + public static ManualMeasureQuery create(String resourceKey) { + return new ManualMeasureQuery(resourceKey); + } +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshaller.java new file mode 100644 index 00000000000..f3b1a2d7bf8 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshaller.java @@ -0,0 +1,45 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.wsclient.unmarshallers; + +import org.sonar.wsclient.services.ManualMeasure; +import org.sonar.wsclient.services.WSUtils; + +/** + * @since 2.10 + */ +public class ManualMeasureUnmarshaller extends AbstractUnmarshaller<ManualMeasure> { + + @Override + protected ManualMeasure parse(Object json) { + WSUtils utils = WSUtils.getINSTANCE(); + return new ManualMeasure() + .setId(utils.getLong(json, "id")) + .setMetricKey(utils.getString(json, "metric")) + .setResourceKey(utils.getString(json, "resource")) + .setCreatedAt(utils.getDateTime(json, "created_at")) + .setUpdatedAt(utils.getDateTime(json, "updated_at")) + .setUserLogin(utils.getString(json, "login")) + .setUserName(utils.getString(json, "username")) + .setValue(utils.getDouble(json, "val")) + .setTextValue(utils.getString(json, "text")) + ; + } +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java index 71be7418dcf..5974603e3d4 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java @@ -48,6 +48,7 @@ public final class Unmarshallers { unmarshallers.put(TimeMachine.class, new TimeMachineUnmarshaller()); unmarshallers.put(Profile.class, new ProfileUnmarshaller()); unmarshallers.put(Review.class, new ReviewUnmarshaller()); + unmarshallers.put(ManualMeasure.class, new ManualMeasureUnmarshaller()); } public static <MODEL extends Model> Unmarshaller<MODEL> forModel(Class<MODEL> modelClass) { diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ManualMeasureQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ManualMeasureQueryTest.java new file mode 100644 index 00000000000..dc3c38c071c --- /dev/null +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ManualMeasureQueryTest.java @@ -0,0 +1,41 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.wsclient.services; + +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class ManualMeasureQueryTest extends QueryTestCase { + + @Test + public void shouldGetAllResourceMeasures() { + ManualMeasureQuery query = ManualMeasureQuery.create("foo"); + assertThat(query.getUrl(), is("/api/manual_measures?resource=foo&")); + assertThat(query.getModelClass().getName(), is(ManualMeasure.class.getName())); + } + + @Test + public void shouldFilterMetric() { + ManualMeasureQuery query = ManualMeasureQuery.create("foo").setMetricKey("burned_budget"); + assertThat(query.getUrl(), is("/api/manual_measures?resource=foo&metric=burned_budget&")); + } +} diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java new file mode 100644 index 00000000000..cc6667bc4f9 --- /dev/null +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java @@ -0,0 +1,59 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.wsclient.unmarshallers; + +import org.junit.Test; +import org.sonar.wsclient.services.ManualMeasure; +import org.sonar.wsclient.services.Metric; + +import java.util.Collection; +import java.util.List; + +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class ManualMeasureUnmarshallerTest extends UnmarshallerTestCase { + + @Test + public void testSingleMeasure() { + ManualMeasure measure = new ManualMeasureUnmarshaller().toModel("[]"); + assertThat(measure, nullValue()); + + measure = new ManualMeasureUnmarshaller().toModel(loadFile("/manual_measures/single_measure.json")); + assertThat(measure.getId(), is(1L)); + assertThat(measure.getMetricKey(), is("burned_budget")); + assertThat(measure.getResourceKey(), is("org.apache.struts:struts-parent")); + assertThat(measure.getValue(), is(302.5)); + assertThat(measure.getUserLogin(), is("admin")); + assertThat(measure.getUserName(), is("Administrator")); + assertThat(measure.getCreatedAt().getDate(), is(27)); + assertThat(measure.getUpdatedAt().getDate(), is(3)); + } + + + @Test + public void testAllMeasures() { + List<ManualMeasure> measures = new ManualMeasureUnmarshaller().toModels(loadFile("/manual_measures/all_measures.json")); + assertThat(measures.size(), is(2)); + } +} diff --git a/sonar-ws-client/src/test/resources/manual_measures/all_measures.json b/sonar-ws-client/src/test/resources/manual_measures/all_measures.json new file mode 100644 index 00000000000..05bce196c2d --- /dev/null +++ b/sonar-ws-client/src/test/resources/manual_measures/all_measures.json @@ -0,0 +1,22 @@ +[ + { + "id":1, + "metric":"burned_budget", + "resource":"org.apache.struts:struts-parent", + "val":302.0, + "created_at":"2011-07-27T10:22:34+0200", + "updated_at":"2011-07-27T10:22:34+0200", + "login":"admin", + "username":"Administrator" + }, + { + "id":2, + "metric":"team_size", + "resource":"org.apache.struts:struts-parent", + "val":555.0, + "created_at":"2011-07-27T10:53:33+0200", + "updated_at":"2011-07-27T10:53:33+0200", + "login":"admin", + "username":"Administrator" + } +]
\ No newline at end of file diff --git a/sonar-ws-client/src/test/resources/manual_measures/single_measure.json b/sonar-ws-client/src/test/resources/manual_measures/single_measure.json new file mode 100644 index 00000000000..587d63bced8 --- /dev/null +++ b/sonar-ws-client/src/test/resources/manual_measures/single_measure.json @@ -0,0 +1,12 @@ +[ + { + "id":1, + "metric":"burned_budget", + "resource":"org.apache.struts:struts-parent", + "val":302.5, + "created_at":"2011-06-27T10:22:34+0200", + "updated_at":"2011-07-03T12:02:12+0200", + "login":"admin", + "username":"Administrator" + } +]
\ No newline at end of file |