Skip to content

Commit e19ea56

Browse files
committed
Add more Tests for ServerEventsClient
1 parent c703947 commit e19ea56

File tree

5 files changed

+500
-10
lines changed

5 files changed

+500
-10
lines changed

src/AndroidClient/client/src/main/java/net/servicestack/client/JsonUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.servicestack.client;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
35
import com.google.gson.JsonElement;
46
import com.google.gson.JsonObject;
57
import com.google.gson.JsonParser;
@@ -53,4 +55,12 @@ public static long asLong(JsonObject obj, String key, long defaultValue) {
5355
? val.getAsLong()
5456
: defaultValue;
5557
}
58+
59+
public static Gson getGson(){
60+
return new GsonBuilder().disableHtmlEscaping().create();
61+
}
62+
63+
public static <T> T fromJson(String json, Class<?> cls) {
64+
return (T)getGson().fromJson(json, cls);
65+
}
5666
}

src/AndroidClient/client/src/main/java/net/servicestack/client/Utils.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.io.IOException;
1717
import java.io.InputStream;
1818
import java.io.InputStreamReader;
19+
import java.io.PrintWriter;
20+
import java.io.StringWriter;
1921
import java.io.UnsupportedEncodingException;
2022
import java.lang.annotation.Annotation;
2123
import java.lang.reflect.Field;
@@ -823,12 +825,15 @@ public static String addQueryParam(String url, String key, String value) {
823825
public static String addQueryParam(String url, String key, String val, boolean encode) {
824826
if (url == null || url.length() == 0)
825827
return null;
828+
if (val == null)
829+
val = "";
830+
826831
String prefix = "";
827832
if (!url.endsWith("?") && !url.endsWith("&")) {
828833
prefix = url.indexOf('?') == -1 ? "?" : "&";
829834
}
830835
try {
831-
return url + prefix + key + "=" + (encode && val != null ? URLEncoder.encode(val, "UTF-8") : val);
836+
return url + prefix + key + "=" + (encode ? URLEncoder.encode(val, "UTF-8") : val);
832837
} catch (UnsupportedEncodingException e) {
833838
throw new RuntimeException(e);
834839
}
@@ -883,4 +888,10 @@ public static String join(final Iterator<?> iterator, final String separator) {
883888
}
884889
return buf.toString();
885890
}
891+
892+
public static String getStackTrace(Exception ex) {
893+
StringWriter sw = new StringWriter();
894+
ex.printStackTrace(new PrintWriter(sw));
895+
return sw.toString();
896+
}
886897
}

