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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.hadoop
.hbase
.client
;
20 import org
.apache
.hadoop
.conf
.Configuration
;
21 import org
.apache
.hadoop
.hbase
.ZooKeeperConnectionException
;
22 import org
.mockito
.Mockito
;
25 * {@link Connection} testing utility.
27 public class HConnectionTestingUtility
{
30 * Not part of {@link HBaseTestingUtility} because this class is not in same package as {@link
31 * ConnectionImplementation}. Would have to reveal ugly {@link ConnectionImplementation} innards
32 * to HBaseTestingUtility to give it access.
35 * Get a Mocked {@link Connection} that goes with the passed <code>conf</code>
36 * configuration instance. Minimally the mock will return <code>conf</conf> when
37 * {@link Connection#getConfiguration()} is invoked. Be sure to shutdown the
38 * connection when done by calling {@link Connection#close()} else it will stick around; this is
39 * probably not what you want.
40 * @param conf configuration
41 * @return ConnectionImplementation object for <code>conf</code>
42 * @throws ZooKeeperConnectionException
44 public static Connection
getMockedConnection(final Configuration conf
)
45 throws ZooKeeperConnectionException
{
46 Connection connection
= Mockito
.mock(Connection
.class);
47 Mockito
.when(connection
.getConfiguration()).thenReturn(conf
);