summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.server.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.lfs.server.test')
-rw-r--r--org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java27
-rw-r--r--org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java18
2 files changed, 33 insertions, 12 deletions
diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java
index ac707eacf0..f15edca01a 100644
--- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java
+++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java
@@ -72,14 +72,15 @@ public class DownloadTest extends LfsServerTest {
public void testDownloadInvalidPathInfo()
throws ClientProtocolException, IOException {
String TEXT = "test";
- AnyLongObjectId id = putContent(TEXT);
+ String id = putContent(TEXT).name().substring(0, 60);
Path f = Paths.get(getTempDirectory().toString(), "download");
try {
- getContent(id.name().substring(0, 60), f);
+ getContent(id, f);
fail("expected RuntimeException");
} catch (RuntimeException e) {
- assertEquals("Status: 422 Unprocessable Entity",
- e.getMessage());
+ String error = String.format(
+ "Invalid pathInfo '/%s' does not match '/{SHA-256}'", id);
+ assertEquals(formatErrorMessage(422, error), e.getMessage());
}
}
@@ -87,14 +88,14 @@ public class DownloadTest extends LfsServerTest {
public void testDownloadInvalidId()
throws ClientProtocolException, IOException {
String TEXT = "test";
- AnyLongObjectId id = putContent(TEXT);
+ String id = putContent(TEXT).name().replace('f', 'z');
Path f = Paths.get(getTempDirectory().toString(), "download");
try {
- getContent(id.name().replace('f', 'z'), f);
+ getContent(id, f);
fail("expected RuntimeException");
} catch (RuntimeException e) {
- assertEquals("Status: 422 Unprocessable Entity",
- e.getMessage());
+ String error = String.format("Invalid id: : %s", id);
+ assertEquals(formatErrorMessage(422, error), e.getMessage());
}
}
@@ -108,8 +109,8 @@ public class DownloadTest extends LfsServerTest {
getContent(id, f);
fail("expected RuntimeException");
} catch (RuntimeException e) {
- assertEquals("Status: 404 Not Found",
- e.getMessage());
+ String error = String.format("Object '%s' not found", id.getName());
+ assertEquals(formatErrorMessage(404, error), e.getMessage());
}
}
@@ -129,4 +130,10 @@ public class DownloadTest extends LfsServerTest {
FileUtils.delete(f.toFile(), FileUtils.RETRY);
}
+
+ @SuppressWarnings("boxing")
+ private String formatErrorMessage(int status, String message) {
+ return String.format("Status: %d {\n \"message\": \"%s\"\n}", status,
+ message);
+ }
}
diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java
index 8c266d4830..b4a4228901 100644
--- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java
+++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java
@@ -45,6 +45,7 @@ package org.eclipse.jgit.lfs.server.fs;
import static org.junit.Assert.assertEquals;
import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -186,8 +187,21 @@ public abstract class LfsServerTest {
StatusLine statusLine = response.getStatusLine();
int status = statusLine.getStatusCode();
if (statusLine.getStatusCode() >= 400) {
- throw new RuntimeException("Status: " + status + " "
- + statusLine.getReasonPhrase());
+ String error;
+ try {
+ BufferedInputStream bis = new BufferedInputStream(
+ response.getEntity().getContent());
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ int result = bis.read();
+ while (result != -1) {
+ buf.write((byte) result);
+ result = bis.read();
+ }
+ error = buf.toString();
+ } catch (IOException e) {
+ error = statusLine.getReasonPhrase();
+ }
+ throw new RuntimeException("Status: " + status + " " + error);
}
assertEquals(200, status);
}