summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJames Mattis <jmattis@google.com>2021-12-26 12:43:03 -0800
committerJames Mattis <jmattis@google.com>2022-01-05 13:50:42 -0800
commit51faeaf411aee891965010cf580042b05ed521cb (patch)
tree8f676d061513019c2658388e949e3f7f8a200a43 /tests
parentf21fda9cdfafa5d815cb2c1a0adfbf211e3ab51c (diff)
downloadethernet-51faeaf411aee891965010cf580042b05ed521cb.tar.gz
Eth Service updates to validate net mgmt calls
Updates to ethernet service code to validate calls to ethernet network management APIs. Bug: 210485380 Test: atest EthernetServiceTests Change-Id: I66b91c6d12e6859de33760ab21bb00f1477720e8
Diffstat (limited to 'tests')
-rw-r--r--tests/java/com/android/server/ethernet/EthernetServiceImplTest.java142
1 files changed, 142 insertions, 0 deletions
diff --git a/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java b/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java
new file mode 100644
index 0000000..9869b82
--- /dev/null
+++ b/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2021 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 com.android.server.ethernet;
+
+import static org.junit.Assert.assertThrows;
+
+import static org.mockito.Mockito.doReturn;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.net.InternalNetworkUpdateRequest;
+import android.net.IpConfiguration;
+import android.net.StaticIpConfiguration;
+
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class EthernetServiceImplTest {
+ private EthernetServiceImpl mEthernetServiceImpl;
+ @Mock private Context mContext;
+ @Mock private PackageManager mPackageManager;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ doReturn(mPackageManager).when(mContext).getPackageManager();
+ mEthernetServiceImpl = new EthernetServiceImpl(mContext);
+ mEthernetServiceImpl.mStarted.set(true);
+ }
+
+ @Test
+ public void testSetConfigurationRejectsWhenEthNotStarted() {
+ mEthernetServiceImpl.mStarted.set(false);
+ assertThrows(IllegalStateException.class, () -> {
+ mEthernetServiceImpl.setConfiguration("" /* iface */, new IpConfiguration());
+ });
+ }
+
+ @Test
+ public void testUpdateConfigurationRejectsWhenEthNotStarted() {
+ mEthernetServiceImpl.mStarted.set(false);
+ assertThrows(IllegalStateException.class, () -> {
+ final InternalNetworkUpdateRequest r =
+ new InternalNetworkUpdateRequest(new StaticIpConfiguration(), null);
+
+ mEthernetServiceImpl.updateConfiguration("" /* iface */, r, null /* listener */);
+ });
+ }
+
+ @Test
+ public void testConnectNetworkRejectsWhenEthNotStarted() {
+ mEthernetServiceImpl.mStarted.set(false);
+ assertThrows(IllegalStateException.class, () -> {
+ mEthernetServiceImpl.connectNetwork("" /* iface */, null /* listener */);
+ });
+ }
+
+ @Test
+ public void testDisconnectNetworkRejectsWhenEthNotStarted() {
+ mEthernetServiceImpl.mStarted.set(false);
+ assertThrows(IllegalStateException.class, () -> {
+ mEthernetServiceImpl.disconnectNetwork("" /* iface */, null /* listener */);
+ });
+ }
+
+ @Test
+ public void testUpdateConfigurationRejectsNullIface() {
+ assertThrows(NullPointerException.class, () -> {
+ final InternalNetworkUpdateRequest r =
+ new InternalNetworkUpdateRequest(new StaticIpConfiguration(), null);
+
+ mEthernetServiceImpl.updateConfiguration(null /* iface */, r, null /* listener */);
+ });
+ }
+
+ @Test
+ public void testConnectNetworkRejectsNullIface() {
+ assertThrows(NullPointerException.class, () -> {
+ mEthernetServiceImpl.connectNetwork(null /* iface */, null /* listener */);
+ });
+ }
+
+ @Test
+ public void testDisconnectNetworkRejectsNullIface() {
+ assertThrows(NullPointerException.class, () -> {
+ mEthernetServiceImpl.disconnectNetwork(null /* iface */, null /* listener */);
+ });
+ }
+
+ @Test
+ public void testUpdateConfigurationRejectsWithoutAutomotiveFeature() {
+ disableAutomotiveFeature();
+ assertThrows(UnsupportedOperationException.class, () -> {
+ final InternalNetworkUpdateRequest r =
+ new InternalNetworkUpdateRequest(new StaticIpConfiguration(), null);
+
+ mEthernetServiceImpl.updateConfiguration("" /* iface */, r, null /* listener */);
+ });
+ }
+
+ @Test
+ public void testConnectNetworkRejectsWithoutAutomotiveFeature() {
+ disableAutomotiveFeature();
+ assertThrows(UnsupportedOperationException.class, () -> {
+ mEthernetServiceImpl.connectNetwork("" /* iface */, null /* listener */);
+ });
+ }
+
+ @Test
+ public void testDisconnectNetworkRejectsWithoutAutomotiveFeature() {
+ disableAutomotiveFeature();
+ assertThrows(UnsupportedOperationException.class, () -> {
+ mEthernetServiceImpl.disconnectNetwork("" /* iface */, null /* listener */);
+ });
+ }
+
+ private void disableAutomotiveFeature() {
+ doReturn(false).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
+ }
+}