import org.arvados.client.test.utils.ArvadosClientMockedWebServerTest;
import org.junit.Test;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.nio.file.Files;
import okhttp3.mockwebserver.MockResponse;
import static org.arvados.client.test.utils.ApiClientTestUtils.getResponse;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull;
public class KeepWebApiClientTest extends ArvadosClientMockedWebServerTest {
// given
String collectionUuid = "some-collection-uuid";
String filePathName = "sample-file-path";
- long offset = 1024;
+ long start = 1024;
+ Long end = null;
byte[] expectedData = "test data".getBytes();
server.enqueue(new MockResponse().setBody(buffer));
// when
- byte[] actualData = client.downloadPartial(collectionUuid, filePathName, offset);
+ InputStream inputStream = client.get(collectionUuid, filePathName, start, end);
+ byte[] actualData = inputStreamToByteArray(inputStream);
// then
assertNotNull(actualData);
- assertEquals(new String(expectedData), new String(actualData));
+ assertArrayEquals(expectedData, actualData);
}
}
+ private byte[] inputStreamToByteArray(InputStream inputStream) throws IOException {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ int nRead;
+ byte[] data = new byte[1024];
+ while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
+ buffer.write(data, 0, nRead);
+ }
+ buffer.flush();
+ return buffer.toByteArray();
+ }
+
}