1 /*
2  * Copyright (C) 2021 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 package com.android.imsserviceentitlement.ts43;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import androidx.test.runner.AndroidJUnit4;
22 
23 import com.android.imsserviceentitlement.ts43.Ts43Constants.EntitlementStatus;
24 import com.android.imsserviceentitlement.ts43.Ts43VowifiStatus.AddrStatus;
25 import com.android.imsserviceentitlement.ts43.Ts43VowifiStatus.ProvStatus;
26 import com.android.imsserviceentitlement.ts43.Ts43VowifiStatus.TcStatus;
27 
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 
31 @RunWith(AndroidJUnit4.class)
32 public class Ts43VowifiStatusTest {
33     @Test
ts43VowifiStatus_vowifiAvailable_vowifiEntitled()34     public void ts43VowifiStatus_vowifiAvailable_vowifiEntitled() {
35         Ts43VowifiStatus status =
36                 Ts43VowifiStatus.builder()
37                         .setEntitlementStatus(EntitlementStatus.ENABLED)
38                         .setAddrStatus(AddrStatus.AVAILABLE)
39                         .setTcStatus(TcStatus.AVAILABLE)
40                         .setProvStatus(ProvStatus.PROVISIONED)
41                         .build();
42 
43         assertThat(status.vowifiEntitled()).isTrue();
44         assertThat(status.serverDataMissing()).isFalse();
45         assertThat(status.inProgress()).isFalse();
46         assertThat(status.incompatible()).isFalse();
47     }
48 
49     @Test
ts43VowifiStatus_addressNotRequired_vowifiEntitled()50     public void ts43VowifiStatus_addressNotRequired_vowifiEntitled() {
51         Ts43VowifiStatus status =
52                 Ts43VowifiStatus.builder()
53                         .setEntitlementStatus(EntitlementStatus.ENABLED)
54                         .setAddrStatus(AddrStatus.NOT_REQUIRED)
55                         .setTcStatus(TcStatus.AVAILABLE)
56                         .setProvStatus(ProvStatus.PROVISIONED)
57                         .build();
58 
59         assertThat(status.vowifiEntitled()).isTrue();
60         assertThat(status.serverDataMissing()).isFalse();
61         assertThat(status.inProgress()).isFalse();
62         assertThat(status.incompatible()).isFalse();
63     }
64 
65     @Test
ts43VowifiStatus_tcStatusNotRequired_vowifiEntitled()66     public void ts43VowifiStatus_tcStatusNotRequired_vowifiEntitled() {
67         Ts43VowifiStatus status =
68                 Ts43VowifiStatus.builder()
69                         .setEntitlementStatus(EntitlementStatus.ENABLED)
70                         .setAddrStatus(AddrStatus.AVAILABLE)
71                         .setTcStatus(TcStatus.NOT_REQUIRED)
72                         .setProvStatus(ProvStatus.PROVISIONED)
73                         .build();
74 
75         assertThat(status.vowifiEntitled()).isTrue();
76         assertThat(status.serverDataMissing()).isFalse();
77         assertThat(status.inProgress()).isFalse();
78         assertThat(status.incompatible()).isFalse();
79     }
80 
81     @Test
ts43VowifiStatus_provisionNotRequired_vowifiEntitled()82     public void ts43VowifiStatus_provisionNotRequired_vowifiEntitled() {
83         Ts43VowifiStatus status =
84                 Ts43VowifiStatus.builder()
85                         .setEntitlementStatus(EntitlementStatus.ENABLED)
86                         .setAddrStatus(AddrStatus.AVAILABLE)
87                         .setTcStatus(TcStatus.AVAILABLE)
88                         .setProvStatus(ProvStatus.NOT_REQUIRED)
89                         .build();
90 
91         assertThat(status.vowifiEntitled()).isTrue();
92         assertThat(status.serverDataMissing()).isFalse();
93         assertThat(status.inProgress()).isFalse();
94         assertThat(status.incompatible()).isFalse();
95     }
96 
97     @Test
ts43VowifiStatus_addressNotAvailable_serverDataMissing()98     public void ts43VowifiStatus_addressNotAvailable_serverDataMissing() {
99         Ts43VowifiStatus status =
100                 Ts43VowifiStatus.builder()
101                         .setEntitlementStatus(EntitlementStatus.DISABLED)
102                         .setAddrStatus(AddrStatus.NOT_AVAILABLE)
103                         .setTcStatus(TcStatus.AVAILABLE)
104                         .setProvStatus(ProvStatus.PROVISIONED)
105                         .build();
106 
107         assertThat(status.vowifiEntitled()).isFalse();
108         assertThat(status.serverDataMissing()).isTrue();
109         assertThat(status.inProgress()).isFalse();
110         assertThat(status.incompatible()).isFalse();
111     }
112 
113     @Test
ts43VowifiStatus_tcStatusAvailable_serverDataMissing()114     public void ts43VowifiStatus_tcStatusAvailable_serverDataMissing() {
115         Ts43VowifiStatus status =
116                 Ts43VowifiStatus.builder()
117                         .setEntitlementStatus(EntitlementStatus.DISABLED)
118                         .setAddrStatus(AddrStatus.AVAILABLE)
119                         .setTcStatus(TcStatus.NOT_AVAILABLE)
120                         .setProvStatus(ProvStatus.PROVISIONED)
121                         .build();
122 
123         assertThat(status.vowifiEntitled()).isFalse();
124         assertThat(status.serverDataMissing()).isTrue();
125         assertThat(status.inProgress()).isFalse();
126         assertThat(status.incompatible()).isFalse();
127     }
128 
129     @Test
ts43VowifiStatus_entitlementStatusProvisioning_inProgress()130     public void ts43VowifiStatus_entitlementStatusProvisioning_inProgress() {
131         Ts43VowifiStatus status =
132                 Ts43VowifiStatus.builder()
133                         .setEntitlementStatus(EntitlementStatus.PROVISIONING)
134                         .setAddrStatus(AddrStatus.AVAILABLE)
135                         .setTcStatus(TcStatus.AVAILABLE)
136                         .setProvStatus(ProvStatus.PROVISIONED)
137                         .build();
138 
139         assertThat(status.vowifiEntitled()).isFalse();
140         assertThat(status.serverDataMissing()).isFalse();
141         assertThat(status.inProgress()).isTrue();
142         assertThat(status.incompatible()).isFalse();
143     }
144 
145     @Test
ts43VowifiStatus_addressInProgress_inProgress()146     public void ts43VowifiStatus_addressInProgress_inProgress() {
147         Ts43VowifiStatus status =
148                 Ts43VowifiStatus.builder()
149                         .setEntitlementStatus(EntitlementStatus.DISABLED)
150                         .setAddrStatus(AddrStatus.IN_PROGRESS)
151                         .setTcStatus(TcStatus.AVAILABLE)
152                         .setProvStatus(ProvStatus.PROVISIONED)
153                         .build();
154 
155         assertThat(status.vowifiEntitled()).isFalse();
156         assertThat(status.serverDataMissing()).isFalse();
157         assertThat(status.inProgress()).isTrue();
158         assertThat(status.incompatible()).isFalse();
159     }
160 
161     @Test
ts43VowifiStatus_tcStatusInProgress_inProgress()162     public void ts43VowifiStatus_tcStatusInProgress_inProgress() {
163         Ts43VowifiStatus status =
164                 Ts43VowifiStatus.builder()
165                         .setEntitlementStatus(EntitlementStatus.DISABLED)
166                         .setAddrStatus(AddrStatus.AVAILABLE)
167                         .setTcStatus(TcStatus.IN_PROGRESS)
168                         .setProvStatus(ProvStatus.PROVISIONED)
169                         .build();
170 
171         assertThat(status.vowifiEntitled()).isFalse();
172         assertThat(status.serverDataMissing()).isFalse();
173         assertThat(status.inProgress()).isTrue();
174         assertThat(status.incompatible()).isFalse();
175     }
176 
177     @Test
ts43VowifiStatus_provStatusNotProvisioned_inProgress()178     public void ts43VowifiStatus_provStatusNotProvisioned_inProgress() {
179         Ts43VowifiStatus status =
180                 Ts43VowifiStatus.builder()
181                         .setEntitlementStatus(EntitlementStatus.DISABLED)
182                         .setAddrStatus(AddrStatus.AVAILABLE)
183                         .setTcStatus(TcStatus.AVAILABLE)
184                         .setProvStatus(ProvStatus.NOT_PROVISIONED)
185                         .build();
186 
187         assertThat(status.vowifiEntitled()).isFalse();
188         assertThat(status.serverDataMissing()).isFalse();
189         assertThat(status.inProgress()).isTrue();
190         assertThat(status.incompatible()).isFalse();
191     }
192 
193     @Test
ts43VowifiStatus_provStatusInProgress_inProgress()194     public void ts43VowifiStatus_provStatusInProgress_inProgress() {
195         Ts43VowifiStatus status =
196                 Ts43VowifiStatus.builder()
197                         .setEntitlementStatus(EntitlementStatus.DISABLED)
198                         .setAddrStatus(AddrStatus.AVAILABLE)
199                         .setTcStatus(TcStatus.AVAILABLE)
200                         .setProvStatus(ProvStatus.IN_PROGRESS)
201                         .build();
202 
203         assertThat(status.vowifiEntitled()).isFalse();
204         assertThat(status.serverDataMissing()).isFalse();
205         assertThat(status.inProgress()).isTrue();
206         assertThat(status.incompatible()).isFalse();
207     }
208 
209     @Test
ts43VowifiStatus_provStatusInProgress_incompatible()210     public void ts43VowifiStatus_provStatusInProgress_incompatible() {
211         Ts43VowifiStatus status =
212                 Ts43VowifiStatus.builder()
213                         .setEntitlementStatus(EntitlementStatus.INCOMPATIBLE)
214                         .setAddrStatus(AddrStatus.AVAILABLE)
215                         .setTcStatus(TcStatus.AVAILABLE)
216                         .setProvStatus(ProvStatus.PROVISIONED)
217                         .build();
218 
219         assertThat(status.vowifiEntitled()).isFalse();
220         assertThat(status.serverDataMissing()).isFalse();
221         assertThat(status.inProgress()).isFalse();
222         assertThat(status.incompatible()).isTrue();
223     }
224 
225     @Test
ts43VowifiStatus_entitlementStatusEnabledAndServerDataMissing_noAnyMatches()226     public void ts43VowifiStatus_entitlementStatusEnabledAndServerDataMissing_noAnyMatches() {
227         Ts43VowifiStatus status =
228                 Ts43VowifiStatus.builder()
229                         .setEntitlementStatus(EntitlementStatus.ENABLED)
230                         .setAddrStatus(AddrStatus.NOT_AVAILABLE)
231                         .setTcStatus(TcStatus.NOT_AVAILABLE)
232                         .setProvStatus(ProvStatus.PROVISIONED)
233                         .build();
234 
235         assertThat(status.vowifiEntitled()).isFalse();
236         assertThat(status.serverDataMissing()).isFalse();
237         assertThat(status.inProgress()).isFalse();
238         assertThat(status.incompatible()).isFalse();
239     }
240 
241     @Test
ts43VowifiStatus_entitlementStatusDisabledAndServerDataNotRequired_noAnyMatches()242     public void ts43VowifiStatus_entitlementStatusDisabledAndServerDataNotRequired_noAnyMatches() {
243         Ts43VowifiStatus status =
244                 Ts43VowifiStatus.builder()
245                         .setEntitlementStatus(EntitlementStatus.DISABLED)
246                         .setAddrStatus(AddrStatus.AVAILABLE)
247                         .setTcStatus(TcStatus.AVAILABLE)
248                         .setProvStatus(ProvStatus.PROVISIONED)
249                         .build();
250 
251         assertThat(status.vowifiEntitled()).isFalse();
252         assertThat(status.serverDataMissing()).isFalse();
253         assertThat(status.inProgress()).isFalse();
254         assertThat(status.incompatible()).isFalse();
255     }
256 
257     @Test
toString_vowifiAvailable_statusLogged()258     public void toString_vowifiAvailable_statusLogged() {
259         Ts43VowifiStatus status =
260                 Ts43VowifiStatus.builder()
261                         .setEntitlementStatus(EntitlementStatus.ENABLED)
262                         .setAddrStatus(AddrStatus.AVAILABLE)
263                         .setTcStatus(TcStatus.AVAILABLE)
264                         .setProvStatus(ProvStatus.PROVISIONED)
265                         .build();
266 
267         assertThat(status.toString())
268                 .isEqualTo("Ts43VowifiStatus {"
269                         + "entitlementStatus=1,tcStatus=1,addrStatus=1,provStatus=1}");
270     }
271 }
272