|
| 1 | +package cn.jpush.api.push.mock; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.net.URL; |
| 5 | + |
| 6 | +import org.junit.After; |
| 7 | +import org.junit.AfterClass; |
| 8 | +import org.junit.BeforeClass; |
| 9 | + |
| 10 | +import cn.jpush.api.push.PushClient; |
| 11 | + |
| 12 | +import com.google.gson.JsonObject; |
| 13 | +import com.google.gson.JsonPrimitive; |
| 14 | +import com.squareup.okhttp.mockwebserver.MockWebServer; |
| 15 | + |
| 16 | +public class BaseMockTests { |
| 17 | + public static final String REMOTE_HOST = "https://localhost:8081"; |
| 18 | + public static final String REMOTE_PATH = "/v3/push"; |
| 19 | + |
| 20 | + public static final String appKey ="dd1066407b044738b6479275"; |
| 21 | + public static final String masterSecret = "2b38ce69b1de2a7fa95706ea"; |
| 22 | + |
| 23 | + public static final String CONTENT_TYPE_JSON = "application/json"; |
| 24 | + |
| 25 | + public static final int SUCCEED_RESULT_CODE = 0; |
| 26 | + public static final int LACK_OF_PARAMS = 1002; |
| 27 | + public static final int INVALID_PARAMS = 1003; |
| 28 | + public static final int AUTHENTICATION_FAIL = 1004; |
| 29 | + public static final int TOO_BIG = 1005; |
| 30 | + public static final int APPKEY_NOT_EXIST = 1008; |
| 31 | + |
| 32 | + public static final String ALERT = "JPush Test - alert"; |
| 33 | + public static final String MSG_CONTENT = "JPush Test - msgContent"; |
| 34 | + |
| 35 | + public static final String TAG1 = "tag1"; |
| 36 | + public static final String TAG2 = "tag2"; |
| 37 | + public static final String TAG_ALL = "tag_all"; |
| 38 | + public static final String TAG_NO = "tag_no"; |
| 39 | + public static final String ALIAS1 = "alias1"; |
| 40 | + public static final String ALIAS2 = "alias2"; |
| 41 | + public static final String ALIAS_NO = "alias_no"; |
| 42 | + public static final String REGISTRATION_ID1 = "0900e8d85ef"; |
| 43 | + public static final String REGISTRATION_ID2 = "0a04ad7d8b4"; |
| 44 | + |
| 45 | + protected static PushClient _client = null; |
| 46 | + protected static MockWebServer _mockServer = null; |
| 47 | + protected static URL _mockUrl = null; |
| 48 | + |
| 49 | + @After |
| 50 | + public void after() { |
| 51 | + // validate input params |
| 52 | + |
| 53 | + } |
| 54 | + |
| 55 | + @BeforeClass |
| 56 | + public static void beforeClass() throws IOException { |
| 57 | + _mockServer = new MockWebServer(); |
| 58 | + |
| 59 | + _mockServer.play(); |
| 60 | + _mockUrl = _mockServer.getUrl("/v3/push/"); |
| 61 | + |
| 62 | + _client = new PushClient(masterSecret, appKey); |
| 63 | + _client.setBaseUrl(_mockUrl.toString()); |
| 64 | + } |
| 65 | + |
| 66 | + @AfterClass |
| 67 | + public static void afterClass() throws IOException { |
| 68 | + _mockServer.shutdown(); |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + protected String getResponseOK(int msgid, int sendno) { |
| 73 | + JsonObject json = new JsonObject(); |
| 74 | + json.add("msg_id", new JsonPrimitive(msgid)); |
| 75 | + json.add("sendno", new JsonPrimitive(sendno)); |
| 76 | + return json.toString(); |
| 77 | + } |
| 78 | + |
| 79 | + protected String getResponseError(int msgid, int sendno, int errorCode, String errorMessage) { |
| 80 | + JsonObject json = new JsonObject(); |
| 81 | + json.add("msg_id", new JsonPrimitive(msgid)); |
| 82 | + json.add("sendno", new JsonPrimitive(sendno)); |
| 83 | + |
| 84 | + JsonObject error = new JsonObject(); |
| 85 | + error.add("code", new JsonPrimitive(errorCode)); |
| 86 | + error.add("message", new JsonPrimitive(errorMessage)); |
| 87 | + |
| 88 | + json.add("error", error); |
| 89 | + return json.toString(); |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +} |
| 95 | + |
0 commit comments