1 /*
2  * Copyright (C) 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 package com.google.android.iwlan;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import android.net.InetAddresses;
22 
23 import com.google.android.iwlan.TunnelMetricsInterface.OnClosedMetrics;
24 import com.google.android.iwlan.TunnelMetricsInterface.OnOpenedMetrics;
25 import com.google.android.iwlan.TunnelMetricsInterface.TunnelMetricsData;
26 
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.junit.runners.JUnit4;
31 import org.mockito.junit.MockitoJUnit;
32 import org.mockito.junit.MockitoRule;
33 
34 @RunWith(JUnit4.class)
35 public class TunnelMetricsInterfaceTest {
36     private static final String TEST_EPDG_ADDRESS = "127.0.0.1";
37     private static final String TEST_APN_NAME = "www.xyz.com";
38 
39     @Rule public final MockitoRule mockito = MockitoJUnit.rule();
40 
41     @Test
testTunnelMetricsBuilder()42     public void testTunnelMetricsBuilder() {
43         TunnelMetricsData metricsData =
44                 new TunnelMetricsData.Builder()
45                         .setApnName(TEST_APN_NAME)
46                         .setEpdgServerAddress(InetAddresses.parseNumericAddress(TEST_EPDG_ADDRESS))
47                         .build();
48         assertEquals(TEST_APN_NAME, metricsData.getApnName());
49         assertEquals(TEST_EPDG_ADDRESS, metricsData.getEpdgServerAddress());
50     }
51 
52     @Test
testOnOpenedMetricsBuilder()53     public void testOnOpenedMetricsBuilder() {
54         OnOpenedMetrics metricsData =
55                 new OnOpenedMetrics.Builder()
56                         .setApnName(TEST_APN_NAME)
57                         .setEpdgServerAddress(InetAddresses.parseNumericAddress(TEST_EPDG_ADDRESS))
58                         .build();
59         assertEquals(TEST_APN_NAME, metricsData.getApnName());
60         assertEquals(TEST_EPDG_ADDRESS, metricsData.getEpdgServerAddress());
61     }
62 
63     @Test
testOnClosedMetricsBuilder()64     public void testOnClosedMetricsBuilder() {
65         OnClosedMetrics metricsData =
66                 new OnClosedMetrics.Builder()
67                         .setApnName(TEST_APN_NAME)
68                         .setEpdgServerAddress(InetAddresses.parseNumericAddress(TEST_EPDG_ADDRESS))
69                         .build();
70         assertEquals(TEST_APN_NAME, metricsData.getApnName());
71         assertEquals(TEST_EPDG_ADDRESS, metricsData.getEpdgServerAddress());
72     }
73 }
74