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