src/AndroidClient/client/src/main/java/net/servicestack/client/sse/ServerEventCommand.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,15 @@ protected void populate(JsonObject obj) {
6969
if (!Utils.isNullOrEmpty(channels))
7070
this.channels = channels.split(",");
7171
}
72+
73+
@Override
74+
public String toString() {
75+
return "(" + this.getClass().getSimpleName() +
76+
"\n eventId: " + eventId +
77+
"\n userId: " + userId +
78+
"\n displayName: " + displayName +
79+
"\n profileUrl: " + profileUrl +
80+
"\n isAuthenticated: " + isAuthenticated +
81+
"\n channels: " + Utils.join(channels, ",") + "\n)";
82+
}
7283
}
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
/* Options:
2+
Date: 2017-02-11 06:41:16
3+
Version: 4.00
4+
Tip: To override a DTO option, remove "//" prefix before updating
5+
BaseUrl: http://chat.servicestack.net
6+
7+
Package: chat
8+
GlobalNamespace: chatdtos
9+
//AddPropertyAccessors: True
10+
//SettersReturnThis: True
11+
//AddServiceStackTypes: True
12+
//AddResponseStatus: False
13+
//AddDescriptionAsComments: True
14+
//AddImplicitVersion:
15+
//IncludeTypes:
16+
ExcludeTypes: Authenticate,AuthenticateResponse,AssignRoles,AssignRolesResponse,UnAssignRoles,UnAssignRolesResponse
17+
//TreatTypesAsStrings:
18+
//DefaultImports: java.math.*,java.util.*,net.servicestack.client.*,com.google.gson.annotations.*,com.google.gson.reflect.*
19+
*/
20+
21+
package chat;
22+
23+
import java.math.*;
24+
import java.util.*;
25+
import net.servicestack.client.*;
26+
import com.google.gson.annotations.*;
27+
import com.google.gson.reflect.*;
28+
29+
public class chatdtos
30+
{
31+
32+
@Route("/channels/{Channel}/raw")
33+
public static class PostRawToChannel implements IReturnVoid
34+
{
35+
public String from = null;
36+
public String toUserId = null;
37+
public String channel = null;
38+
public String message = null;
39+
public String selector = null;
40+
41+
public String getFrom() { return from; }
42+
public PostRawToChannel setFrom(String value) { this.from = value; return this; }
43+
public String getToUserId() { return toUserId; }
44+
public PostRawToChannel setToUserId(String value) { this.toUserId = value; return this; }
45+
public String getChannel() { return channel; }
46+
public PostRawToChannel setChannel(String value) { this.channel = value; return this; }
47+
public String getMessage() { return message; }
48+
public PostRawToChannel setMessage(String value) { this.message = value; return this; }
49+
public String getSelector() { return selector; }
50+
public PostRawToChannel setSelector(String value) { this.selector = value; return this; }
51+
}
52+
53+
@Route("/channels/{Channel}/chat")
54+
public static class PostChatToChannel implements IReturn<ChatMessage>
55+
{
56+
public String from = null;
57+
public String toUserId = null;
58+
public String channel = null;
59+
public String message = null;
60+
public String selector = null;
61+
62+
public String getFrom() { return from; }
63+
public PostChatToChannel setFrom(String value) { this.from = value; return this; }
64+
public String getToUserId() { return toUserId; }
65+
public PostChatToChannel setToUserId(String value) { this.toUserId = value; return this; }
66+
public String getChannel() { return channel; }
67+
public PostChatToChannel setChannel(String value) { this.channel = value; return this; }
68+
public String getMessage() { return message; }
69+
public PostChatToChannel setMessage(String value) { this.message = value; return this; }
70+
public String getSelector() { return selector; }
71+
public PostChatToChannel setSelector(String value) { this.selector = value; return this; }
72+
private static Object responseType = ChatMessage.class;
73+
public Object getResponseType() { return responseType; }
74+
}
75+
76+
@Route("/chathistory")
77+
public static class GetChatHistory implements IReturn<GetChatHistoryResponse>
78+
{
79+
public ArrayList<String> channels = null;
80+
public Long afterId = null;
81+
public Integer take = null;
82+
83+
public ArrayList<String> getChannels() { return channels; }
84+
public GetChatHistory setChannels(ArrayList<String> value) { this.channels = value; return this; }
85+
public Long getAfterId() { return afterId; }
86+
public GetChatHistory setAfterId(Long value) { this.afterId = value; return this; }
87+
public Integer getTake() { return take; }
88+
public GetChatHistory setTake(Integer value) { this.take = value; return this; }
89+
private static Object responseType = GetChatHistoryResponse.class;
90+
public Object getResponseType() { return responseType; }
91+
}
92+
93+
@Route("/reset")
94+
public static class ClearChatHistory implements IReturnVoid
95+
{
96+
97+
}
98+
99+
@Route("/account")
100+
public static class GetUserDetails implements IReturn<GetUserDetailsResponse>
101+
{
102+
103+
private static Object responseType = GetUserDetailsResponse.class;
104+
public Object getResponseType() { return responseType; }
105+
}
106+
107+
public static class ChatMessage
108+
{
109+
public Long id = null;
110+
public String channel = null;
111+
public String fromUserId = null;
112+
public String fromName = null;
113+
public String displayName = null;
114+
public String message = null;
115+
public String userAuthId = null;
116+
@SerializedName("private") public Boolean Private = null;
117+
118+
public Long getId() { return id; }
119+
public ChatMessage setId(Long value) { this.id = value; return this; }
120+
public String getChannel() { return channel; }
121+
public ChatMessage setChannel(String value) { this.channel = value; return this; }
122+
public String getFromUserId() { return fromUserId; }
123+
public ChatMessage setFromUserId(String value) { this.fromUserId = value; return this; }
124+
public String getFromName() { return fromName; }
125+
public ChatMessage setFromName(String value) { this.fromName = value; return this; }
126+
public String getDisplayName() { return displayName; }
127+
public ChatMessage setDisplayName(String value) { this.displayName = value; return this; }
128+
public String getMessage() { return message; }
129+
public ChatMessage setMessage(String value) { this.message = value; return this; }
130+
public String getUserAuthId() { return userAuthId; }
131+
public ChatMessage setUserAuthId(String value) { this.userAuthId = value; return this; }
132+
public Boolean isPrivate() { return Private; }
133+
public ChatMessage setPrivate(Boolean value) { this.Private = value; return this; }
134+
}
135+
136+
public static class GetChatHistoryResponse
137+
{
138+
public ArrayList<ChatMessage> results = null;
139+
public ResponseStatus responseStatus = null;
140+
141+
public ArrayList<ChatMessage> getResults() { return results; }
142+
public GetChatHistoryResponse setResults(ArrayList<ChatMessage> value) { this.results = value; return this; }
143+
public ResponseStatus getResponseStatus() { return responseStatus; }
144+
public GetChatHistoryResponse setResponseStatus(ResponseStatus value) { this.responseStatus = value; return this; }
145+
}
146+
147+
public static class GetUserDetailsResponse
148+
{
149+
public String provider = null;
150+
public String userId = null;
151+
public String userName = null;
152+
public String fullName = null;
153+
public String displayName = null;
154+
public String firstName = null;
155+
public String lastName = null;
156+
public String company = null;
157+
public String email = null;
158+
public String phoneNumber = null;
159+
public Date birthDate = null;
160+
public String birthDateRaw = null;
161+
public String address = null;
162+
public String address2 = null;
163+
public String city = null;
164+
public String state = null;
165+
public String country = null;
166+
public String culture = null;
167+
public String gender = null;
168+
public String language = null;
169+
public String mailAddress = null;
170+
public String nickname = null;
171+
public String postalCode = null;
172+
public String timeZone = null;
173+
174+
public String getProvider() { return provider; }
175+
public GetUserDetailsResponse setProvider(String value) { this.provider = value; return this; }
176+
public String getUserId() { return userId; }
177+
public GetUserDetailsResponse setUserId(String value) { this.userId = value; return this; }
178+
public String getUserName() { return userName; }
179+
public GetUserDetailsResponse setUserName(String value) { this.userName = value; return this; }
180+
public String getFullName() { return fullName; }
181+
public GetUserDetailsResponse setFullName(String value) { this.fullName = value; return this; }
182+
public String getDisplayName() { return displayName; }
183+
public GetUserDetailsResponse setDisplayName(String value) { this.displayName = value; return this; }
184+
public String getFirstName() { return firstName; }
185+
public GetUserDetailsResponse setFirstName(String value) { this.firstName = value; return this; }
186+
public String getLastName() { return lastName; }
187+
public GetUserDetailsResponse setLastName(String value) { this.lastName = value; return this; }
188+
public String getCompany() { return company; }
189+
public GetUserDetailsResponse setCompany(String value) { this.company = value; return this; }
190+
public String getEmail() { return email; }
191+
public GetUserDetailsResponse setEmail(String value) { this.email = value; return this; }
192+
public String getPhoneNumber() { return phoneNumber; }
193+
public GetUserDetailsResponse setPhoneNumber(String value) { this.phoneNumber = value; return this; }
194+
public Date getBirthDate() { return birthDate; }
195+
public GetUserDetailsResponse setBirthDate(Date value) { this.birthDate = value; return this; }
196+
public String getBirthDateRaw() { return birthDateRaw; }
197+
public GetUserDetailsResponse setBirthDateRaw(String value) { this.birthDateRaw = value; return this; }
198+
public String getAddress() { return address; }
199+
public GetUserDetailsResponse setAddress(String value) { this.address = value; return this; }
200+
public String getAddress2() { return address2; }
201+
public GetUserDetailsResponse setAddress2(String value) { this.address2 = value; return this; }
202+
public String getCity() { return city; }
203+
public GetUserDetailsResponse setCity(String value) { this.city = value; return this; }
204+
public String getState() { return state; }
205+
public GetUserDetailsResponse setState(String value) { this.state = value; return this; }
206+
public String getCountry() { return country; }
207+
public GetUserDetailsResponse setCountry(String value) { this.country = value; return this; }
208+
public String getCulture() { return culture; }
209+
public GetUserDetailsResponse setCulture(String value) { this.culture = value; return this; }
210+
public String getGender() { return gender; }
211+
public GetUserDetailsResponse setGender(String value) { this.gender = value; return this; }
212+
public String getLanguage() { return language; }
213+
public GetUserDetailsResponse setLanguage(String value) { this.language = value; return this; }
214+
public String getMailAddress() { return mailAddress; }
215+
public GetUserDetailsResponse setMailAddress(String value) { this.mailAddress = value; return this; }
216+
public String getNickname() { return nickname; }
217+
public GetUserDetailsResponse setNickname(String value) { this.nickname = value; return this; }
218+
public String getPostalCode() { return postalCode; }
219+
public GetUserDetailsResponse setPostalCode(String value) { this.postalCode = value; return this; }
220+
public String getTimeZone() { return timeZone; }
221+
public GetUserDetailsResponse setTimeZone(String value) { this.timeZone = value; return this; }
222+
}
223+
224+
}

0 commit comments

Comments
 (0)