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.util; 019 020import static org.junit.Assert.assertEquals; 021import static org.junit.Assert.assertNull; 022 023import java.util.List; 024import java.util.Map; 025import org.apache.hadoop.conf.Configuration; 026import org.apache.hadoop.hbase.HBaseClassTestRule; 027import org.apache.hadoop.hbase.testclassification.SmallTests; 028import org.junit.Before; 029import org.junit.ClassRule; 030import org.junit.Test; 031import org.junit.experimental.categories.Category; 032 033import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap; 034import org.apache.hbase.thirdparty.com.google.common.collect.Lists; 035 036@Category({ SmallTests.class }) 037public class TestConfigurationUtil { 038 039 @ClassRule 040 public static final HBaseClassTestRule CLASS_RULE = 041 HBaseClassTestRule.forClass(TestConfigurationUtil.class); 042 043 private Configuration conf; 044 private Map<String, String> keyValues; 045 private String key; 046 047 @Before 048 public void setUp() throws Exception { 049 this.conf = new Configuration(); 050 this.keyValues = ImmutableMap.of("k1", "v1", "k2", "v2"); 051 this.key = "my_conf_key"; 052 } 053 054 public void callSetKeyValues() { 055 ConfigurationUtil.setKeyValues(conf, key, keyValues.entrySet()); 056 } 057 058 public List<Map.Entry<String, String>> callGetKeyValues() { 059 return ConfigurationUtil.getKeyValues(conf, key); 060 } 061 062 @Test 063 public void testGetAndSetKeyValuesWithValues() throws Exception { 064 callSetKeyValues(); 065 assertEquals(Lists.newArrayList(this.keyValues.entrySet()), callGetKeyValues()); 066 } 067 068 @Test 069 public void testGetKeyValuesWithUnsetKey() throws Exception { 070 assertNull(callGetKeyValues()); 071 } 072 073}