diff options
author | Godin <mandrikov@gmail.com> | 2010-12-13 15:34:18 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-13 15:34:18 +0000 |
commit | d52d82788c75ca8f67270b247105d3350b22f4e8 (patch) | |
tree | 52550df8b7c9c2f3bf4a2a94afa6edb6c659bd9e /sonar-ws-client | |
parent | 1147fd00b57d8b0d519315b04ffa0b8443a979cd (diff) | |
download | sonarqube-d52d82788c75ca8f67270b247105d3350b22f4e8.tar.gz sonarqube-d52d82788c75ca8f67270b247105d3350b22f4e8.zip |
Improve tests for sonar-ws-client
Diffstat (limited to 'sonar-ws-client')
17 files changed, 95 insertions, 108 deletions
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshallerTest.java index 3d30f1b9cff..4d5e412330e 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshallerTest.java @@ -19,11 +19,9 @@ */ 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; @@ -31,11 +29,11 @@ import static org.junit.Assert.assertThat; 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")); @@ -49,8 +47,8 @@ public class DependencyTreeUnmarshallerTest { } @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)); @@ -62,8 +60,4 @@ public class DependencyTreeUnmarshallerTest { assertThat(secondLevelTrees.get(1).getResourceName(), is("Commons Lang")); } - private static String loadFile(String path) throws IOException { - return IOUtils.toString(DependencyTreeUnmarshallerTest.class.getResourceAsStream(path)); - } - } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshallerTest.java index 985a05cd7fa..d5c999d57ff 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshallerTest.java @@ -19,11 +19,9 @@ */ 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; @@ -33,11 +31,11 @@ import static org.junit.Assert.assertThat; 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")); @@ -50,16 +48,12 @@ public class DependencyUnmarshallerTest { } @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)); - } - } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/EventUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/EventUnmarshallerTest.java index 556ebc88cb2..1577760bb23 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/EventUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/EventUnmarshallerTest.java @@ -19,27 +19,27 @@ */ 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)); } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/MetricUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/MetricUnmarshallerTest.java index 9acb259edcd..1ac9d9a83b1 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/MetricUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/MetricUnmarshallerTest.java @@ -19,11 +19,9 @@ */ 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; @@ -34,11 +32,11 @@ import static org.junit.Assert.assertTrue; 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")); @@ -46,21 +44,16 @@ public class MetricUnmarshallerTest { 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)); - } } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java index 615407b15b1..6b709a3a594 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java @@ -12,7 +12,7 @@ public class PluginUnmarshallerTest { @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")); diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshallerTest.java index 6a788964e04..ea919cb18f6 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshallerTest.java @@ -19,11 +19,9 @@ */ 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; @@ -32,28 +30,24 @@ import static org.junit.Assert.assertThat; 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)); - } } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshallerTest.java index 9561968f9de..98df780a512 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshallerTest.java @@ -19,11 +19,9 @@ */ 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; @@ -34,8 +32,8 @@ import static org.junit.Assert.assertThat; 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); @@ -44,8 +42,8 @@ public class ResourceUnmarshallerTest { } @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)); @@ -55,8 +53,8 @@ public class ResourceUnmarshallerTest { } @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)); @@ -69,8 +67,8 @@ public class ResourceUnmarshallerTest { } @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) { @@ -81,8 +79,8 @@ public class ResourceUnmarshallerTest { } @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) { @@ -102,8 +100,4 @@ public class ResourceUnmarshallerTest { 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)); - } } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/RuleUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/RuleUnmarshallerTest.java index a5cc7f04a5a..57c4f43dc26 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/RuleUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/RuleUnmarshallerTest.java @@ -19,11 +19,9 @@ */ 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; @@ -33,14 +31,14 @@ import static org.junit.Assert.assertThat; 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); @@ -58,8 +56,4 @@ public class RuleUnmarshallerTest { assertThat(rule.isActive(), is(true)); } - private static String loadFile(String path) throws IOException { - return IOUtils.toString(MetricUnmarshallerTest.class.getResourceAsStream(path)); - } - } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java index 830996828f4..8e966d1a7c1 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java @@ -22,8 +22,6 @@ package org.sonar.wsclient.unmarshallers; 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; @@ -31,8 +29,8 @@ 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)); @@ -40,11 +38,12 @@ public class ServerUnmarshallerTest { } @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()); } + } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/SourceUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/SourceUnmarshallerTest.java index 1e5558865f1..31061fa2bbe 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/SourceUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/SourceUnmarshallerTest.java @@ -19,12 +19,9 @@ */ 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; @@ -32,24 +29,21 @@ 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)); - } } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java index a05319884a2..13a8b5c0482 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java @@ -1,10 +1,8 @@ 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; @@ -18,7 +16,7 @@ public class TimeMachineUnmarshallerTest { @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)); @@ -34,14 +32,10 @@ public class TimeMachineUnmarshallerTest { @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)); - } - } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java index 4f2feefd4a5..22e256dc73b 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java @@ -19,11 +19,9 @@ */ 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; @@ -35,11 +33,11 @@ import static org.junit.Assert.assertThat; 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); @@ -57,15 +55,11 @@ public class ViolationUnmarshallerTest { } @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)); - } - } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/WSTestUtils.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/WSTestUtils.java new file mode 100644 index 00000000000..a6c8981137d --- /dev/null +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/WSTestUtils.java @@ -0,0 +1,39 @@ +/* + * 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() { + } + +} diff --git a/sonar-ws-client/src/test/resources/events/events.json b/sonar-ws-client/src/test/resources/events/events.json new file mode 100644 index 00000000000..a76260924bf --- /dev/null +++ b/sonar-ws-client/src/test/resources/events/events.json @@ -0,0 +1 @@ +[{"id": "10", "n": "foo", "ds": "desc", "c": "categ", "dt": "2009-12-25T15:59:23+0000"}] diff --git a/sonar-ws-client/src/test/resources/plugins/plugins.json b/sonar-ws-client/src/test/resources/plugins/plugins.json new file mode 100644 index 00000000000..d762cf6fb86 --- /dev/null +++ b/sonar-ws-client/src/test/resources/plugins/plugins.json @@ -0,0 +1 @@ +[{"key": "foo", "name": "Foo", "version": "1.0"}] diff --git a/sonar-ws-client/src/test/resources/server/server.json b/sonar-ws-client/src/test/resources/server/server.json new file mode 100644 index 00000000000..c772e9020e5 --- /dev/null +++ b/sonar-ws-client/src/test/resources/server/server.json @@ -0,0 +1 @@ +{"id":"123456789", "version":"2.0-SNAPSHOT", "status":"UP", "status_msg":"everything is under control"} diff --git a/sonar-ws-client/src/test/resources/server/status_missing.json b/sonar-ws-client/src/test/resources/server/status_missing.json new file mode 100644 index 00000000000..a68e4ce63c5 --- /dev/null +++ b/sonar-ws-client/src/test/resources/server/status_missing.json @@ -0,0 +1 @@ +{"id":"123456789", "version":"2.0-SNAPSHOT"} |