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 package android.net.vcn; 17 18 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY; 19 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN; 20 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED; 21 22 import static org.junit.Assert.assertEquals; 23 import static org.junit.Assert.fail; 24 25 import org.junit.Test; 26 27 import java.util.HashSet; 28 import java.util.Set; 29 30 public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTemplateTestBase { 31 private static final Set<String> ALLOWED_PLMN_IDS = new HashSet<>(); 32 private static final Set<Integer> ALLOWED_CARRIER_IDS = new HashSet<>(); 33 34 // Package private for use in VcnGatewayConnectionConfigTest getTestNetworkTemplate()35 static VcnCellUnderlyingNetworkTemplate getTestNetworkTemplate() { 36 return new VcnCellUnderlyingNetworkTemplate.Builder() 37 .setMetered(MATCH_FORBIDDEN) 38 .setMinUpstreamBandwidthKbps( 39 TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS, 40 TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS) 41 .setMinDownstreamBandwidthKbps( 42 TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS, 43 TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS) 44 .setOperatorPlmnIds(ALLOWED_PLMN_IDS) 45 .setSimSpecificCarrierIds(ALLOWED_CARRIER_IDS) 46 .setRoaming(MATCH_FORBIDDEN) 47 .setOpportunistic(MATCH_REQUIRED) 48 .build(); 49 } 50 51 @Test testBuilderAndGetters()52 public void testBuilderAndGetters() { 53 final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate(); 54 assertEquals(MATCH_FORBIDDEN, networkPriority.getMetered()); 55 assertEquals( 56 TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS, 57 networkPriority.getMinEntryUpstreamBandwidthKbps()); 58 assertEquals( 59 TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS, 60 networkPriority.getMinExitUpstreamBandwidthKbps()); 61 assertEquals( 62 TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS, 63 networkPriority.getMinEntryDownstreamBandwidthKbps()); 64 assertEquals( 65 TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS, 66 networkPriority.getMinExitDownstreamBandwidthKbps()); 67 assertEquals(ALLOWED_PLMN_IDS, networkPriority.getOperatorPlmnIds()); 68 assertEquals(ALLOWED_CARRIER_IDS, networkPriority.getSimSpecificCarrierIds()); 69 assertEquals(MATCH_FORBIDDEN, networkPriority.getRoaming()); 70 assertEquals(MATCH_REQUIRED, networkPriority.getOpportunistic()); 71 } 72 73 @Test testBuilderAndGettersForDefaultValues()74 public void testBuilderAndGettersForDefaultValues() { 75 final VcnCellUnderlyingNetworkTemplate networkPriority = 76 new VcnCellUnderlyingNetworkTemplate.Builder().build(); 77 assertEquals(MATCH_ANY, networkPriority.getMetered()); 78 79 // Explicitly expect 0, as documented in Javadoc on setter methods. 80 assertEquals(0, networkPriority.getMinEntryUpstreamBandwidthKbps()); 81 assertEquals(0, networkPriority.getMinExitUpstreamBandwidthKbps()); 82 assertEquals(0, networkPriority.getMinEntryDownstreamBandwidthKbps()); 83 assertEquals(0, networkPriority.getMinExitDownstreamBandwidthKbps()); 84 85 assertEquals(new HashSet<String>(), networkPriority.getOperatorPlmnIds()); 86 assertEquals(new HashSet<Integer>(), networkPriority.getSimSpecificCarrierIds()); 87 assertEquals(MATCH_ANY, networkPriority.getRoaming()); 88 assertEquals(MATCH_ANY, networkPriority.getOpportunistic()); 89 } 90 91 @Test testBuilderRequiresStricterEntryCriteria()92 public void testBuilderRequiresStricterEntryCriteria() { 93 try { 94 new VcnCellUnderlyingNetworkTemplate.Builder() 95 .setMinUpstreamBandwidthKbps( 96 TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS, 97 TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS); 98 99 fail("Expected IAE for exit threshold > entry threshold"); 100 } catch (IllegalArgumentException expected) { 101 } 102 103 try { 104 new VcnCellUnderlyingNetworkTemplate.Builder() 105 .setMinDownstreamBandwidthKbps( 106 TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS, 107 TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS); 108 109 fail("Expected IAE for exit threshold > entry threshold"); 110 } catch (IllegalArgumentException expected) { 111 } 112 } 113 114 @Test testPersistableBundle()115 public void testPersistableBundle() { 116 final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate(); 117 assertEquals( 118 networkPriority, 119 VcnUnderlyingNetworkTemplate.fromPersistableBundle( 120 networkPriority.toPersistableBundle())); 121 } 122 } 123