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
53 lines (40 loc) · 1.47 KB
/
Copy pathPubNubExceptionTest.java
File metadata and controls
53 lines (40 loc) · 1.47 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
package com.pubnub.api;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.pubnub.api.endpoints.TestHarness;
import com.pubnub.api.endpoints.pubsub.Publish;
import org.junit.After;
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 com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.Assert.assertEquals;
public class PubNubExceptionTest extends TestHarness {
@Rule
public WireMockRule wireMockRule = new WireMockRule(options().port(this.PORT), false);
private Publish instance;
@Before
public void beforeEach() throws IOException, PubNubException {
PubNub pubnub = this.createPubNubInstance();
instance = pubnub.publish();
wireMockRule.start();
}
@After
public void cleanup() {
instance = null;
wireMockRule.stop();
}
@Test
public void testPubnubError() {
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("hi").sync();
} catch (PubNubException error) {
statusCode = error.getStatusCode();
}
assertEquals(404, statusCode);
}
}