forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPubNubExceptionTest.java
More file actions
71 lines (58 loc) · 2.2 KB
/
PubNubExceptionTest.java
File metadata and controls
71 lines (58 loc) · 2.2 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import com.fasterxml.jackson.databind.JsonNode;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.pubnub.api.PubNub;
import com.pubnub.api.PubNubError;
import com.pubnub.api.PubNubException;
import com.pubnub.api.endpoints.TestHarness;
import com.pubnub.api.endpoints.pubsub.Publish;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.io.IOException;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.Assert.assertEquals;
/**
* Created by tukunare on 7/5/2016.
*/
public class PubNubExceptionTest extends TestHarness {
@Rule
public WireMockRule wireMockRule = new WireMockRule();
private PubNub pubnub;
private Publish instance;
@Before
public void beforeEach() throws IOException {
pubnub = this.createPubNubInstance(8080);
instance = pubnub.publish();
}
@Test
public void testPubnubError() throws PubNubException, InterruptedException {
stubFor(get(urlPathEqualTo("/publish/myPublishKey/mySubscribeKey/0/coolChannel/0/%22hi%22"))
.willReturn(aResponse().withStatus(404).withBody("[1,\"Sent\",\"14598111595318003\"]")));
int statusCode = -1;
PubNubError pubnubError = null;
int pnErrorCode= - 1;
int pnErroCodeExtended = -1;
JsonNode pnErrorJNode = null;
String pnErrorMessage = null;
String pnErrorString = null;
String response = null;
String erroMsg = null;
JsonNode jNode = null;
try {
instance.channel("coolChannel").message(new Object()).sync();
}
catch (PubNubException error) {
statusCode = error.getStatusCode();
pubnubError = error.getPubnubError();
pnErrorCode = pubnubError.getErrorCode();
pnErroCodeExtended = pubnubError.getErrorCodeExtended();
pnErrorJNode = pubnubError.getErrorObject();
pnErrorMessage = pubnubError.getMessage();
pnErrorString = pubnubError.getErrorString();
response = error.getResponse();
erroMsg = error.getErrormsg();
jNode = error.getJso();
}
assertEquals(0, statusCode);
}
}