ProbeDetailQueryServiceImplTest

  1 import org.apache.commons.io.FileUtils;
  2 import org.junit.Assert;
  3 import org.junit.Before;
  4 import org.junit.BeforeClass;
  5 import org.junit.Test;
  6 import org.mockito.InjectMocks;
  7 import org.mockito.Mock;
  8 import org.mockito.MockitoAnnotations;
  9 import org.slf4j.Logger;
 10 import org.springframework.util.ResourceUtils;
 11 import java.io.File;
 12 import java.io.IOException;
 13 import java.nio.charset.StandardCharsets;
 14 import java.util.Arrays;
 15 import static org.mockito.Mockito.*;
 16 
 17 public class ProbeDetailQueryServiceImplTest {
 18 
 19     private static final String TEST_DATA = "classpath:data/request/ProbeDetailQuery.req.json";
 20     private static final String QUERYTABLEDETAIL_REQ = "classpath:data/request/probeDetail.queryTableDetail.req.json";
 21 
 22     private static Condition condition;
 23     private static Condition condition4;
 24 
 25     @Mock
 26     HttpConfig httpConfig;
 27     @Mock
 28     MybatisQuery mybatisQuery;
 29     @Mock
 30     Logger log;
 31     @Mock
 32     HttpUtils httpUtils;
 33     @InjectMocks
 34     ProbeDetailQueryServiceImpl probeDetailQueryServiceImpl;
 35 
 36     @BeforeClass
 37     public static void init() throws IOException {
 38         File testFile = ResourceUtils.getFile(TEST_DATA);
 39         String testJson = FileUtils.readFileToString(testFile, StandardCharsets.UTF_8);
 40         condition = JsonUtil.stringToObject(testJson, Condition.class);
 41 
 42         File testFile4 = ResourceUtils.getFile(QUERYTABLEDETAIL_REQ);
 43         String testJson4 = FileUtils.readFileToString(testFile4, StandardCharsets.UTF_8);
 44         condition4 = JsonUtil.stringToObject(testJson4, Condition.class);
 45     }
 46 
 47     @Before
 48     public void setUp() {
 49         MockitoAnnotations.initMocks(this);
 50     }
 51 
 52     @Test
 53     public void testQueryTargetAttainment() throws Exception {
 54         when(httpConfig.getTargetAttainmentNotReceived()).thenReturn(
 55             "http://apigw.huawei.com/api/data-subject/app_000000035085/D103024");
 56         when(httpConfig.getTargetAttainmentNotCheck()).thenReturn(
 57             "http://apigw.huawei.com/api/data-subject/app_000000035085/D103165");
 58         when(httpConfig.getAppId()).thenReturn("app_000000035085");
 59         when(httpConfig.getAppSecret()).thenReturn("czyImZk1LvPcP+m+BgmyzA==");
 60         when(mybatisQuery.getProbeInfo(any())).thenReturn(Arrays.<ProbeInfo>asList(
 61             new ProbeInfo("0.2", "0.6", "7", "20221102", "regionCnName", "repoffceCnName", "countryCnName",
 62                 "probeId")));
 63         TargetAttainment result = probeDetailQueryServiceImpl.queryTargetAttainment(condition);
 64         Assert.assertNotNull(result);
 65     }
 66 
 67     @Test
 68     public void testQueryAchievementTrend() throws Exception {
 69         when(httpConfig.getAchievementTrendNotReceived()).thenReturn(
 70             "http://apigw.huawei.com/api/data-subject/app_000000035085/D103198");
 71         when(httpConfig.getAchievementTrendNotCheck()).thenReturn(
 72             "http://apigw.huawei.com/api/data-subject/app_000000035085/D103165");
 73         when(httpConfig.getAppId()).thenReturn("app_000000035085");
 74         when(httpConfig.getAppSecret()).thenReturn("czyImZk1LvPcP+m+BgmyzA==");
 75         when(mybatisQuery.getProbeInfo(any())).thenReturn(Arrays.<ProbeInfo>asList(
 76             new ProbeInfo("0.2", "0.6", "7", "20221102", "regionCnName", "repoffceCnName", "countryCnName",
 77                 "probeId")));
 78         BasicChart result = probeDetailQueryServiceImpl.queryAchievementTrend(condition);
 79         Assert.assertNotNull(result);
 80     }
 81 
 82     @Test
 83     public void testQueryDistribution() throws Exception {
 84         when(httpConfig.getDistributionNotReceived()).thenReturn(
 85             "http://apigw.huawei.com/api/data-subject/app_000000035085/D103199");
 86         when(httpConfig.getDistributionNotCheck()).thenReturn(
 87             "http://apigw.huawei.com/api/data-subject/app_000000035085/D103200");
 88         when(httpConfig.getAppId()).thenReturn("app_000000035085");
 89         when(httpConfig.getAppSecret()).thenReturn("czyImZk1LvPcP+m+BgmyzA==");
 90         when(mybatisQuery.getProbeInfo(any())).thenReturn(Arrays.<ProbeInfo>asList(
 91             new ProbeInfo("0.2", "0.6", "7", "20221102", "regionCnName", "repoffceCnName", "countryCnName",
 92                 "probeId")));
 93         Distribution result = probeDetailQueryServiceImpl.queryDistribution(condition);
 94         Assert.assertNotNull(result);
 95     }
 96 
 97     @Test
 98     public void testQueryTableDetail() throws IOException {
 99         TableDetail tableDetail = probeDetailQueryServiceImpl.queryTableDetail(condition4);
100         Assert.assertNotNull(tableDetail);
101     }
102 
103 }

 

posted @ 2022-11-08 20:58  MING5135  阅读(32)  评论(0)    收藏  举报