|
7 | 7 | */
|
8 | 8 | package com.opentok.test;
|
9 | 9 |
|
| 10 | +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 11 | +import static com.github.tomakehurst.wiremock.client.WireMock.any; |
| 12 | +import static com.github.tomakehurst.wiremock.client.WireMock.delete; |
| 13 | +import static com.github.tomakehurst.wiremock.client.WireMock.deleteRequestedFor; |
| 14 | +import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 15 | +import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; |
| 16 | +import static com.github.tomakehurst.wiremock.client.WireMock.matching; |
| 17 | +import static com.github.tomakehurst.wiremock.client.WireMock.post; |
| 18 | +import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; |
| 19 | +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; |
| 20 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; |
| 21 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; |
| 22 | +import static com.github.tomakehurst.wiremock.client.WireMock.verify; |
| 23 | +import static org.hamcrest.CoreMatchers.instanceOf; |
| 24 | +import static org.junit.Assert.assertEquals; |
| 25 | +import static org.junit.Assert.assertNotNull; |
| 26 | +import static org.junit.Assert.assertNull; |
| 27 | +import static org.junit.Assert.assertThat; |
| 28 | +import static org.junit.Assert.assertTrue; |
| 29 | + |
10 | 30 | import java.io.UnsupportedEncodingException;
|
| 31 | +import java.net.InetAddress; |
| 32 | +import java.net.InetSocketAddress; |
| 33 | +import java.net.Proxy; |
| 34 | +import java.net.UnknownHostException; |
11 | 35 | import java.security.InvalidKeyException;
|
12 | 36 | import java.security.NoSuchAlgorithmException;
|
13 | 37 | import java.security.SignatureException;
|
14 | 38 | import java.util.ArrayList;
|
15 | 39 | import java.util.Map;
|
16 | 40 |
|
17 |
| -import com.opentok.*; |
18 |
| -import com.opentok.Archive.OutputMode; |
19 |
| - |
20 | 41 | import org.apache.commons.lang.StringUtils;
|
21 |
| - |
22 |
| -import com.opentok.constants.Version; |
23 |
| -import com.opentok.exception.OpenTokException; |
24 |
| -import com.opentok.exception.InvalidArgumentException; |
25 |
| - |
26 | 42 | import org.junit.Before;
|
27 | 43 | import org.junit.Rule;
|
28 | 44 | import org.junit.Test;
|
29 | 45 |
|
30 |
| -import static org.junit.Assert.*; |
31 |
| -import static org.hamcrest.CoreMatchers.*; |
32 |
| -import static com.github.tomakehurst.wiremock.client.WireMock.*; |
33 |
| - |
| 46 | +import com.github.tomakehurst.wiremock.WireMockServer; |
| 47 | +import com.github.tomakehurst.wiremock.client.RequestPatternBuilder; |
| 48 | +import com.github.tomakehurst.wiremock.client.WireMock; |
| 49 | +import com.github.tomakehurst.wiremock.common.ProxySettings; |
| 50 | +import com.github.tomakehurst.wiremock.core.WireMockConfiguration; |
34 | 51 | import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
| 52 | +import com.opentok.Archive; |
| 53 | +import com.opentok.Archive.OutputMode; |
| 54 | +import com.opentok.constants.Version; |
| 55 | +import com.opentok.ArchiveList; |
| 56 | +import com.opentok.ArchiveMode; |
| 57 | +import com.opentok.ArchiveProperties; |
| 58 | +import com.opentok.MediaMode; |
| 59 | +import com.opentok.OpenTok; |
| 60 | +import com.opentok.Role; |
| 61 | +import com.opentok.Session; |
| 62 | +import com.opentok.SessionProperties; |
| 63 | +import com.opentok.TokenOptions; |
| 64 | +import com.opentok.exception.InvalidArgumentException; |
| 65 | +import com.opentok.exception.OpenTokException; |
35 | 66 |
|
36 | 67 | public class OpenTokTest {
|
37 | 68 |
|
@@ -820,5 +851,44 @@ public void testDeleteArchive() throws OpenTokException {
|
820 | 851 |
|
821 | 852 | assertNotNull(archive);
|
822 | 853 | }
|
| 854 | + |
| 855 | + @Test |
| 856 | + public void testCreateSessionWithProxy() throws OpenTokException, UnknownHostException { |
| 857 | + WireMockConfiguration proxyConfig = WireMockConfiguration.wireMockConfig(); |
| 858 | + proxyConfig.dynamicPort(); |
| 859 | + WireMockServer proxyingService = new WireMockServer(proxyConfig); |
| 860 | + proxyingService.start(); |
| 861 | + WireMock proxyingServiceAdmin = new WireMock(proxyingService.port()); |
| 862 | + |
| 863 | + String targetServiceBaseUrl = "http://localhost:" + wireMockRule.port(); |
| 864 | + proxyingServiceAdmin.register(any(urlMatching(".*")).atPriority(10) |
| 865 | + .willReturn(aResponse() |
| 866 | + .proxiedFrom(targetServiceBaseUrl))); |
| 867 | + |
| 868 | + String sessionId = "SESSIONID"; |
| 869 | + Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getLocalHost(), proxyingService.port())); |
| 870 | + |
| 871 | + sdk = new OpenTok(apiKey, apiSecret, apiUrl, proxy); |
| 872 | + stubFor(post(urlEqualTo("/session/create")) |
| 873 | + .willReturn(aResponse() |
| 874 | + .withStatus(200) |
| 875 | + .withHeader("Content-Type", "text/xml") |
| 876 | + .withBody("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><sessions><Session><" + |
| 877 | + "session_id>" + sessionId + "</session_id><partner_id>123456</partner_id><create_dt>" + |
| 878 | + "Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>") |
| 879 | + )); |
| 880 | + |
| 881 | + Session session = sdk.createSession(); |
| 882 | + |
| 883 | + assertNotNull(session); |
| 884 | + assertEquals(this.apiKey, session.getApiKey()); |
| 885 | + assertEquals(sessionId, session.getSessionId()); |
| 886 | + |
| 887 | + verify(postRequestedFor(urlMatching("/session/create"))); |
| 888 | + |
| 889 | + Helpers.verifyPartnerAuth(this.apiKey, this.apiSecret); |
| 890 | + Helpers.verifyUserAgent(); |
| 891 | + |
| 892 | + } |
823 | 893 |
|
824 | 894 | }
|
0 commit comments