1 /*
2  * Copyright 2022 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 
17 import androidx.benchmark.darwin.gradle.xcode.ActionTestPlanRunSummaries
18 import androidx.benchmark.darwin.gradle.xcode.ActionTestSummary
19 import androidx.benchmark.darwin.gradle.xcode.ActionsInvocationRecord
20 import androidx.benchmark.darwin.gradle.xcode.GsonHelpers
21 import com.google.common.truth.Truth.assertThat
22 import org.junit.Test
23 import org.junit.runner.RunWith
24 import org.junit.runners.JUnit4
25 
26 @RunWith(JUnit4::class)
27 class ModelsTest {
28     @Test
parseXcResultOutputsnull29     fun parseXcResultOutputs() {
30         val json = testData(XCRESULT_OUTPUT_JSON).readText()
31         val gson = GsonHelpers.gson()
32         val record = gson.fromJson(json, ActionsInvocationRecord::class.java)
33         assertThat(record.actions.testReferences().size).isEqualTo(1)
34         assertThat(record.metrics.size()).isEqualTo(1)
35         assertThat(record.actions.isSuccessful()).isTrue()
36     }
37 
38     @Test
parseTestsReferenceOutputnull39     fun parseTestsReferenceOutput() {
40         val json = testData(XC_TESTS_REFERENCE_OUTPUT_JSON).readText()
41         val gson = GsonHelpers.gson()
42         val testPlanSummaries = gson.fromJson(json, ActionTestPlanRunSummaries::class.java)
43         val testSummaryMetas = testPlanSummaries.testSummaries()
44         assertThat(testSummaryMetas.size).isEqualTo(1)
45         assertThat(testSummaryMetas[0].summaryRefId()).isNotEmpty()
46         assertThat(testSummaryMetas[0].isSuccessful()).isTrue()
47     }
48 
49     @Test
parseTestOutputnull50     fun parseTestOutput() {
51         val json = testData(XC_TEST_OUTPUT_JSON).readText()
52         val gson = GsonHelpers.gson()
53         val testSummary = gson.fromJson(json, ActionTestSummary::class.java)
54         assertThat(testSummary.title()).isNotEmpty()
55         assertThat(testSummary.isSuccessful()).isTrue()
56     }
57 
58     companion object {
59         private const val XCRESULT_OUTPUT_JSON = "xcresult_output.json"
60         private const val XC_TESTS_REFERENCE_OUTPUT_JSON = "tests_reference_output.json"
61         private const val XC_TEST_OUTPUT_JSON = "test_output.json"
62     }
63 }
64