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 package android.net.vcn.cts; 17 18 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY; 19 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN; 20 21 import static org.junit.Assert.assertEquals; 22 import static org.junit.Assert.fail; 23 24 import android.net.vcn.VcnWifiUnderlyingNetworkTemplate; 25 26 import org.junit.Test; 27 28 import java.util.HashSet; 29 import java.util.Set; 30 31 public class VcnWifiUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTemplateTestBase { 32 private static final Set<String> SSIDS = Set.of("TestWifi"); 33 34 // Package private for use in VcnGatewayConnectionConfigTest getTestNetworkTemplate()35 static VcnWifiUnderlyingNetworkTemplate getTestNetworkTemplate() { 36 return new VcnWifiUnderlyingNetworkTemplate.Builder() 37 .setMetered(MATCH_FORBIDDEN) 38 .setSsids(SSIDS) 39 .setMinDownstreamBandwidthKbps( 40 MIN_ENTRY_DOWN_BANDWIDTH_KBPS, MIN_EXIT_DOWN_BANDWIDTH_KBPS) 41 .setMinUpstreamBandwidthKbps( 42 MIN_ENTRY_UP_BANDWIDTH_KBPS, MIN_EXIT_UP_BANDWIDTH_KBPS) 43 .build(); 44 } 45 46 @Test testBuilderAndGetters()47 public void testBuilderAndGetters() { 48 final VcnWifiUnderlyingNetworkTemplate networkTemplate = getTestNetworkTemplate(); 49 assertEquals(MATCH_FORBIDDEN, networkTemplate.getMetered()); 50 assertEquals(SSIDS, networkTemplate.getSsids()); 51 verifyBandwidthsWithTestValues(networkTemplate); 52 } 53 54 @Test testBuilderAndGettersForDefaultValues()55 public void testBuilderAndGettersForDefaultValues() { 56 final VcnWifiUnderlyingNetworkTemplate networkTemplate = 57 new VcnWifiUnderlyingNetworkTemplate.Builder().build(); 58 assertEquals(MATCH_ANY, networkTemplate.getMetered()); 59 assertEquals(new HashSet<String>(), networkTemplate.getSsids()); 60 verifyBandwidthsWithDefaultValues(networkTemplate); 61 } 62 63 @Test testBuildWithEmptySets()64 public void testBuildWithEmptySets() { 65 final VcnWifiUnderlyingNetworkTemplate networkTemplate = 66 new VcnWifiUnderlyingNetworkTemplate.Builder() 67 .setSsids(new HashSet<String>()) 68 .build(); 69 assertEquals(new HashSet<String>(), networkTemplate.getSsids()); 70 } 71 72 @Test testBuildWithNullSsids()73 public void testBuildWithNullSsids() { 74 try { 75 new VcnWifiUnderlyingNetworkTemplate.Builder().setSsids(null); 76 fail("Expect to fail due to the null argument"); 77 } catch (Exception expected) { 78 } 79 } 80 81 @Test testBuildWithInvalidDownstreamBandwidth()82 public void testBuildWithInvalidDownstreamBandwidth() { 83 try { 84 new VcnWifiUnderlyingNetworkTemplate.Builder() 85 .setMinDownstreamBandwidthKbps( 86 MIN_ENTRY_DOWN_BANDWIDTH_KBPS, MIN_ENTRY_DOWN_BANDWIDTH_KBPS + 1); 87 fail("Expect to fail because entry bandwidth is smaller than exit bandwidth"); 88 } catch (Exception expected) { 89 } 90 } 91 92 @Test testBuildWithInvalidUpstreamBandwidth()93 public void testBuildWithInvalidUpstreamBandwidth() { 94 try { 95 new VcnWifiUnderlyingNetworkTemplate.Builder() 96 .setMinUpstreamBandwidthKbps( 97 MIN_ENTRY_UP_BANDWIDTH_KBPS, MIN_ENTRY_UP_BANDWIDTH_KBPS + 1); 98 fail("Expect to fail because entry bandwidth is smaller than exit bandwidth"); 99 } catch (Exception expected) { 100 } 101 } 102 } 103