View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.http;
19  
20  import org.junit.Test;
21  import org.junit.experimental.categories.Category;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.commons.logging.Log;
24  import org.apache.hadoop.hbase.testclassification.SmallTests;
25  
26  import java.io.FileNotFoundException;
27  
28  /**
29   * Test webapp loading
30   */
31  @Category(SmallTests.class)
32  public class TestHttpServerWebapps extends HttpServerFunctionalTest {
33    private static final Log log = LogFactory.getLog(TestHttpServerWebapps.class);
34  
35    /**
36     * Test that the test server is loadable on the classpath
37     * @throws Throwable if something went wrong
38     */
39    @Test
40    public void testValidServerResource() throws Throwable {
41      HttpServer server = null;
42      try {
43        server = createServer("test");
44      } finally {
45        stop(server);
46      }
47    }
48  
49    /**
50     * Test that an invalid webapp triggers an exception
51     * @throws Throwable if something went wrong
52     */
53    @Test
54    public void testMissingServerResource() throws Throwable {
55      try {
56        HttpServer server = createServer("NoSuchWebapp");
57        //should not have got here.
58        //close the server
59        String serverDescription = server.toString();
60        stop(server);
61        fail("Expected an exception, got " + serverDescription);
62      } catch (FileNotFoundException expected) {
63        log.debug("Expected exception " + expected, expected);
64      }
65    }
66  
67  }