forked from ringcentral/ringcentral-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RestClientTest.java
42 lines (35 loc) · 1.57 KB
/
RestClientTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.ringcentral;
import com.ringcentral.definitions.CreateSMSMessage;
import com.ringcentral.definitions.MessageStoreCallerInfoRequest;
import com.ringcentral.definitions.VersionInfo;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.*;
public class RestClientTest extends BaseTest {
@Test
public void testGet() throws IOException, RestException {
VersionInfo versionInfo = restClient.get("/restapi/v1.0", VersionInfo.class);
assertEquals("v1.0", versionInfo.uriString);
}
@Test
public void testPost() throws IOException, RestException {
CreateSMSMessage postParameters = new CreateSMSMessage();
postParameters.from = new MessageStoreCallerInfoRequest().phoneNumber(config.get("username"));
postParameters.to = new MessageStoreCallerInfoRequest[]{new MessageStoreCallerInfoRequest().phoneNumber(config.get("receiver"))};
postParameters.text = "hello world";
String result = restClient.post("/restapi/v1.0/account/~/extension/~/sms", postParameters).string();
assertEquals(true, result.contains("hello world"));
}
@Test
public void testRestException() {
try {
restClient.get("/restapi/v1.0/account/~/invalid-url");
fail("Expected RestException was not thrown");
} catch (RestException e) {
assertTrue(e.getMessage().contains("HTTP status code: 404"));
assertEquals(404, e.getHttpStatusCode());
} catch (IOException e) {
fail("Unexpected IOException was thrown");
}
}
}