Skip to content

Commit f35d0cd

Browse files
committed
Add raw image bytes sync and async AndroidServiceClient tests
1 parent e0aff12 commit f35d0cd

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/AndroidClient/.idea/workspace.xml___jb_bak___

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,54 @@
11
package net.servicestack.android;
22

33
import android.app.Application;
4+
import android.graphics.Bitmap;
5+
import android.graphics.BitmapFactory;
46
import android.test.ApplicationTestCase;
57

8+
import net.servicestack.client.AsyncResult;
9+
import net.servicestack.client.Utils;
10+
11+
import java.net.HttpURLConnection;
12+
import java.util.concurrent.CountDownLatch;
13+
import java.util.concurrent.TimeUnit;
14+
615
/**
716
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
817
*/
918
public class ApplicationTest extends ApplicationTestCase<Application> {
1019
public ApplicationTest() {
1120
super(Application.class);
1221
}
22+
23+
AndroidServiceClient client = new AndroidServiceClient("http://techstacks.io");
24+
25+
public void test_Can_download_image_bytes(){
26+
HttpURLConnection httpRes = client.get("https://servicestack.net/img/logo.png");
27+
byte[] imgBytes = Utils.readBytesToEnd(httpRes);
28+
Bitmap img = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
29+
30+
assertEquals(338, img.getWidth());
31+
assertEquals(55, img.getHeight());
32+
}
33+
34+
public void test_Can_download_image_bytes_Async() throws InterruptedException {
35+
final CountDownLatch signal = new CountDownLatch(1);
36+
37+
client.getAsync("https://servicestack.net/img/logo.png", new AsyncResult<byte[]>() {
38+
@Override
39+
public void success(byte[] imgBytes) {
40+
Bitmap img = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
41+
42+
assertEquals(338, img.getWidth());
43+
assertEquals(55, img.getHeight());
44+
}
45+
46+
@Override
47+
public void complete() {
48+
signal.countDown();
49+
}
50+
});
51+
52+
assertTrue(signal.await(5, TimeUnit.SECONDS));
53+
}
1354
}

0 commit comments

Comments
 (0)