1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.vcn;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import android.net.NetworkCapabilities;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class VcnGatewayConnectionConfigTest {
// Public for use in VcnGatewayConnectionTest
public static final int[] EXPOSED_CAPS =
new int[] {
NetworkCapabilities.NET_CAPABILITY_INTERNET, NetworkCapabilities.NET_CAPABILITY_MMS
};
public static final int[] UNDERLYING_CAPS = new int[] {NetworkCapabilities.NET_CAPABILITY_DUN};
static {
Arrays.sort(EXPOSED_CAPS);
Arrays.sort(UNDERLYING_CAPS);
}
public static final long[] RETRY_INTERVALS_MS =
new long[] {
TimeUnit.SECONDS.toMillis(5),
TimeUnit.SECONDS.toMillis(30),
TimeUnit.MINUTES.toMillis(1),
TimeUnit.MINUTES.toMillis(5),
TimeUnit.MINUTES.toMillis(15),
TimeUnit.MINUTES.toMillis(30)
};
public static final int MAX_MTU = 1360;
public static final VcnControlPlaneConfig CONTROL_PLANE_CONFIG =
VcnControlPlaneIkeConfigTest.buildTestConfig();
// Public for use in VcnGatewayConnectionTest
public static VcnGatewayConnectionConfig buildTestConfig() {
return buildTestConfigWithExposedCaps(EXPOSED_CAPS);
}
private static VcnGatewayConnectionConfig.Builder newBuilder() {
return new VcnGatewayConnectionConfig.Builder(CONTROL_PLANE_CONFIG);
}
// Public for use in VcnGatewayConnectionTest
public static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(int... exposedCaps) {
final VcnGatewayConnectionConfig.Builder builder =
newBuilder().setRetryInterval(RETRY_INTERVALS_MS).setMaxMtu(MAX_MTU);
for (int caps : exposedCaps) {
builder.addExposedCapability(caps);
}
for (int caps : UNDERLYING_CAPS) {
builder.addRequiredUnderlyingCapability(caps);
}
return builder.build();
}
@Test
public void testBuilderRequiresNonNullControlPlaneConfig() {
try {
new VcnGatewayConnectionConfig.Builder(null).build();
fail("Expected exception due to invalid control plane config");
} catch (NullPointerException e) {
}
}
@Test
public void testBuilderRequiresNonEmptyExposedCaps() {
try {
newBuilder()
.addRequiredUnderlyingCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build();
fail("Expected exception due to invalid exposed capabilities");
} catch (IllegalArgumentException e) {
}
}
@Test
public void testBuilderRequiresNonEmptyUnderlyingCaps() {
try {
newBuilder().addExposedCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build();
fail("Expected exception due to invalid required underlying capabilities");
} catch (IllegalArgumentException e) {
}
}
@Test
public void testBuilderRequiresNonNullRetryInterval() {
try {
newBuilder().setRetryInterval(null);
fail("Expected exception due to invalid retryIntervalMs");
} catch (IllegalArgumentException e) {
}
}
@Test
public void testBuilderRequiresNonEmptyRetryInterval() {
try {
newBuilder().setRetryInterval(new long[0]);
fail("Expected exception due to invalid retryIntervalMs");
} catch (IllegalArgumentException e) {
}
}
@Test
public void testBuilderRequiresValidMtu() {
try {
newBuilder().setMaxMtu(VcnGatewayConnectionConfig.MIN_MTU_V6 - 1);
fail("Expected exception due to invalid mtu");
} catch (IllegalArgumentException e) {
}
}
@Test
public void testBuilderAndGetters() {
final VcnGatewayConnectionConfig config = buildTestConfig();
int[] exposedCaps = config.getExposedCapabilities();
Arrays.sort(exposedCaps);
assertArrayEquals(EXPOSED_CAPS, exposedCaps);
int[] underlyingCaps = config.getRequiredUnderlyingCapabilities();
Arrays.sort(underlyingCaps);
assertArrayEquals(UNDERLYING_CAPS, underlyingCaps);
assertEquals(CONTROL_PLANE_CONFIG, config.getControlPlaneConfig());
assertFalse(CONTROL_PLANE_CONFIG == config.getControlPlaneConfig());
assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMs());
assertEquals(MAX_MTU, config.getMaxMtu());
}
@Test
public void testPersistableBundle() {
final VcnGatewayConnectionConfig config = buildTestConfig();
assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle()));
}
}
|