1 /*
2  * Copyright (C) 2019 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.compatibility.tradefed;
17 
18 import static org.junit.Assert.assertEquals;
19 
20 import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
21 import com.android.compatibility.common.tradefed.build.CompatibilityBuildProvider;
22 import com.android.tradefed.build.IBuildInfo;
23 import com.android.tradefed.config.OptionSetter;
24 import com.android.tradefed.util.FileUtil;
25 import java.io.File;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.junit.runners.JUnit4;
31 
32 /** Tests for vts-tradefed. */
33 @RunWith(JUnit4.class)
34 public class VtsCoreTradefedTest {
35     private static final String PROPERTY_NAME = "VTS_ROOT";
36     private static final String SUITE_FULL_NAME = "Vendor Test Suite";
37     private static final String SUITE_NAME = "VTS";
38     private static final String SUITE_PLAN = "vts";
39     private static final String DYNAMIC_CONFIG_URL = "";
40 
41     private String mOriginalProperty = null;
42 
43     @Before
setUp()44     public void setUp() {
45         mOriginalProperty = System.getProperty(PROPERTY_NAME);
46     }
47 
48     @After
tearDown()49     public void tearDown() {
50         if (mOriginalProperty != null) {
51             System.setProperty(PROPERTY_NAME, mOriginalProperty);
52         }
53     }
54 
55     @Test
testSuiteInfoLoad()56     public void testSuiteInfoLoad() throws Exception {
57         // Test the values in the manifest can be loaded
58         File root = FileUtil.createTempDir("root");
59         System.setProperty(PROPERTY_NAME, root.getAbsolutePath());
60         File base = new File(root, "android-vts");
61         base.mkdirs();
62         File tests = new File(base, "testcases");
63         tests.mkdirs();
64         CompatibilityBuildProvider provider = new CompatibilityBuildProvider();
65         OptionSetter setter = new OptionSetter(provider);
66         setter.setOptionValue("plan", SUITE_PLAN);
67         setter.setOptionValue("dynamic-config-url", DYNAMIC_CONFIG_URL);
68         IBuildInfo info = provider.getBuild();
69         CompatibilityBuildHelper helper = new CompatibilityBuildHelper(info);
70         assertEquals("Incorrect suite full name", SUITE_FULL_NAME, helper.getSuiteFullName());
71         assertEquals("Incorrect suite name", SUITE_NAME, helper.getSuiteName());
72         FileUtil.recursiveDelete(root);
73     }
74 }
75