1 /*******************************************************************************
2 * Copyright 2016-2017 ZTE, Inc. and others.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mockito;
21 import org.onap.msb.apiroute.health.OpenRestyHealthCheck;
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;
29 import com.codahale.metrics.health.HealthCheck.Result;
31 @RunWith(PowerMockRunner.class)
32 @PrepareForTest({ HttpClientUtil.class,OpenRestyHealthCheck.class })
33 public class OpenRestyHealthCheckTest {
34 private static final Logger LOGGER = LoggerFactory
35 .getLogger(OpenRestyHealthCheckTest.class);
38 public void testchecksuccess()
40 PowerMockito.mockStatic(HttpClientUtil.class);
43 PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(200);
44 } catch (Exception e) {
45 // TODO Auto-generated catch block
49 PowerMockito.mockStatic(System.class);
50 PowerMockito.when(System.getenv("HTTP_OVERWRITE_PORT")).thenReturn("10080");
52 OpenRestyHealthCheck check = new OpenRestyHealthCheck();
54 Result rst = check.execute();
56 if (!rst.isHealthy()) {
57 LOGGER.warn("testchecksuccess health check failed:"+rst.getMessage());
61 LOGGER.debug(" testchecksuccess health");
66 public void testcheckfailed()
68 PowerMockito.mockStatic(HttpClientUtil.class);
71 PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(400);
72 } catch (Exception e) {
73 // TODO Auto-generated catch block
77 PowerMockito.mockStatic(System.class);
78 PowerMockito.when(System.getenv("HTTP_OVERWRITE_PORT")).thenReturn("");
80 OpenRestyHealthCheck check = new OpenRestyHealthCheck();
82 Result rst = check.execute();
84 if (!rst.isHealthy()) {
85 LOGGER.warn("testchecksuccess health check failed:"+rst.getMessage());
89 LOGGER.debug(" testchecksuccess health");