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.http; 019 020import static org.junit.jupiter.api.Assertions.fail; 021 022import java.io.FileNotFoundException; 023import org.apache.hadoop.hbase.testclassification.MiscTests; 024import org.apache.hadoop.hbase.testclassification.SmallTests; 025import org.junit.jupiter.api.Tag; 026import org.junit.jupiter.api.Test; 027import org.slf4j.Logger; 028import org.slf4j.LoggerFactory; 029 030/** 031 * Test webapp loading 032 */ 033@Tag(MiscTests.TAG) 034@Tag(SmallTests.TAG) 035public class TestHttpServerWebapps extends HttpServerFunctionalTest { 036 037 private static final Logger log = LoggerFactory.getLogger(TestHttpServerWebapps.class); 038 039 /** 040 * Test that the test server is loadable on the classpath 041 * @throws Throwable if something went wrong 042 */ 043 @Test 044 public void testValidServerResource() throws Throwable { 045 HttpServer server = null; 046 try { 047 server = createServer("test"); 048 } finally { 049 stop(server); 050 } 051 } 052 053 /** 054 * Test that an invalid webapp triggers an exception 055 * @throws Throwable if something went wrong 056 */ 057 @Test 058 public void testMissingServerResource() throws Throwable { 059 try { 060 HttpServer server = createServer("NoSuchWebapp"); 061 // should not have got here. 062 // close the server 063 String serverDescription = server.toString(); 064 stop(server); 065 fail("Expected an exception, got " + serverDescription); 066 } catch (FileNotFoundException expected) { 067 log.debug("Expected exception " + expected, expected); 068 } 069 } 070 071}