Skip to content

Commit 0af7a6d

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 47952fb + 567a361 commit 0af7a6d

File tree

4 files changed

+1927
-1
lines changed

4 files changed

+1927
-1
lines changed

src/AndroidClient/.idea/workspace.xml___jb_bak___

Whitespace-only changes.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,84 @@
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 com.google.gson.annotations.SerializedName;
9+
10+
import net.servicestack.client.AsyncResult;
11+
import net.servicestack.client.Flags;
12+
import net.servicestack.client.Utils;
13+
14+
import java.net.HttpURLConnection;
15+
import java.util.concurrent.CountDownLatch;
16+
import java.util.concurrent.TimeUnit;
17+
618
/**
719
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
820
*/
921
public class ApplicationTest extends ApplicationTestCase<Application> {
1022
public ApplicationTest() {
1123
super(Application.class);
1224
}
25+
26+
AndroidServiceClient client = new AndroidServiceClient("http://techstacks.io");
27+
28+
public void test_Can_download_image_bytes(){
29+
HttpURLConnection httpRes = client.get("https://servicestack.net/img/logo.png");
30+
byte[] imgBytes = Utils.readBytesToEnd(httpRes);
31+
Bitmap img = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
32+
33+
assertEquals(338, img.getWidth());
34+
assertEquals(55, img.getHeight());
35+
}
36+
37+
public void test_Can_download_image_bytes_Async() throws InterruptedException {
38+
final CountDownLatch signal = new CountDownLatch(1);
39+
40+
client.getAsync("https://servicestack.net/img/logo.png", new AsyncResult<byte[]>() {
41+
@Override
42+
public void success(byte[] imgBytes) {
43+
Bitmap img = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
44+
45+
assertEquals(338, img.getWidth());
46+
assertEquals(55, img.getHeight());
47+
}
48+
49+
@Override
50+
public void complete() {
51+
signal.countDown();
52+
}
53+
});
54+
55+
assertTrue(signal.await(5, TimeUnit.SECONDS));
56+
}
57+
58+
public void test_Can_deserialize_enum_flags(){
59+
EnumTest o = client.getGson().fromJson("{\"Flags\":2}", EnumTest.class);
60+
61+
assertEquals(o.Flags, EnumFlags.Value2);
62+
63+
o = client.getGson().fromJson("{\"Flags\":4}", EnumTest.class);
64+
assertEquals(o.Flags, EnumFlags.Value3);
65+
}
66+
67+
public static class EnumTest
68+
{
69+
public EnumFlags Flags;
70+
}
71+
72+
@Flags()
73+
public static enum EnumFlags
74+
{
75+
@SerializedName("1") Value1(1),
76+
@SerializedName("2") Value2(2),
77+
@SerializedName("4") Value3(4);
78+
79+
private final int value;
80+
EnumFlags(final int intValue) { value = intValue; }
81+
public int getValue() { return value; }
82+
}
83+
1384
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy