summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Trutz2011-11-09 08:03:27 (EST)
committer Steffen Pingel2011-11-09 08:03:27 (EST)
commit64f3aef142b854b422a97cec36463d8d83885f4b (patch)
tree8262066e67baf7ada7a43bf6d4cc90b936feaffc
parentaa7dfa0e4e752fb1fa23e930390f5ff3299a5742 (diff)
downloadorg.eclipse.mylyn.reviews-64f3aef142b854b422a97cec36463d8d83885f4b.zip
org.eclipse.mylyn.reviews-64f3aef142b854b422a97cec36463d8d83885f4b.tar.gz
org.eclipse.mylyn.reviews-64f3aef142b854b422a97cec36463d8d83885f4b.tar.bz2
Unit tests for GerritHttpClient
-rw-r--r--gerrit/org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF3
-rw-r--r--gerrit/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClientTest.java72
-rw-r--r--gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java4
-rw-r--r--gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java7
4 files changed, 85 insertions, 1 deletions
diff --git a/gerrit/org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF b/gerrit/org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF
index 10e7e09..ed0d2aa 100644
--- a/gerrit/org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF
+++ b/gerrit/org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.mylyn.tests.util;bundle-version="3.5.0",
org.mockito;bundle-version="[1.8.4,2.0.0)",
org.objenesis;bundle-version="[1.0.0,2.0.0)",
org.hamcrest;bundle-version="[1.0.0,2.0.0)",
- org.eclipse.equinox.security
+ org.eclipse.equinox.security,
+ org.eclipse.mylyn.commons.net
Export-Package: org.eclipse.mylyn.internal.gerrit.core;x-internal:=true,
org.eclipse.mylyn.internal.gerrit.core.client;x-internal:=true,
org.eclipse.mylyn.internal.gerrit.core.egit;x-internal:=true
diff --git a/gerrit/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClientTest.java b/gerrit/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClientTest.java
new file mode 100644
index 0000000..b892b04
--- /dev/null
+++ b/gerrit/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClientTest.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Christian Trutz.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian Trutz - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.gerrit.core.client;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.commons.net.AbstractWebLocation;
+import org.eclipse.mylyn.internal.gerrit.core.client.GerritHttpClient.JsonEntity;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * Unit tests for {@link GerritHttpClient}.
+ *
+ * @author Christian Trutz
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class GerritHttpClientTest {
+
+ @Mock
+ AbstractWebLocation abstractWebLocation;
+
+ @Mock
+ IProgressMonitor progressMonitor;
+
+ /**
+ * Test {@link GerritHttpClient} constructor with {@code null} argument.
+ */
+ @Test(expected = AssertionFailedException.class)
+ public void constructorNull() {
+ new GerritHttpClient((AbstractWebLocation) null);
+ }
+
+ /**
+ * Test {@link GerritHttpClient#postJsonRequest(String, JsonEntity, IProgressMonitor)} with {@code null} service URI
+ * argument.
+ */
+ @Test(expected = AssertionFailedException.class)
+ public void postJsonRequestNullServiceUri() throws IOException, GerritException {
+ GerritHttpClient gerritHttpClient = new GerritHttpClient(abstractWebLocation);
+ gerritHttpClient.postJsonRequest(null, new JsonEntity() {
+ @Override
+ public String getContent() {
+ return "[]"; //$NON-NLS-1$
+ }
+ }, progressMonitor);
+ }
+
+ /**
+ * Test {@link GerritHttpClient#postJsonRequest(String, JsonEntity, IProgressMonitor)} with {@code null}
+ * {@link JsonEntity} argument.
+ */
+ @Test(expected = AssertionFailedException.class)
+ public void postJsonRequestNullJsonEntity() throws IOException, GerritException {
+ GerritHttpClient gerritHttpClient = new GerritHttpClient(abstractWebLocation);
+ gerritHttpClient.postJsonRequest("not null", null, progressMonitor); //$NON-NLS-1$
+ }
+
+}
diff --git a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
index e9d0678..7d1bda4 100644
--- a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
+++ b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
@@ -10,6 +10,7 @@
* Tasktop Technologies - improvements
* Sascha Scholz (SAP) - improvements
* GitHub, Inc. - fixes for bug 354753
+ * Christian Trutz - improvements
*********************************************************************/
package org.eclipse.mylyn.internal.gerrit.core.client;
@@ -88,6 +89,7 @@ import com.google.gwtjsonrpc.client.VoidResult;
* @author Mikael Kober
* @author Thomas Westling
* @author Steffen Pingel
+ * @author Christian Trutz
*/
public class GerritClient {
@@ -768,6 +770,8 @@ public class GerritClient {
throw (GerritException) operation.getException();
} else if (operation.getException() instanceof OperationCanceledException) {
throw (OperationCanceledException) operation.getException();
+ } else if (operation.getException() instanceof RuntimeException) {
+ throw (RuntimeException) operation.getException();
} else if (operation.getException() != null) {
GerritException e = new GerritException();
e.initCause(operation.getException());
diff --git a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
index e42295e..2f1f24b 100644
--- a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
+++ b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
@@ -8,6 +8,7 @@
* Contributors:
* Sony Ericsson/ST Ericsson - initial API and implementation
* Tasktop Technologies - improvements
+ * Christian Trutz - improvements
*********************************************************************/
package org.eclipse.mylyn.internal.gerrit.core.client;
@@ -29,6 +30,7 @@ import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.commons.core.CoreUtil;
import org.eclipse.mylyn.commons.net.AbstractWebLocation;
@@ -48,6 +50,7 @@ import com.google.gerrit.common.auth.userpass.LoginResult;
* @author Daniel Olsson, ST Ericsson
* @author Thomas Westling
* @author Steffen Pingel
+ * @author Christian Trutz
*/
public class GerritHttpClient {
@@ -74,6 +77,7 @@ public class GerritHttpClient {
private volatile Cookie xsrfCookie;
public GerritHttpClient(AbstractWebLocation location) {
+ Assert.isNotNull(location, "Location must be not null."); //$NON-NLS-1$
this.location = location;
this.httpClient = new HttpClient(WebUtil.getConnectionManager());
}
@@ -98,6 +102,9 @@ public class GerritHttpClient {
*/
public String postJsonRequest(String serviceUri, JsonEntity entity, IProgressMonitor monitor) throws IOException,
GerritException {
+ Assert.isNotNull(serviceUri, "Service URI must be not null."); //$NON-NLS-1$
+ Assert.isNotNull(entity, "JSON entity must be not null."); //$NON-NLS-1$
+
String openIdProvider = getOpenIdProvider();
hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor);