aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/test/java/org
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-07-11 12:08:54 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-07-11 12:08:54 +0200
commitcbeacdfd2deca921a2f8c5b6663d2c701963faa7 (patch)
treee78a49a4b2d6db163650375adf21fd95f8b3790f /sonar-ws-client/src/test/java/org
parent8f7d6c7378e522c643d1e6bc6cacaf078763c749 (diff)
downloadsonarqube-cbeacdfd2deca921a2f8c5b6663d2c701963faa7.tar.gz
sonarqube-cbeacdfd2deca921a2f8c5b6663d2c701963faa7.zip
Fix quality flaws
Diffstat (limited to 'sonar-ws-client/src/test/java/org')
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java48
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java36
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java44
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/AuthenticationUnmarshallerTest.java18
4 files changed, 102 insertions, 44 deletions
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java
index 4cbe8a78d38..17955c9cdd8 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java
@@ -21,34 +21,32 @@ package org.sonar.wsclient.services;
import org.junit.Test;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class ResourceQueryTest extends QueryTestCase {
@Test
public void resource() {
ResourceQuery query = new ResourceQuery("org.foo:bar");
- assertThat(query.getUrl(), is("/api/resources?resource=org.foo%3Abar&verbose=false&"));
- assertThat(query.getResourceKeyOrId(), is("org.foo:bar"));
- assertThat(query.isVerbose(), is(false));
+ assertThat(query.getUrl()).isEqualTo(("/api/resources?resource=org.foo%3Abar&verbose=false&"));
+ assertThat(query.getResourceKeyOrId()).isEqualTo(("org.foo:bar"));
+ assertThat(query.isVerbose()).isEqualTo((false));
}
@Test
public void resourceByLanguages() {
ResourceQuery query = new ResourceQuery("org.foo:bar").setLanguages("java,php");
- assertThat(query.getUrl(), is("/api/resources?resource=org.foo%3Abar&languages=java%2Cphp&verbose=false&"));
- assertThat(query.getResourceKeyOrId(), is("org.foo:bar"));
+ assertThat(query.getUrl()).isEqualTo(("/api/resources?resource=org.foo%3Abar&languages=java%2Cphp&verbose=false&"));
+ assertThat(query.getResourceKeyOrId()).isEqualTo(("org.foo:bar"));
}
@Test
public void measures() {
ResourceQuery query = new ResourceQuery();
query.setMetrics("loc", "coverage", "lines");
- assertThat(query.getUrl(), is("/api/resources?metrics=loc,coverage,lines&verbose=false&"));
- assertThat(query.getResourceKeyOrId(), nullValue());
- assertThat(query.getMetrics(), is(new String[] { "loc", "coverage", "lines" }));
+ assertThat(query.getUrl()).isEqualTo(("/api/resources?metrics=loc,coverage,lines&verbose=false&"));
+ assertThat(query.getResourceKeyOrId()).isNull();
+ assertThat(query.getMetrics()).isEqualTo((new String[]{"loc", "coverage", "lines"}));
}
@Test
@@ -56,14 +54,14 @@ public class ResourceQueryTest extends QueryTestCase {
ResourceQuery query = new ResourceQuery();
query.setIncludeTrends(true);
- assertThat(query.getUrl(), is("/api/resources?includetrends=true&verbose=false&"));
+ assertThat(query.getUrl()).isEqualTo(("/api/resources?includetrends=true&verbose=false&"));
}
@Test
public void measuresOnRules() {
ResourceQuery query = new ResourceQuery().setMetrics("violations");
query.setRules("ruleA", "ruleB");
- assertThat(query.getUrl(), is("/api/resources?metrics=violations&rules=ruleA,ruleB&verbose=false&"));
+ assertThat(query.getUrl()).isEqualTo(("/api/resources?metrics=violations&rules=ruleA,ruleB&verbose=false&"));
}
@Test
@@ -71,13 +69,29 @@ public class ResourceQueryTest extends QueryTestCase {
ResourceQuery query = new ResourceQuery().setMetrics("violations");
query.setRuleSeverities("MAJOR", "MINOR");
- assertThat(query.getUrl(), is("/api/resources?metrics=violations&rule_priorities=MAJOR,MINOR&verbose=false&"));
+ assertThat(query.getUrl()).isEqualTo(("/api/resources?metrics=violations&rule_priorities=MAJOR,MINOR&verbose=false&"));
}
@Test
- public void build() {
+ public void should_create_query() {
ResourceQuery query = ResourceQuery.createForMetrics("org.foo", "ncloc", "lines");
- assertThat(query.getResourceKeyOrId(), is("org.foo"));
- assertThat(query.getMetrics(), is(new String[] { "ncloc", "lines" }));
+ assertThat(query.getResourceKeyOrId()).isEqualTo(("org.foo"));
+ assertThat(query.getMetrics()).isEqualTo((new String[]{"ncloc", "lines"}));
+ }
+
+ @Test
+ public void should_create_query_from_resource() {
+ ResourceQuery query = ResourceQuery.createForResource(new Resource().setId(1), "ncloc");
+ assertThat(query.getResourceKeyOrId()).isEqualTo("1");
+ assertThat(query.getUrl()).isEqualTo("/api/resources?resource=1&metrics=ncloc&verbose=false&");
+ }
+
+ @Test
+ public void should_not_create_query_from_resource_without_id() {
+ try {
+ ResourceQuery.createForResource(new Resource());
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalArgumentException.class);
+ }
}
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java
index af83f183e9b..d089f427991 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java
@@ -19,18 +19,17 @@
*/
package org.sonar.wsclient.services;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.wsclient.JdkUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.wsclient.JdkUtils;
+import static org.fest.assertions.Assertions.assertThat;
public class TimeMachineQueryTest extends QueryTestCase {
@@ -49,18 +48,31 @@ public class TimeMachineQueryTest extends QueryTestCase {
}
@Test
- public void shouldGetUrl() {
+ public void should_get_url() {
TimeMachineQuery query = TimeMachineQuery.createForMetrics("12345", "ncloc", "coverage");
- assertThat(query.getUrl(), is("/api/timemachine?resource=12345&metrics=ncloc,coverage&"));
+ assertThat(query.getUrl()).isEqualTo("/api/timemachine?resource=12345&metrics=ncloc,coverage&");
}
@Test
- public void shouldSetPeriod() throws ParseException {
+ public void should_set_period() throws ParseException {
Date from = new SimpleDateFormat("yyyy-MM-dd").parse("2010-02-18");
Date to = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2010-03-25 14:59");
TimeMachineQuery query = TimeMachineQuery.createForMetrics("12345", "ncloc").setFrom(from).setTo(to);
- assertThat(
- query.getUrl(),
- is("/api/timemachine?resource=12345&metrics=ncloc&fromDateTime=2010-02-18T00%3A00%3A00%2B0000&toDateTime=2010-03-25T14%3A59%3A00%2B0000&"));
+ assertThat(query.getUrl()).isEqualTo(
+ "/api/timemachine?resource=12345&metrics=ncloc&fromDateTime=2010-02-18T00%3A00%3A00%2B0000&toDateTime=2010-03-25T14%3A59%3A00%2B0000&");
+ }
+
+ @Test
+ public void should_create_query_from_resource() {
+ TimeMachineQuery query = TimeMachineQuery.createForMetrics(new Resource().setId(1), "ncloc");
+ assertThat(query.getUrl()).isEqualTo("/api/timemachine?resource=1&metrics=ncloc&"); }
+
+ @Test
+ public void should_not_create_query_from_resource_without_id() {
+ try {
+ TimeMachineQuery.createForMetrics(new Resource());
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalArgumentException.class);
+ }
}
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java
index 6da64d96cc1..2d8007bb57b 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java
@@ -19,30 +19,44 @@
*/
package org.sonar.wsclient.services;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
import org.junit.Test;
+import static org.fest.assertions.Assertions.assertThat;
+
public class ViolationQueryTest extends QueryTestCase {
@Test
- public void resourceViolations() {
+ public void should_create_query() {
ViolationQuery query = ViolationQuery.createForResource("myproject:org.foo:bar");
- assertThat(query.getUrl(), is("/api/violations?resource=myproject%3Aorg.foo%3Abar&"));
- assertThat(query.getModelClass().getName(), is(Violation.class.getName()));
+ assertThat(query.getUrl()).isEqualTo("/api/violations?resource=myproject%3Aorg.foo%3Abar&");
+ assertThat(query.getModelClass().getName()).isEqualTo(Violation.class.getName());
}
@Test
- public void resourceTreeViolations() {
+ public void should_create_query_tree() {
ViolationQuery query = ViolationQuery.createForResource("myproject")
- .setDepth(-1)
- .setLimit(20)
- .setSeverities("MAJOR", "BLOCKER")
- .setQualifiers("FIL")
- .setRuleKeys("checkstyle:foo", "pmd:bar");
- assertThat(
- query.getUrl(),
- is("/api/violations?resource=myproject&depth=-1&limit=20&qualifiers=FIL&rules=checkstyle%3Afoo,pmd%3Abar&priorities=MAJOR,BLOCKER&"));
+ .setDepth(-1)
+ .setLimit(20)
+ .setSeverities("MAJOR", "BLOCKER")
+ .setQualifiers("FIL")
+ .setRuleKeys("checkstyle:foo", "pmd:bar");
+ assertThat(query.getUrl()).isEqualTo(
+ "/api/violations?resource=myproject&depth=-1&limit=20&qualifiers=FIL&rules=checkstyle%3Afoo,pmd%3Abar&priorities=MAJOR,BLOCKER&");
+ }
+
+ @Test
+ public void should_create_query_from_resource() {
+ ViolationQuery query = ViolationQuery.createForResource(new Resource().setId(1));
+ assertThat(query.getUrl()).isEqualTo("/api/violations?resource=1&");
+ assertThat(query.getModelClass().getName()).isEqualTo(Violation.class.getName());
+ }
+
+ @Test
+ public void should_not_create_query_from_resource_without_id() {
+ try {
+ ViolationQuery.createForResource(new Resource());
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalArgumentException.class);
+ }
}
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/AuthenticationUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/AuthenticationUnmarshallerTest.java
index f66a507e94f..939d35645ad 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/AuthenticationUnmarshallerTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/AuthenticationUnmarshallerTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
import org.sonar.wsclient.services.Authentication;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
public class AuthenticationUnmarshallerTest extends UnmarshallerTestCase {
@Test
@@ -38,4 +39,21 @@ public class AuthenticationUnmarshallerTest extends UnmarshallerTestCase {
assertThat(authentication.isValid()).isFalse();
}
+
+ @Test
+ public void should_unmarshall_empty_authentication() {
+ Authentication authentication = new AuthenticationUnmarshaller().toModel("{}");
+
+ assertThat(authentication.isValid()).isFalse();
+ }
+
+ @Test
+ public void should_not_umarshall_authentication_list() {
+ try {
+ new AuthenticationUnmarshaller().toModels("[{\"valid\":true},{\"valid\":true}]");
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class);
+ }
+ }
}