MessageHandlerTest.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.inspur.customer;
  2. import com.inspur.customer.object.inform.CommonMessageCO;
  3. import com.inspur.customer.service.inform.handler.EmailMessageHandler;
  4. import com.inspur.customer.service.inform.handler.WeChatAppletMessageHandler;
  5. import com.inspur.customer.service.inform.handler.WeChatMessageHandler;
  6. import com.inspur.inform.object.applet.WeChatAppletUserDataDto;
  7. import com.inspur.inform.object.applet.message.WxAppletUserMessageDto;
  8. import com.inspur.inform.object.message.EmailMessage;
  9. import com.inspur.inform.object.message.WechatMessage;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.junit.jupiter.api.Test;
  12. import java.io.IOException;
  13. import java.util.BitSet;
  14. import java.util.Collections;
  15. import java.util.HashMap;
  16. import java.util.Map;
  17. /**
  18. * @author linwenhua
  19. * @date 2022-07-01 13:56
  20. **/
  21. @Slf4j
  22. class MessageHandlerTest {
  23. private final EmailMessageHandler emailMessageHandler = new EmailMessageHandler();
  24. private final WeChatAppletMessageHandler weChatAppletMessageHandler = new WeChatAppletMessageHandler();
  25. private final WeChatMessageHandler weChatMessageHandler = new WeChatMessageHandler();
  26. @Test
  27. void testEmail() throws IOException {
  28. CommonMessageCO commonMessageCo = new CommonMessageCO();
  29. commonMessageCo.setSubject("测试");
  30. Map<String, String> attributes = new HashMap<>(10);
  31. attributes.put("MSRlevel", "紧急");
  32. attributes.put("MSRdevice", "紧急");
  33. attributes.put("MSRarea", "紧急");
  34. attributes.put("MSRtime", "紧急");
  35. commonMessageCo.setMessageMap(attributes);
  36. EmailMessage emailMessage = emailMessageHandler.makeEmailMessage(commonMessageCo, "BatchDeviceEmptyOrchestration", Collections.emptyList());
  37. log.info("message: {}", emailMessage);
  38. }
  39. @Test
  40. void testApplet() throws IOException {
  41. CommonMessageCO commonMessageCo = new CommonMessageCO();
  42. commonMessageCo.setSubject("测试");
  43. Map<String, String> attributes = new HashMap<>(10);
  44. attributes.put("MSRlevel", "紧急");
  45. attributes.put("MSRdevice", "紧急");
  46. attributes.put("MSRarea", "紧急");
  47. attributes.put("MSRtime", "紧急");
  48. commonMessageCo.setMessageMap(attributes);
  49. WxAppletUserMessageDto wxAppletUserMessageDto = weChatAppletMessageHandler.makeWeChatAppletMessage(commonMessageCo, "MultiWarn");
  50. log.info("message: {}", wxAppletUserMessageDto);
  51. }
  52. @Test
  53. void testWeChat() throws IOException {
  54. CommonMessageCO commonMessageCo = new CommonMessageCO();
  55. commonMessageCo.setSubject("测试");
  56. Map<String, String> attributes = new HashMap<>(10);
  57. attributes.put("keyword1", "紧急");
  58. attributes.put("keyword3", "紧急");
  59. commonMessageCo.setMessageMap(attributes);
  60. WechatMessage wechatMessage = weChatMessageHandler.makeWeChatMessage(commonMessageCo, Collections.emptyList(), "device");
  61. log.info("message: {}", wechatMessage);
  62. }
  63. @Test
  64. void testBitset() {
  65. BitSet bitSet = new BitSet(4);
  66. bitSet.set(2);
  67. log.info("size: {}", bitSet.length());
  68. }
  69. }