001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.util; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertNotNull; 022import static org.mockito.Mockito.doReturn; 023import static org.mockito.Mockito.mock; 024 025import org.apache.hadoop.hbase.ServerName; 026import org.apache.hadoop.hbase.testclassification.MiscTests; 027import org.apache.hadoop.hbase.testclassification.SmallTests; 028import org.junit.jupiter.api.Tag; 029import org.junit.jupiter.api.Test; 030 031@Tag(MiscTests.TAG) 032@Tag(SmallTests.TAG) 033public class TestCanaryStatusUtil { 034 035 static final ServerName FAKE_HOST = ServerName.valueOf("fakehost", 12345, 1234567890); 036 037 @Test 038 public void testServerNameLink() { 039 String link = CanaryStatusUtil.serverNameLink(FAKE_HOST); 040 041 assertNotNull(link); 042 assertEquals("<a href=\"//fakehost:12346/\">fakehost,12345,1234567890</a>", link); 043 } 044 045 @Test 046 public void testServerNameLinkNoInfoPort() { 047 ServerName serverName = mock(ServerName.class); 048 doReturn(-1).when(serverName).getPort(); 049 doReturn("fakehost,12345,1234567890").when(serverName).getServerName(); 050 051 String link = CanaryStatusUtil.serverNameLink(serverName); 052 053 assertNotNull(link); 054 assertEquals("fakehost,12345,1234567890", link); 055 } 056}