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
51 lines (39 loc) · 1.39 KB
/
PubNubExceptionTest.java
File metadata and controls
51 lines (39 loc) · 1.39 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
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.pubnub.api.PubNub;
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();
wireMockRule.start();
}
@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;
try {
instance.channel("coolChannel").message(new Object()).sync();
}
catch (PubNubException error) {
statusCode = error.getStatusCode();
}
assertEquals(0, statusCode);
}
}