• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016, 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 com.android.managedprovisioning.parser;
17 
18 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE;
19 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE;
20 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE;
21 
22 import static org.mockito.Mockito.doReturn;
23 import static org.mockito.Mockito.spy;
24 
25 import android.content.ComponentName;
26 import android.content.Context;
27 import android.os.UserHandle;
28 import android.test.AndroidTestCase;
29 import android.test.suitebuilder.annotation.SmallTest;
30 
31 import com.android.managedprovisioning.common.SettingsFacade;
32 import com.android.managedprovisioning.common.Utils;
33 
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 
37 /** Tests {@link MessageParser} */
38 @SmallTest
39 public class MessageParserTest extends AndroidTestCase {
40     private static final String TEST_PACKAGE_NAME = "com.afwsamples.testdpc";
41     private static final ComponentName TEST_COMPONENT_NAME =
42             ComponentName.unflattenFromString(
43                     "com.afwsamples.testdpc/com.afwsamples.testdpc.DeviceAdminReceiver");
44 
45     @Mock
46     private Context mContext;
47 
48     private Utils mUtils;
49 
50     private MessageParser mMessageParser;
51 
52     @Override
setUp()53     public void setUp() {
54         // this is necessary for mockito to work
55         System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());
56 
57         MockitoAnnotations.initMocks(this);
58         mUtils = spy(new Utils());
59         mMessageParser = new MessageParser(
60                 mContext, mUtils, new ParserUtils(), new SettingsFacade());
61     }
62 
test_correctParserUsedToParseOtherSupportedProvisioningIntent()63     public void test_correctParserUsedToParseOtherSupportedProvisioningIntent() throws Exception {
64         // GIVEN the device admin app is installed.
65         doReturn(TEST_COMPONENT_NAME)
66                 .when(mUtils)
67                 .findDeviceAdmin(null, TEST_COMPONENT_NAME, mContext, UserHandle.myUserId());
68         // GIVEN a list of supported provisioning actions, except NFC.
69         String[] supportedProvisioningActions = new String[] {
70                 ACTION_PROVISION_MANAGED_DEVICE,
71                 ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE,
72                 ACTION_PROVISION_MANAGED_PROFILE
73         };
74 
75         for (String provisioningAction : supportedProvisioningActions) {
76             // WHEN the mMessageParser.getParser is invoked.
77             ProvisioningDataParser parser = mMessageParser.getParser();
78 
79             // THEN the extras parser is returned.
80             assertTrue(parser instanceof ExtrasProvisioningDataParser);
81         }
82     }
83 }
84