]> source.dussan.org Git - sonarqube.git/commitdiff
Improve tests for sonar-ws-client
authorGodin <mandrikov@gmail.com>
Mon, 13 Dec 2010 15:34:18 +0000 (15:34 +0000)
committerGodin <mandrikov@gmail.com>
Mon, 13 Dec 2010 15:34:18 +0000 (15:34 +0000)
17 files changed:
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/EventUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/MetricUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/RuleUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/SourceUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/WSTestUtils.java [new file with mode: 0644]
sonar-ws-client/src/test/resources/events/events.json [new file with mode: 0644]
sonar-ws-client/src/test/resources/plugins/plugins.json [new file with mode: 0644]
sonar-ws-client/src/test/resources/server/server.json [new file with mode: 0644]
sonar-ws-client/src/test/resources/server/status_missing.json [new file with mode: 0644]

index 3d30f1b9cff4d8dd951e7732bdf1d8f707be02d0..4d5e412330e8f6663e4fd5793dd05cecbde039fa 100644 (file)
  */
 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));
-  }
-
 }
index 985a05cd7fa4ff405c97e422ac71e62ba0cba60c..d5c999d57ff928996e00001d3ccfc308f9363217 100644 (file)
  */
 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));
-  }
-
 }
index 556ebc88cb202667413bcc0c1339702b3f05cf1f..1577760bb234196f2d82dd152cc2de5396a2fddf 100644 (file)
  */
 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));
   }
 
index 9acb259edcd3c7f54c1b46fa8f34f2b8103b67bf..1ac9d9a83b1296662083a556b89907c8f92c08bc 100644 (file)
  */
 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));
-  }
 }
index 615407b15b188c558ea0caf671a5f3948af6d940..6b709a3a5945eb8ed76a11c6e7e80a27a74d76eb 100644 (file)
@@ -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"));
index 6a788964e04c4bd227f0675bc44ec7cbb2dede4f..ea919cb18f65cd76fe494b6f364ab1df622d24df 100644 (file)
  */
 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));
-  }
 }
index 9561968f9de2a2c0688872ab2380d900a80893e2..98df780a5127b3895f54b2f83cd9a9efc5e63522 100644 (file)
  */
 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));
-  }
 }
index a5cc7f04a5a45d330cb0a9eab5252a1fe1b51132..57c4f43dc26ad1dcfcef6d83d114480a766d017f 100644 (file)
  */
 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));
-  }
-
 }
index 830996828f45cb3781294be38bd239b21825d7c0..8e966d1a7c16180ea3f78dc461f78cb566dda6e3 100644 (file)
@@ -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());
   }
+
 }
index 1e5558865f111c7ee66a2a6b1595d1195631c370..31061fa2bbe30a029150ae9fa20efd6cc2f0be91 100644 (file)
  */
 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));
-  }
 }
index a05319884a2a877597b03d2940f1911e932eb8f6..13a8b5c048267fa42c6d027c5e0bd6afbb5db1af 100644 (file)
@@ -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));
-  }
-
 }
index 4f2feefd4a59763d8067a1ea1010d336cb68a1c7..22e256dc73bea662e89650fd4b993f712d7cedbe 100644 (file)
  */
 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 (file)
index 0000000..a6c8981
--- /dev/null
@@ -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 (file)
index 0000000..a762609
--- /dev/null
@@ -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 (file)
index 0000000..d762cf6
--- /dev/null
@@ -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 (file)
index 0000000..c772e90
--- /dev/null
@@ -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 (file)
index 0000000..a68e4ce
--- /dev/null
@@ -0,0 +1 @@
+{"id":"123456789", "version":"2.0-SNAPSHOT"}