1 import org.junit.Assert; 2 import org.junit.Before; 3 import org.junit.Test; 4 import org.junit.runner.RunWith; 5 import org.mockito.InjectMocks; 6 import org.mockito.Mock; 7 import org.mockito.MockitoAnnotations; 8 import org.powermock.api.mockito.PowerMockito; 9 import org.powermock.core.classloader.annotations.PowerMockIgnore; 10 import org.powermock.core.classloader.annotations.PrepareForTest; 11 import org.powermock.modules.junit4.PowerMockRunner; 12 import org.springframework.beans.factory.annotation.Value; 13 14 import java.io.IOException; 15 import java.util.ArrayList; 16 import java.util.Date; 17 import java.util.List; 18 19 import static org.mockito.Matchers.any; 20 21 @RunWith(PowerMockRunner.class) 22 @PrepareForTest({RegistryUtilService.class, ApiContainer.class,HttpUtils.class}) 23 @PowerMockIgnore({"javax.management.*", "javax.script.*", "javax.net.ssl.*"}) 24 public class RealTimeWarningServiceImplTest { 25 26 @InjectMocks 27 RealTimeWarningServiceImpl realTimeWarningService; 28 29 @Mock 30 MybatisQuery mybatisQuery; 31 32 @Value("${request.application.appId}") 33 private String appId; 34 35 @Value("${request.appSecret}") 36 private String appSecret; 37 38 @Mock 39 IPlinkManageService iPlinkManageService; 40 41 @Before 42 public void setUp() { 43 MockitoAnnotations.initMocks(this); 44 } 45 46 @Test 47 public void testQueryWarningTotal() throws IOException { 48 Condition condition = new Condition("123", "20220101", new Region("西欧地区部", "ALL", "ALL")); 49 ApiTemplate template = new ApiTemplate(); 50 template.setUrl("http://apigw.huawei.com/api/data-subject/app_000000035085/D103193"); 51 PowerMockito.mockStatic(ApiContainer.class); 52 PowerMockito.when(ApiContainer.getApiById(ApiType.WARNING_TOTAL.getId())).thenReturn(template); 53 54 String result = "{ \"list\":[{ \"REGION_CN_NAME\":\"西欧地区部\", \"COUNTRY_CN_NAME\":\"西班牙\", \"REPOFFICE_CN_NAME\":\"西班牙代表处\", \"PERIOD_ID\":\"20220101\", \"INDICATOR_NAME\":\"清关超期\", \"PROJ_NUM\":\"null\" },{ \"REGION_CN_NAME\":\"西欧地区部\", \"COUNTRY_CN_NAME\":\"法国\", \"REPOFFICE_CN_NAME\":\"法国代表处\", \"PERIOD_ID\":\"20220101\", \"INDICATOR_NAME\":\"清关超期\", \"PROJ_NUM\":\"56A05VC\" },{ \"REGION_CN_NAME\":\"西欧地区部\", \"COUNTRY_CN_NAME\":\"荷兰\", \"REPOFFICE_CN_NAME\":\"西欧多国管理部\", \"PERIOD_ID\":\"20220101\", \"INDICATOR_NAME\":\"清关超期\", \"PROJ_NUM\":\"null\" }]}\n"; 55 PowerMockito.mockStatic(HttpUtils.class); 56 PowerMockito.when(HttpUtils.postRequest(any(),any(),any())).thenReturn(result); 57 58 realTimeWarningService.queryWarningTotal(condition); 59 } 60 61 @Test 62 public void testQueryDetailsList() { 63 ArrayList<WarningDetailsParam> list = new ArrayList<>(); 64 list.add(new WarningDetailsParam("over_not_received", "56A0EXB")); 65 list.add(new WarningDetailsParam("over_not_received", "56A0ED2")); 66 list.add(new WarningDetailsParam("over_not_accept", "564690E")); 67 list.add(new WarningDetailsParam("over_not_accept", "56A0FU8")); 68 69 PlinkManageResponse response = new PlinkManageResponse(); 70 ArrayList<PlinkManageVo> plinkManageVos = new ArrayList<>(); 71 PlinkManageVo plinkManageVo = new PlinkManageVo(); 72 plinkManageVo.setContent("测试内容"); 73 plinkManageVo.setId("635f35e8bb299b00f1a9fae6"); 74 plinkManageVos.add(plinkManageVo); 75 response.setPlinkManageVoList(plinkManageVos); 76 PowerMockito.when(iPlinkManageService.batchQueryPlinkManageInfo(any())).thenReturn(response); 77 78 List<WarningDetails> details = new ArrayList<>(); 79 details.add(new WarningDetails(null, null, null, null, null, "56A0EXB", "over_not_received", null)); 80 details.add(new WarningDetails(null, null, null, null, null, "56A0ED2", "over_not_received", null)); 81 details.add(new WarningDetails(null, null, null, null, null, "564690E", "over_not_accept", null)); 82 details.add(new WarningDetails(null, null, null, null, null, "56A0FU8", "over_not_accept", null)); 83 84 PowerMockito.when(mybatisQuery.queryTaskLink(any())).thenReturn(details); 85 //{"taskIdList":["632d04ce269432047c9fd9dc"]} 86 List<WarningDetails> warningDetails = realTimeWarningService.queryDetailsList(list); 87 //Assert.assertNotNull(warningDetails); 88 // todo 89 } 90 91 @Test 92 public void testQueryDetails() { 93 WarningDetailsParam warningDetailsParam = new WarningDetailsParam("1", "1"); 94 WarningDetailsCheckList warningDetailsCheckList = realTimeWarningService.queryDetails(warningDetailsParam); 95 //Assert.assertNotNull(warningDetailsCheckList); 96 } 97 98 @Test 99 public void testTrendingWeek() { 100 WaringTrendingParam waringTrendingParam = new WaringTrendingParam("西欧地区部", "", "1", "overdue_not_received", 2); 101 102 List<Trending> trendingList = new ArrayList<>(); 103 trendingList.add(new Trending("0.6",new Date())); 104 PowerMockito.when(mybatisQuery.queryTrending(any(),any(),any(),any())).thenReturn(trendingList); 105 106 List<WarningTrending> warningTrendings = realTimeWarningService.trendingWeek(waringTrendingParam); 107 108 Assert.assertNotNull(warningTrendings); 109 } 110 }
标签:NAME,import,add,org,new,RealTimeWarningServiceImplTest,null From: https://www.cnblogs.com/mingruifeng/p/16874902.html