Add license header for java files
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / health / ApiRouteHealthCheckTest.java
1 /*******************************************************************************
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at 
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 package org.onap.msb.apiroute.health;
17
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mockito;
21 import org.onap.msb.apiroute.health.ApiRouteHealthCheck;
22 import org.onap.msb.apiroute.wrapper.util.HttpClientUtil;
23 import org.powermock.api.mockito.PowerMockito;
24 import org.powermock.core.classloader.annotations.PrepareForTest;
25 import org.powermock.modules.junit4.PowerMockRunner;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import com.codahale.metrics.health.HealthCheck.Result;
30
31 @RunWith(PowerMockRunner.class)
32 @PrepareForTest({ HttpClientUtil.class })
33 public class ApiRouteHealthCheckTest {
34         private static final Logger LOGGER = LoggerFactory
35                         .getLogger(ApiRouteHealthCheckTest.class);
36         
37         @Test
38         public void testchecksuccess()
39         {
40                 PowerMockito.mockStatic(HttpClientUtil.class);
41                 try {
42                         
43                         PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(200);
44                 } catch (Exception e) {
45                         // TODO Auto-generated catch block
46                         e.printStackTrace();
47                 }
48                 
49                 ApiRouteHealthCheck check = new ApiRouteHealthCheck();
50                 Result rst = check.execute();
51                 
52                 if (!rst.isHealthy()) {
53                         LOGGER.warn("testchecksuccess health check failed:"+rst.getMessage());
54                 }
55                 else
56                 {
57                         LOGGER.debug(" testchecksuccess health");
58                 }
59         }
60         
61         @Test
62         public void testcheckfailed()
63         {
64                 PowerMockito.mockStatic(HttpClientUtil.class);
65                 try {
66                         
67                         PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(400);
68                 } catch (Exception e) {
69                         // TODO Auto-generated catch block
70                         e.printStackTrace();
71                 }
72                 
73                 ApiRouteHealthCheck check = new ApiRouteHealthCheck();
74                 Result rst = check.execute();
75                 
76                 if (!rst.isHealthy()) {
77                         LOGGER.warn("testcheckfailed health check failed:"+rst.getMessage());
78                 }
79                 else
80                 {
81                         LOGGER.debug(" testcheckfailed health");
82                 }
83         }
84 }