1 /*******************************************************************************
2 * Copyright 2016-2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
13 ******************************************************************************/
14 package org.onap.msb.apiroute.health;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mockito;
19 import org.onap.msb.apiroute.wrapper.util.HttpClientUtil;
20 import org.powermock.api.mockito.PowerMockito;
21 import org.powermock.core.classloader.annotations.PrepareForTest;
22 import org.powermock.modules.junit4.PowerMockRunner;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.codahale.metrics.health.HealthCheck.Result;
28 @RunWith(PowerMockRunner.class)
29 @PrepareForTest({HttpClientUtil.class, OpenRestyHealthCheck.class})
30 public class OpenRestyHealthCheckTest {
31 private static final Logger LOGGER = LoggerFactory.getLogger(OpenRestyHealthCheckTest.class);
34 public void testchecksuccess() {
35 PowerMockito.mockStatic(HttpClientUtil.class);
38 PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(200);
39 } catch (Exception e) {
40 // TODO Auto-generated catch block
44 PowerMockito.mockStatic(System.class);
45 PowerMockito.when(System.getenv("HTTP_OVERWRITE_PORT")).thenReturn("10080");
47 OpenRestyHealthCheck check = new OpenRestyHealthCheck();
49 Result rst = check.execute();
51 if (!rst.isHealthy()) {
52 LOGGER.warn("testchecksuccess health check failed:" + rst.getMessage());
54 LOGGER.debug(" testchecksuccess health");
59 public void testcheckfailed() {
60 PowerMockito.mockStatic(HttpClientUtil.class);
63 PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(400);
64 } catch (Exception e) {
65 // TODO Auto-generated catch block
69 PowerMockito.mockStatic(System.class);
70 PowerMockito.when(System.getenv("HTTP_OVERWRITE_PORT")).thenReturn("");
72 OpenRestyHealthCheck check = new OpenRestyHealthCheck();
74 Result rst = check.execute();
76 if (!rst.isHealthy()) {
77 LOGGER.warn("testchecksuccess health check failed:" + rst.getMessage());
79 LOGGER.debug(" testchecksuccess health");