Commit 15cd9681 authored by huangcb's avatar huangcb

调整推送返回

parent 9db856f7
...@@ -50,7 +50,9 @@ public class PushController { ...@@ -50,7 +50,9 @@ public class PushController {
data.put("msgId", pushResult.getMsgId()); data.put("msgId", pushResult.getMsgId());
return EResponse.ok(data); return EResponse.ok(data);
} else { } else {
return EResponse.error(pushResult.getCode(), pushResult.getMessage()); StringBuffer sb = new StringBuffer();
sb.append("[").append(pushResult.getCode()).append("]").append(pushResult.getMessage());
return EResponse.error(1001, sb.toString());
} }
} }
} }
...@@ -75,4 +75,42 @@ public class PushControllerTest extends BaseTestController { ...@@ -75,4 +75,42 @@ public class PushControllerTest extends BaseTestController {
Assert.assertEquals(ECode.SUCCESS.code(), result.getIntValue("code")); Assert.assertEquals(ECode.SUCCESS.code(), result.getIntValue("code"));
Assert.assertTrue(result.getJSONObject("data").containsKey("msgId")); Assert.assertTrue(result.getJSONObject("data").containsKey("msgId"));
} }
/**
* 给指定设备推送消息:错误的设备ID
**/
@Test
public void a2_push2Device_wrong_registrationId_failure_test() throws Exception {
String url = "/message/push2Device";
// 构造数据
DevicePushForm form = new DevicePushForm();
form.setAppType(1); // APP类型:1-货主、2-司机
form.setDeviceType(1); // 设备类型:1-android、2-ios
form.setRegistrationId("18071adc038dfcf8abx");
// 设置自定义消息[message]
JSONObject message = new JSONObject();
message.put("msg_content", "这是一条测试消息-" + System.currentTimeMillis());
message.put("title", "测试消息标题-" + System.currentTimeMillis());
message.put("content_type", "text");
JSONObject extras = new JSONObject();
extras.put("messageType", 0);
extras.put("data", new JSONObject());
message.put("extras", extras);
form.setMessage(message);
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.content(form.toString()))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String responseStr = mvcResult.getResponse().getContentAsString();
log.info(responseStr);
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertNotEquals(ECode.SUCCESS.code(), result.getIntValue("code"));
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment