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