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