*/
package org.sonar.wsclient.unmarshallers;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.wsclient.services.DependencyTree;
-import java.io.IOException;
import java.util.List;
import static org.hamcrest.core.Is.is;
public class DependencyTreeUnmarshallerTest {
@Test
- public void singleDepthOfDependencies() throws IOException {
+ public void singleDepthOfDependencies() {
List<DependencyTree> trees = new DependencyTreeUnmarshaller().toModels("[]");
assertThat(trees.size(), is(0));
- trees = new DependencyTreeUnmarshaller().toModels(loadFile("/dependency_tree/single_depth.json"));
+ trees = new DependencyTreeUnmarshaller().toModels(WSTestUtils.loadFile("/dependency_tree/single_depth.json"));
assertThat(trees.size(), is(2));
assertThat(trees.get(0).getDepId(), is("12345"));
assertThat(trees.get(0).getResourceId(), is("2000"));
}
@Test
- public void manyDepthsOfDependencies() throws IOException {
- List<DependencyTree> trees = new DependencyTreeUnmarshaller().toModels(loadFile("/dependency_tree/many_depths.json"));
+ public void manyDepthsOfDependencies() {
+ List<DependencyTree> trees = new DependencyTreeUnmarshaller().toModels(WSTestUtils.loadFile("/dependency_tree/many_depths.json"));
assertThat(trees.size(), is(1));
List<DependencyTree> secondLevelTrees = trees.get(0).getTo();
assertThat(secondLevelTrees.size(), is(2));
assertThat(secondLevelTrees.get(1).getResourceName(), is("Commons Lang"));
}
- private static String loadFile(String path) throws IOException {
- return IOUtils.toString(DependencyTreeUnmarshallerTest.class.getResourceAsStream(path));
- }
-
}
*/
package org.sonar.wsclient.unmarshallers;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.wsclient.services.Dependency;
-import java.io.IOException;
import java.util.Collection;
import static org.hamcrest.CoreMatchers.nullValue;
public class DependencyUnmarshallerTest {
@Test
- public void toModel() throws IOException {
+ public void toModel() {
Dependency dependency = new DependencyUnmarshaller().toModel("[]");
assertThat(dependency, nullValue());
- dependency = new DependencyUnmarshaller().toModel(loadFile("/dependencies/single.json"));
+ dependency = new DependencyUnmarshaller().toModel(WSTestUtils.loadFile("/dependencies/single.json"));
assertThat(dependency.getId(), is("1649"));
assertThat(dependency.getFromKey(), is("org.apache.shiro:shiro-core:org.apache.shiro.authc.pam"));
assertThat(dependency.getToKey(), is("org.apache.shiro:shiro-core:org.apache.shiro.realm"));
}
@Test
- public void toModels() throws IOException {
+ public void toModels() {
Collection<Dependency> dependencies = new DependencyUnmarshaller().toModels("[]");
assertThat(dependencies.size(), is(0));
- dependencies = new DependencyUnmarshaller().toModels(loadFile("/dependencies/many.json"));
+ dependencies = new DependencyUnmarshaller().toModels(WSTestUtils.loadFile("/dependencies/many.json"));
assertThat(dependencies.size(), is(15));
}
- private static String loadFile(String path) throws IOException {
- return IOUtils.toString(DependencyUnmarshallerTest.class.getResourceAsStream(path));
- }
-
}
*/
package org.sonar.wsclient.unmarshallers;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
+import org.junit.Test;
+import org.sonar.wsclient.services.Event;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
-import org.junit.Test;
-import org.sonar.wsclient.services.Event;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
public class EventUnmarshallerTest {
@Test
public void toModel() throws Exception {
- List<Event> events = new EventUnmarshaller().toModels("[{\"id\": \"10\", \"n\": \"foo\", \"ds\": \"desc\", \"c\": \"categ\", \"dt\": \"2009-12-25T15:59:23+0000\"}]");
+ List<Event> events = new EventUnmarshaller().toModels(WSTestUtils.loadFile("/events/events.json"));
Event event = events.get(0);
assertThat(event.getId(), is("10"));
assertThat(event.getName(), is("foo"));
assertThat(event.getDescription(), is("desc"));
assertThat(event.getCategory(), is("categ"));
- final Date expectedDate = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ssZZZZ").parse("2009-12-25T15:59:23+0000");
+ final Date expectedDate = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ssZZZZ").parse("2009-12-25T15:59:23+0000");
assertThat(event.getDate(), is(expectedDate));
}
*/
package org.sonar.wsclient.unmarshallers;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.wsclient.services.Metric;
-import java.io.IOException;
import java.util.Collection;
import static org.hamcrest.CoreMatchers.nullValue;
public class MetricUnmarshallerTest {
@Test
- public void toModel() throws IOException {
+ public void toModel() {
Metric metric = new MetricUnmarshaller().toModel("[]");
assertThat(metric, nullValue());
- metric = new MetricUnmarshaller().toModel(loadFile("/metrics/one_metric.json"));
+ metric = new MetricUnmarshaller().toModel(WSTestUtils.loadFile("/metrics/one_metric.json"));
assertThat(metric.getKey(), is("ncloc"));
assertThat(metric.getName(), is("Lines of code"));
assertThat(metric.getDescription(), is("Non Commenting Lines of Code"));
assertTrue(metric.getHidden());
}
-
-
@Test
- public void toModels() throws IOException {
+ public void toModels() {
Collection<Metric> metrics = new MetricUnmarshaller().toModels("[]");
assertThat(metrics.size(), is(0));
- metrics = new MetricUnmarshaller().toModels(loadFile("/metrics/one_metric.json"));
+ metrics = new MetricUnmarshaller().toModels(WSTestUtils.loadFile("/metrics/one_metric.json"));
assertThat(metrics.size(), is(1));
- metrics = new MetricUnmarshaller().toModels(loadFile("/metrics/many_metrics.json"));
+ metrics = new MetricUnmarshaller().toModels(WSTestUtils.loadFile("/metrics/many_metrics.json"));
assertThat(metrics.size(), is(10));
}
- private static String loadFile(String path) throws IOException {
- return IOUtils.toString(MetricUnmarshallerTest.class.getResourceAsStream(path));
- }
}
@Test
public void toModel() throws Exception {
- List<Plugin> plugins = new PluginUnmarshaller().toModels("[{\"key\": \"foo\", \"name\": \"Foo\", \"version\": \"1.0\"}]");
+ List<Plugin> plugins = new PluginUnmarshaller().toModels(WSTestUtils.loadFile("/plugins/plugins.json"));
Plugin plugin = plugins.get(0);
assertThat(plugin.getKey(), is("foo"));
assertThat(plugin.getName(), is("Foo"));
*/
package org.sonar.wsclient.unmarshallers;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.wsclient.services.Property;
-import java.io.IOException;
import java.util.Collection;
import static org.hamcrest.CoreMatchers.nullValue;
public class PropertyUnmarshallerTest {
@Test
- public void toModel() throws IOException {
+ public void toModel() {
Property property = new PropertyUnmarshaller().toModel("[]");
assertThat(property, nullValue());
- property = new PropertyUnmarshaller().toModel(loadFile("/properties/single.json"));
+ property = new PropertyUnmarshaller().toModel(WSTestUtils.loadFile("/properties/single.json"));
assertThat(property.getKey(), is("myprop"));
assertThat(property.getValue(), is("myvalue"));
}
@Test
- public void toModels() throws IOException {
+ public void toModels() {
Collection<Property> properties = new PropertyUnmarshaller().toModels("[]");
assertThat(properties.size(), is(0));
- properties = new PropertyUnmarshaller().toModels(loadFile("/properties/single.json"));
+ properties = new PropertyUnmarshaller().toModels(WSTestUtils.loadFile("/properties/single.json"));
assertThat(properties.size(), is(1));
- properties = new PropertyUnmarshaller().toModels(loadFile("/properties/many.json"));
+ properties = new PropertyUnmarshaller().toModels(WSTestUtils.loadFile("/properties/many.json"));
assertThat(properties.size(), is(3));
}
-
- private static String loadFile(String path) throws IOException {
- return IOUtils.toString(PropertyUnmarshallerTest.class.getResourceAsStream(path));
- }
}
*/
package org.sonar.wsclient.unmarshallers;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.wsclient.services.Resource;
-import java.io.IOException;
import java.util.List;
import static org.hamcrest.Matchers.nullValue;
public class ResourceUnmarshallerTest {
@Test
- public void singleResource() throws IOException {
- String json = loadFile("/resources/single-resource.json");
+ public void singleResource() {
+ String json = WSTestUtils.loadFile("/resources/single-resource.json");
assertSonar(new ResourceUnmarshaller().toModel(json));
List<Resource> resources = new ResourceUnmarshaller().toModels(json);
}
@Test
- public void singleResourceWithMeasures() throws IOException {
- Resource resource = new ResourceUnmarshaller().toModel(loadFile("/resources/single-resource-with-measures.json"));
+ public void singleResourceWithMeasures() {
+ Resource resource = new ResourceUnmarshaller().toModel(WSTestUtils.loadFile("/resources/single-resource-with-measures.json"));
assertSonar(resource);
assertThat(resource.getMeasures().size(), is(2));
}
@Test
- public void singleResourceWithTrends() throws IOException {
- Resource resource = new ResourceUnmarshaller().toModel(loadFile("/resources/single-resource-with-trends.json"));
+ public void singleResourceWithTrends() {
+ Resource resource = new ResourceUnmarshaller().toModel(WSTestUtils.loadFile("/resources/single-resource-with-trends.json"));
assertSonar(resource);
assertThat(resource.getMeasures().size(), is(2));
}
@Test
- public void manyResources() throws IOException {
- List<Resource> resources = new ResourceUnmarshaller().toModels(loadFile("/resources/many-resources.json"));
+ public void manyResources() {
+ List<Resource> resources = new ResourceUnmarshaller().toModels(WSTestUtils.loadFile("/resources/many-resources.json"));
assertThat(resources.size(), is(19));
for (Resource resource : resources) {
}
@Test
- public void manyResourcesWithMeasures() throws IOException {
- List<Resource> resources = new ResourceUnmarshaller().toModels(loadFile("/resources/many-resources-with-measures.json"));
+ public void manyResourcesWithMeasures() {
+ List<Resource> resources = new ResourceUnmarshaller().toModels(WSTestUtils.loadFile("/resources/many-resources-with-measures.json"));
assertThat(resources.size(), is(17));
for (Resource resource : resources) {
assertThat(resource.getDescription(), is("Embrace Quality"));
assertThat(resource.getDate(), not(nullValue()));
}
-
- private static String loadFile(String path) throws IOException {
- return IOUtils.toString(ResourceUnmarshallerTest.class.getResourceAsStream(path));
- }
}
*/
package org.sonar.wsclient.unmarshallers;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.wsclient.services.Rule;
-import java.io.IOException;
import java.util.List;
import static org.hamcrest.Matchers.is;
public class RuleUnmarshallerTest {
@Test
- public void toModels() throws IOException {
+ public void toModels() {
Rule rule = new RuleUnmarshaller().toModel("[]");
assertThat(rule, nullValue());
List<Rule> rules = new RuleUnmarshaller().toModels("[]");
assertThat(rules.size(), is(0));
- rules = new RuleUnmarshaller().toModels(loadFile("/rules/rules.json"));
+ rules = new RuleUnmarshaller().toModels(WSTestUtils.loadFile("/rules/rules.json"));
assertThat(rules.size(), is(6));
rule = rules.get(0);
assertThat(rule.isActive(), is(true));
}
- private static String loadFile(String path) throws IOException {
- return IOUtils.toString(MetricUnmarshallerTest.class.getResourceAsStream(path));
- }
-
}
import org.junit.Test;
import org.sonar.wsclient.services.Server;
-import java.io.IOException;
-
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class ServerUnmarshallerTest {
@Test
- public void testToModel() throws IOException {
- Server server = new ServerUnmarshaller().toModel("{\"id\":\"123456789\", \"version\":\"2.0-SNAPSHOT\", \"status\":\"UP\", \"status_msg\":\"everything is under control\"}");
+ public void testToModel() {
+ Server server = new ServerUnmarshaller().toModel(WSTestUtils.loadFile("/server/server.json"));
assertThat(server.getId(), is("123456789"));
assertThat(server.getVersion(), is("2.0-SNAPSHOT"));
assertThat(server.getStatus(), is(Server.Status.UP));
}
@Test
- public void shouldNotFailIfStatusIsMissing() throws IOException {
- Server server = new ServerUnmarshaller().toModel("{\"id\":\"123456789\", \"version\":\"2.0-SNAPSHOT\"}");
+ public void shouldNotFailIfStatusIsMissing() {
+ Server server = new ServerUnmarshaller().toModel(WSTestUtils.loadFile("/server/status_missing.json"));
assertThat(server.getId(), is("123456789"));
assertThat(server.getVersion(), is("2.0-SNAPSHOT"));
assertThat(server.getStatus(), nullValue());
assertThat(server.getStatusMessage(), nullValue());
}
+
}
*/
package org.sonar.wsclient.unmarshallers;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.wsclient.services.Source;
-import java.io.IOException;
-
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class SourceUnmarshallerTest {
@Test
- public void toModel() throws IOException {
+ public void toModel() {
Source source = new SourceUnmarshaller().toModel("[]");
assertThat(source, nullValue());
- source = new SourceUnmarshaller().toModel(loadFile("/sources/source.json"));
+ source = new SourceUnmarshaller().toModel(WSTestUtils.loadFile("/sources/source.json"));
assertThat(source.getLines().size(), is(236));
assertThat(source.getLine(3), is(" * Copyright (C) 2009 SonarSource SA"));
}
@Test
- public void fromLineToLine() throws IOException {
- Source source = new SourceUnmarshaller().toModel(loadFile("/sources/from_line_to_line.json"));
+ public void fromLineToLine() {
+ Source source = new SourceUnmarshaller().toModel(WSTestUtils.loadFile("/sources/from_line_to_line.json"));
assertThat(source.getLines().size(), is(15));
assertThat(source.getLine(1), nullValue());
assertThat(source.getLine(3), is(" * Copyright (C) 2009 SonarSource SA"));
}
- private static String loadFile(String path) throws IOException {
- return IOUtils.toString(PropertyUnmarshallerTest.class.getResourceAsStream(path));
- }
}
package org.sonar.wsclient.unmarshallers;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.wsclient.services.TimeMachineData;
-import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Test
public void toModel() throws Exception {
- TimeMachineData data = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/timemachine.json"));
+ TimeMachineData data = new TimeMachineUnmarshaller().toModel(WSTestUtils.loadFile("/timemachine/timemachine.json"));
Map<Date, List<String>> map = data.getData();
assertThat(map.size(), is(1));
@Test
public void many() throws Exception {
- TimeMachineData data = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/many.json"));
+ TimeMachineData data = new TimeMachineUnmarshaller().toModel(WSTestUtils.loadFile("/timemachine/many.json"));
Map<Date, List<String>> map = data.getData();
assertThat(map.size(), is(3));
}
- private static String loadFile(String path) throws IOException {
- return IOUtils.toString(TimeMachineUnmarshallerTest.class.getResourceAsStream(path));
- }
-
}
*/
package org.sonar.wsclient.unmarshallers;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.wsclient.services.Violation;
-import java.io.IOException;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
public class ViolationUnmarshallerTest {
@Test
- public void toModels() throws IOException {
+ public void toModels() {
Violation violation = new ViolationUnmarshaller().toModel("[]");
assertThat(violation, nullValue());
- List<Violation> violations = new ViolationUnmarshaller().toModels(loadFile("/violations/violations.json"));
+ List<Violation> violations = new ViolationUnmarshaller().toModels(WSTestUtils.loadFile("/violations/violations.json"));
assertThat(violations.size(), is(2));
violation = violations.get(0);
}
@Test
- public void violationWithoutLineNumber() throws IOException {
- Violation violation = new ViolationUnmarshaller().toModel(loadFile("/violations/violation-without-optional-fields.json"));
+ public void violationWithoutLineNumber() {
+ Violation violation = new ViolationUnmarshaller().toModel(WSTestUtils.loadFile("/violations/violation-without-optional-fields.json"));
assertThat(violation.getMessage(), not(nullValue()));
assertThat(violation.getLine(), nullValue());
assertThat(violation.getCreatedAt(), nullValue());
}
- private static String loadFile(String path) throws IOException {
- return IOUtils.toString(MetricUnmarshallerTest.class.getResourceAsStream(path));
- }
-
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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.apache.commons.io.IOUtils;
+
+import java.io.IOException;
+
+public final class WSTestUtils {
+
+ public static String loadFile(String path) {
+ try {
+ return IOUtils.toString(WSTestUtils.class.getResourceAsStream(path));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private WSTestUtils() {
+ }
+
+}
--- /dev/null
+[{"id": "10", "n": "foo", "ds": "desc", "c": "categ", "dt": "2009-12-25T15:59:23+0000"}]
--- /dev/null
+[{"key": "foo", "name": "Foo", "version": "1.0"}]
--- /dev/null
+{"id":"123456789", "version":"2.0-SNAPSHOT", "status":"UP", "status_msg":"everything is under control"}
--- /dev/null
+{"id":"123456789", "version":"2.0-SNAPSHOT"}