1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.tradefed.config; 17 18 import static org.junit.Assert.assertEquals; 19 import static org.junit.Assert.fail; 20 21 import org.junit.Before; 22 import org.junit.Test; 23 import org.junit.runner.RunWith; 24 import org.junit.runners.JUnit4; 25 26 /** Unit Tests for {@link ConfigurationDescriptor} */ 27 @RunWith(JUnit4.class) 28 public class ConfigurationDescriptorTest { 29 30 private ConfigurationFactory mFactory; 31 32 @Before 33 public void setUp() throws Exception { 34 mFactory = 35 new ConfigurationFactory() { 36 @Override 37 String getConfigPrefix() { 38 return "testconfigs/"; 39 } 40 }; 41 } 42 43 /** 44 * Test that even if an option exists in a ConfigurationDescriptor, it cannot receive value via 45 * command line. 46 */ 47 @Test 48 public void testRejectCommandLine() throws Exception { 49 IConfiguration config = mFactory.createConfigurationFromArgs(new String[] {"test-config"}); 50 OptionSetter setter = new OptionSetter(config.getConfigurationDescription()); 51 // Confirm that options exists for the object 52 setter.setOptionValue("test-suite-tag", "Test"); 53 try { 54 // This will still throw since it cannot be set via command line. 55 mFactory.createConfigurationFromArgs( 56 new String[] {"test-config", "--test-suite-tag", "TEST"}); 57 fail("Should have thrown an exception."); 58 } catch (OptionNotAllowedException expected) { 59 assertEquals( 60 "Option test-suite-tag cannot be specified via command line. " 61 + "Only in the configuration xml.", 62 expected.getMessage()); 63 } 64 } 65 } 66