Add more test cases

revert-dabc3590
charitha 7 years ago
parent cafdeaef48
commit baa30d39a3

@ -18,7 +18,6 @@
package org.wso2.carbon.mdm.services.android; package org.wso2.carbon.mdm.services.android;
import org.mockito.Matchers;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PowerMockIgnore;
@ -31,16 +30,15 @@ import org.testng.annotations.ObjectFactory;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.mdm.services.android.mocks.DeviceManagementProviderServiceMock;
import org.wso2.carbon.mdm.services.android.services.impl.DeviceManagementAdminServiceImpl; import org.wso2.carbon.mdm.services.android.services.impl.DeviceManagementAdminServiceImpl;
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
import org.wso2.carbon.mdm.services.android.utils.TestUtils; import org.wso2.carbon.mdm.services.android.utils.TestUtils;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@PowerMockIgnore({"javax.ws.rs.*"}) @PowerMockIgnore({"javax.ws.rs.*", "org.apache.log4j.*"})
@PrepareForTest(AndroidAPIUtils.class) @PrepareForTest(AndroidAPIUtils.class)
public class DeviceManagementAdminServiceTests { public class DeviceManagementAdminServiceTests {
@ -57,23 +55,17 @@ public class DeviceManagementAdminServiceTests {
deviceManagementAdminService = new DeviceManagementAdminServiceImpl(); deviceManagementAdminService = new DeviceManagementAdminServiceImpl();
} }
private void mockAndroidAPIUtils() private void mockDeviceManagementService()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
Activity activity = TestUtils.getActivity();
PowerMockito.mockStatic(AndroidAPIUtils.class); PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService"))
.toReturn(new DeviceManagementProviderServiceMock());
try {
PowerMockito.when(AndroidAPIUtils.class, "getOperationResponse", Matchers.anyList(), Matchers.any(Operation.class))
.thenReturn(activity);
} catch (Exception e) {
e.printStackTrace();
}
} }
@Test @Test
public void testConfigureDeviceLock() public void testConfigureDeviceLock()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.configureDeviceLock(TestUtils.getDeviceLockBeanWrapper()); Response response = deviceManagementAdminService.configureDeviceLock(TestUtils.getDeviceLockBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -82,7 +74,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testConfigureDeviceUnlock() public void testConfigureDeviceUnlock()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.configureDeviceUnlock(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.configureDeviceUnlock(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -91,7 +83,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testGetDeviceLocation() public void testGetDeviceLocation()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.getDeviceLocation(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.getDeviceLocation(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -100,7 +92,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testRemovePassword() public void testRemovePassword()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.removePassword(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.removePassword(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -109,7 +101,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testConfigureCamera() public void testConfigureCamera()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.configureCamera(TestUtils.getCamerabeanWrapper()); Response response = deviceManagementAdminService.configureCamera(TestUtils.getCamerabeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -118,7 +110,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testGetDeviceInformation() public void testGetDeviceInformation()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.getDeviceInformation(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.getDeviceInformation(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -127,7 +119,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testGetDeviceLogcat() public void testGetDeviceLogcat()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.getDeviceLogcat(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.getDeviceLogcat(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -136,7 +128,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testWipeDevice() public void testWipeDevice()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.wipeDevice(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.wipeDevice(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -145,7 +137,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testWipeData() public void testWipeData()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.wipeData(TestUtils.getWipeDataBeanWrapper()); Response response = deviceManagementAdminService.wipeData(TestUtils.getWipeDataBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -154,7 +146,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testGetApplications() public void testGetApplications()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.getApplications(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.getApplications(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -163,7 +155,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testRingDevice() public void testRingDevice()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.ringDevice(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.ringDevice(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -172,7 +164,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testRebootDevice() public void testRebootDevice()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.rebootDevice(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.rebootDevice(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -181,7 +173,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testMuteDevice() public void testMuteDevice()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.muteDevice(TestUtils.getDeviceIds()); Response response = deviceManagementAdminService.muteDevice(TestUtils.getDeviceIds());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -190,7 +182,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testInstallApplication() public void testInstallApplication()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService Response response = deviceManagementAdminService
.installApplication(TestUtils.getApplicationInstallationBeanWrapper()); .installApplication(TestUtils.getApplicationInstallationBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
@ -200,7 +192,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testUpdateApplication() public void testUpdateApplication()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.updateApplication(TestUtils.getApplicationUpdateBeanWrapper()); Response response = deviceManagementAdminService.updateApplication(TestUtils.getApplicationUpdateBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -209,7 +201,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testUninstallApplicationPublic() public void testUninstallApplicationPublic()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService Response response = deviceManagementAdminService
.uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperPublic()); .uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperPublic());
Assert.assertNotNull(response); Assert.assertNotNull(response);
@ -219,7 +211,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testUninstallApplicationWebApp() public void testUninstallApplicationWebApp()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService Response response = deviceManagementAdminService
.uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperWebApp()); .uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperWebApp());
Assert.assertNotNull(response); Assert.assertNotNull(response);
@ -229,7 +221,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testBlacklistApplications() public void testBlacklistApplications()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService Response response = deviceManagementAdminService
.blacklistApplications(TestUtils.getBlacklistApplicationsBeanWrapper()); .blacklistApplications(TestUtils.getBlacklistApplicationsBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
@ -239,7 +231,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testUpgradeFirmware() public void testUpgradeFirmware()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.upgradeFirmware(TestUtils.getUpgradeFirmwareBeanWrapper()); Response response = deviceManagementAdminService.upgradeFirmware(TestUtils.getUpgradeFirmwareBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -248,7 +240,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testConfigureVPN() public void testConfigureVPN()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.configureVPN(TestUtils.getVpnBeanWrapper()); Response response = deviceManagementAdminService.configureVPN(TestUtils.getVpnBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -257,7 +249,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testSendNotification() public void testSendNotification()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.sendNotification(TestUtils.getNotificationBeanWrapper()); Response response = deviceManagementAdminService.sendNotification(TestUtils.getNotificationBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -266,7 +258,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testConfigureWifi() public void testConfigureWifi()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.configureWifi(TestUtils.getWifiBeanWrapper()); Response response = deviceManagementAdminService.configureWifi(TestUtils.getWifiBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -275,7 +267,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testEncryptStorage() public void testEncryptStorage()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.encryptStorage(TestUtils.getEncryptionBeanWrapper()); Response response = deviceManagementAdminService.encryptStorage(TestUtils.getEncryptionBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -284,7 +276,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testChangeLockCode() public void testChangeLockCode()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.changeLockCode(TestUtils.getLockCodeBeanWrapper()); Response response = deviceManagementAdminService.changeLockCode(TestUtils.getLockCodeBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -293,7 +285,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testSetPasswordPolicy() public void testSetPasswordPolicy()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.setPasswordPolicy(TestUtils.getPasswordPolicyBeanWrapper()); Response response = deviceManagementAdminService.setPasswordPolicy(TestUtils.getPasswordPolicyBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@ -302,7 +294,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testSetWebClip() public void testSetWebClip()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockAndroidAPIUtils(); mockDeviceManagementService();
Response response = deviceManagementAdminService.setWebClip(TestUtils.getWebClipBeanWrapper()); Response response = deviceManagementAdminService.setWebClip(TestUtils.getWebClipBeanWrapper());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());

@ -0,0 +1,250 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.mdm.services.android;
import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.testng.PowerMockObjectFactory;
import org.testng.Assert;
import org.testng.IObjectFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.ObjectFactory;
import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice;
import org.wso2.carbon.mdm.services.android.mocks.ApplicationManagementProviderServiceMock;
import org.wso2.carbon.mdm.services.android.mocks.DeviceInformationManagerServiceMock;
import org.wso2.carbon.mdm.services.android.mocks.DeviceManagementProviderServiceMock;
import org.wso2.carbon.mdm.services.android.mocks.NotificationManagementServiceMock;
import org.wso2.carbon.mdm.services.android.mocks.PolicyManagerServiceMock;
import org.wso2.carbon.mdm.services.android.services.impl.DeviceManagementServiceImpl;
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
import org.wso2.carbon.mdm.services.android.utils.TestUtils;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@PowerMockIgnore({"javax.ws.rs.*", "org.apache.log4j.*"})
@PrepareForTest(AndroidAPIUtils.class)
public class DeviceManagementServiceTests {
private DeviceManagementServiceImpl deviceManagementService;
@ObjectFactory
public IObjectFactory getObjectFactory() {
return new PowerMockObjectFactory();
}
@BeforeClass
public void init() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
MockitoAnnotations.initMocks(this);
deviceManagementService = new DeviceManagementServiceImpl();
}
private void mockDeviceManagementService()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService"))
.toReturn(new DeviceManagementProviderServiceMock());
}
private void mockApplicationManagerService()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getApplicationManagerService"))
.toReturn(new ApplicationManagementProviderServiceMock());
}
private void mockPolicyManagerService()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getPolicyManagerService"))
.toReturn(new PolicyManagerServiceMock());
}
private void mockDeviceInformationManagerService()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceInformationManagerService"))
.toReturn(new DeviceInformationManagerServiceMock());
}
private void mockNotificationManagementService()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getNotificationManagementService"))
.toReturn(new NotificationManagementServiceMock());
}
private void mockUser()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getAuthenticatedUser"))
.toReturn("admin");
}
@Test
public void testUpdateApplicationList()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockApplicationManagerService();
Response response = deviceManagementService
.updateApplicationList(TestUtils.getDeviceId(), TestUtils.getAndroidApplications());
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode());
}
@Test
public void testGetPendingOperationsForNullDevice()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
Response response = deviceManagementService
.getPendingOperations(null, null, null);
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
}
@Test
public void testGetPendingOperationsInvalidDevice()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
Response response = deviceManagementService
.getPendingOperations("1234", null, null);
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
@Test
public void testGetPendingOperationsNullResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
Response response = deviceManagementService
.getPendingOperations(TestUtils.getDeviceId(), null, null);
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
}
@Test
public void testGetPendingOperationsWithMonitorResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
mockPolicyManagerService();
Response response = deviceManagementService
.getPendingOperations(TestUtils.getDeviceId(), null,
TestUtils.getSuccessMonitorOperationResponse());
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
}
@Test
public void testGetPendingOperationsWithApplicationResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
mockApplicationManagerService();
Response response = deviceManagementService
.getPendingOperations(TestUtils.getDeviceId(), null,
TestUtils.getSuccessApplicationOperationResponse());
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
}
@Test
public void testGetPendingOperationsWithDeviceInfoResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
mockDeviceInformationManagerService();
Response response = deviceManagementService
.getPendingOperations(TestUtils.getDeviceId(), null,
TestUtils.getSuccessInfoOperationResponse());
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
}
@Test
public void testGetPendingOperationsWithInProgressResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
Response response = deviceManagementService
.getPendingOperations(TestUtils.getDeviceId(), null,
TestUtils.getInProgressOperationResponse());
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
}
@Test
public void testGetPendingOperationsWithErrorResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
mockNotificationManagementService();
Response response = deviceManagementService
.getPendingOperations(TestUtils.getDeviceId(), null,
TestUtils.getErrorOperationResponse());
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
}
@Test
public void testEnrollDeviceWithoutLocationSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
mockPolicyManagerService();
mockUser();
Response response = deviceManagementService.enrollDevice(TestUtils.getBasicAndroidDevice());
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
}
@Test
public void testEnrollDeviceWithLocationSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
mockDeviceInformationManagerService();
mockPolicyManagerService();
mockUser();
AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice();
List<Device.Property> properties = new ArrayList<>();
Device.Property property = new Device.Property();
property.setName("LATITUDE");
property.setValue("79.5");
properties.add(property);
property = new Device.Property();
property.setName("LONGITUDE");
property.setValue("6.9");
properties.add(property);
androidDevice.setProperties(properties);
Response response = deviceManagementService.enrollDevice(androidDevice);
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
}
@Test
public void testEnrollDeviceUnSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
mockUser();
AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice();
androidDevice.setDeviceIdentifier("1234");
Response response = deviceManagementService.enrollDevice(androidDevice);
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}

@ -0,0 +1,77 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.mdm.services.android.mocks;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import java.util.List;
public class ApplicationManagementProviderServiceMock implements ApplicationManagementProviderService {
@Override
public void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier, List<Application> list)
throws ApplicationManagementException {
}
@Override
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
throws ApplicationManagementException {
return null;
}
@Override
public Application[] getApplications(String s, int i, int i1) throws ApplicationManagementException {
return new Application[0];
}
@Override
public void updateApplicationStatus(DeviceIdentifier deviceIdentifier, Application application, String s)
throws ApplicationManagementException {
}
@Override
public String getApplicationStatus(DeviceIdentifier deviceIdentifier, Application application)
throws ApplicationManagementException {
return null;
}
@Override
public Activity installApplicationForDevices(Operation operation, List<DeviceIdentifier> list)
throws ApplicationManagementException {
return null;
}
@Override
public Activity installApplicationForUsers(Operation operation, List<String> list)
throws ApplicationManagementException {
return null;
}
@Override
public Activity installApplicationForUserRoles(Operation operation, List<String> list)
throws ApplicationManagementException {
return null;
}
}

@ -0,0 +1,42 @@
package org.wso2.carbon.mdm.services.android.mocks;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import java.util.List;
public class DeviceInformationManagerServiceMock implements DeviceInformationManager {
@Override
public void addDeviceInfo(DeviceIdentifier deviceIdentifier, DeviceInfo deviceInfo)
throws DeviceDetailsMgtException {
}
@Override
public DeviceInfo getDeviceInfo(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException {
return null;
}
@Override
public List<DeviceInfo> getDevicesInfo(List<DeviceIdentifier> list) throws DeviceDetailsMgtException {
return null;
}
@Override
public void addDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException {
}
@Override
public DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException {
return null;
}
@Override
public List<DeviceLocation> getDeviceLocations(List<DeviceIdentifier> list) throws DeviceDetailsMgtException {
return null;
}
}

@ -0,0 +1,500 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.mdm.services.android.mocks;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
import org.wso2.carbon.mdm.services.android.utils.TestUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
public class DeviceManagementProviderServiceMock implements DeviceManagementProviderService {
@Override
public List<Device> getAllDevices(String s) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getAllDevices(String s, boolean b) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
return null;
}
@Override
public List<Device> getAllDevices(boolean b) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getDevices(Date date) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getDevices(Date date, boolean b) throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesByType(PaginationRequest paginationRequest) throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesByType(PaginationRequest paginationRequest, boolean b)
throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getAllDevices(PaginationRequest paginationRequest) throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getAllDevices(PaginationRequest paginationRequest, boolean b)
throws DeviceManagementException {
return null;
}
@Override
public Device getDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return null;
}
@Override
public Device getDeviceWithTypeProperties(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return null;
}
@Override
public Device getDevice(DeviceIdentifier deviceIdentifier, boolean b) throws DeviceManagementException {
if (TestUtils.getDeviceId().equals(deviceIdentifier.getId())) {
return TestUtils.getDevice();
} else {
return null;
}
}
@Override
public Device getDevice(DeviceIdentifier deviceIdentifier, String s, boolean b) throws DeviceManagementException {
return null;
}
@Override
public Device getDevice(DeviceIdentifier deviceIdentifier, Date date) throws DeviceManagementException {
return null;
}
@Override
public Device getDevice(DeviceIdentifier deviceIdentifier, Date date, boolean b) throws DeviceManagementException {
return null;
}
@Override
public Device getDevice(DeviceIdentifier deviceIdentifier, String s, Date date, boolean b)
throws DeviceManagementException {
return null;
}
@Override
public Device getDevice(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status)
throws DeviceManagementException {
return null;
}
@Override
public Device getDevice(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status, boolean b)
throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesOfUser(PaginationRequest paginationRequest) throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesOfUser(PaginationRequest paginationRequest, boolean b)
throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesByOwnership(PaginationRequest paginationRequest)
throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesByOwnership(PaginationRequest paginationRequest, boolean b)
throws DeviceManagementException {
return null;
}
@Override
public List<Device> getDevicesOfUser(String s) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getDevicesOfUser(String s, boolean b) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getDevicesOfUser(String s, String s1) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getDevicesOfUser(String s, String s1, boolean b) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getAllDevicesOfRole(String s) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getAllDevicesOfRole(String s, boolean b) throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesByStatus(PaginationRequest paginationRequest) throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesByStatus(PaginationRequest paginationRequest, boolean b)
throws DeviceManagementException {
return null;
}
@Override
public List<Device> getDevicesByNameAndType(PaginationRequest paginationRequest, boolean b)
throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesByName(PaginationRequest paginationRequest) throws DeviceManagementException {
return null;
}
@Override
public PaginationResult getDevicesByName(PaginationRequest paginationRequest, boolean b)
throws DeviceManagementException {
return null;
}
@Override
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException {
return null;
}
@Override
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status, boolean b) throws DeviceManagementException {
return null;
}
@Override
public int getDeviceCount(String s) throws DeviceManagementException {
return 0;
}
@Override
public int getDeviceCount() throws DeviceManagementException {
return 0;
}
@Override
public HashMap<Integer, Device> getTenantedDevice(DeviceIdentifier deviceIdentifier)
throws DeviceManagementException {
return null;
}
@Override
public void sendEnrolmentInvitation(String s, EmailMetaInfo emailMetaInfo)
throws DeviceManagementException, ConfigurationManagementException {
}
@Override
public void sendRegistrationEmail(EmailMetaInfo emailMetaInfo)
throws DeviceManagementException, ConfigurationManagementException {
}
@Override
public FeatureManager getFeatureManager(String s) throws DeviceManagementException {
return null;
}
@Override
public PlatformConfiguration getConfiguration(String s) throws DeviceManagementException {
return null;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceIdentifier, String s) throws DeviceManagementException {
return false;
}
@Override
public NotificationStrategy getNotificationStrategyByDeviceType(String s) throws DeviceManagementException {
return null;
}
@Override
public License getLicense(String s, String s1) throws DeviceManagementException {
return null;
}
@Override
public void addLicense(String s, License license) throws DeviceManagementException {
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
return TestUtils.getDeviceId().equals(device.getDeviceIdentifier());
}
@Override
public boolean saveConfiguration(PlatformConfiguration platformConfiguration) throws DeviceManagementException {
return false;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override
public boolean isActive(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override
public boolean setActive(DeviceIdentifier deviceIdentifier, boolean b) throws DeviceManagementException {
return false;
}
@Override
public List<String> getAvailableDeviceTypes() throws DeviceManagementException {
return null;
}
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean setOwnership(DeviceIdentifier deviceIdentifier, String s) throws DeviceManagementException {
return false;
}
@Override
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override
public boolean setStatus(DeviceIdentifier deviceIdentifier, String s, EnrolmentInfo.Status status)
throws DeviceManagementException {
return false;
}
@Override
public boolean setStatus(String s, EnrolmentInfo.Status status) throws DeviceManagementException {
return false;
}
@Override
public void notifyOperationToDevices(Operation operation, List<DeviceIdentifier> list)
throws DeviceManagementException {
}
@Override
public Activity addOperation(String s, Operation operation, List<DeviceIdentifier> list)
throws OperationManagementException, InvalidDeviceException {
return TestUtils.getActivity();
}
@Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceIdentifier)
throws OperationManagementException {
return null;
}
@Override
public PaginationResult getOperations(DeviceIdentifier deviceIdentifier, PaginationRequest paginationRequest)
throws OperationManagementException {
return null;
}
@Override
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
throws OperationManagementException {
return null;
}
@Override
public Operation getNextPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
return null;
}
@Override
public void updateOperation(DeviceIdentifier deviceIdentifier, Operation operation)
throws OperationManagementException {
}
@Override
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceIdentifier, int i)
throws OperationManagementException {
return null;
}
@Override
public List<? extends Operation> getOperationsByDeviceAndStatus(DeviceIdentifier deviceIdentifier,
Operation.Status status)
throws OperationManagementException, DeviceManagementException {
return null;
}
@Override
public Operation getOperation(String s, int i) throws OperationManagementException {
return null;
}
@Override
public Activity getOperationByActivityId(String s) throws OperationManagementException {
return null;
}
@Override
public Activity getOperationByActivityIdAndDevice(String s, DeviceIdentifier deviceIdentifier)
throws OperationManagementException {
return null;
}
@Override
public List<Activity> getActivitiesUpdatedAfter(long l, int i, int i1) throws OperationManagementException {
return null;
}
@Override
public int getActivityCountUpdatedAfter(long l) throws OperationManagementException {
return 0;
}
@Override
public List<MonitoringOperation> getMonitoringOperationList(String s) {
return null;
}
@Override
public int getDeviceMonitoringFrequency(String s) {
return 0;
}
@Override
public boolean isDeviceMonitoringEnabled(String s) {
return false;
}
@Override
public PolicyMonitoringManager getPolicyMonitoringManager(String s) {
return null;
}
@Override
public boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status)
throws DeviceManagementException {
return false;
}
@Override
public void registerDeviceType(DeviceManagementService deviceManagementService) throws DeviceManagementException {
}
@Override
public DeviceType getDeviceType(String s) throws DeviceManagementException {
return null;
}
@Override
public List<DeviceType> getDeviceTypes() throws DeviceManagementException {
return null;
}
@Override
public void notifyPullNotificationSubscriber(DeviceIdentifier deviceIdentifier, Operation operation)
throws PullNotificationExecutionFailedException {
}
@Override
public List<Integer> getDeviceEnrolledTenants() throws DeviceManagementException {
return null;
}
}

@ -0,0 +1,56 @@
package org.wso2.carbon.mdm.services.android.mocks;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
import java.util.List;
public class NotificationManagementServiceMock implements NotificationManagementService {
@Override
public boolean addNotification(DeviceIdentifier deviceIdentifier, Notification notification)
throws NotificationManagementException {
return false;
}
@Override
public boolean updateNotification(Notification notification) throws NotificationManagementException {
return false;
}
@Override
public boolean updateNotificationStatus(int i, Notification.Status status) throws NotificationManagementException {
return false;
}
@Override
public List<Notification> getAllNotifications() throws NotificationManagementException {
return null;
}
@Override
public Notification getNotification(int i) throws NotificationManagementException {
return null;
}
@Override
public PaginationResult getAllNotifications(PaginationRequest paginationRequest)
throws NotificationManagementException {
return null;
}
@Override
public List<Notification> getNotificationsByStatus(Notification.Status status)
throws NotificationManagementException {
return null;
}
@Override
public PaginationResult getNotificationsByStatus(Notification.Status status, PaginationRequest paginationRequest)
throws NotificationManagementException {
return null;
}
}

@ -0,0 +1,142 @@
package org.wso2.carbon.mdm.services.android.mocks;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.
*/
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
import java.util.List;
public class PolicyManagerServiceMock implements PolicyManagerService {
@Override
public Profile addProfile(Profile profile) throws PolicyManagementException {
return null;
}
@Override
public Profile updateProfile(Profile profile) throws PolicyManagementException {
return null;
}
@Override
public Policy addPolicy(Policy policy) throws PolicyManagementException {
return null;
}
@Override
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
return null;
}
@Override
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
return false;
}
@Override
public boolean deletePolicy(int i) throws PolicyManagementException {
return false;
}
@Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return null;
}
@Override
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier)
throws FeatureManagementException {
return null;
}
@Override
public List<Policy> getPolicies(String s) throws PolicyManagementException {
return null;
}
@Override
public List<Feature> getFeatures() throws FeatureManagementException {
return null;
}
@Override
public PolicyAdministratorPoint getPAP() throws PolicyManagementException {
return null;
}
@Override
public PolicyInformationPoint getPIP() throws PolicyManagementException {
return null;
}
@Override
public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
return null;
}
@Override
public TaskScheduleService getTaskScheduleService() throws PolicyMonitoringTaskException {
return null;
}
@Override
public int getPolicyCount() throws PolicyManagementException {
return 0;
}
@Override
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return null;
}
@Override
public List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Object o)
throws PolicyComplianceException {
return null;
}
@Override
public boolean checkCompliance(DeviceIdentifier deviceIdentifier, Object o) throws PolicyComplianceException {
return false;
}
@Override
public NonComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
return null;
}
@Override
public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
return false;
}
}

@ -18,7 +18,14 @@
package org.wso2.carbon.mdm.services.android.utils; package org.wso2.carbon.mdm.services.android.utils;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.mdm.services.android.bean.ApplicationInstallation; import org.wso2.carbon.mdm.services.android.bean.ApplicationInstallation;
import org.wso2.carbon.mdm.services.android.bean.ApplicationUninstallation; import org.wso2.carbon.mdm.services.android.bean.ApplicationUninstallation;
import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate; import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate;
@ -34,6 +41,8 @@ import org.wso2.carbon.mdm.services.android.bean.Vpn;
import org.wso2.carbon.mdm.services.android.bean.WebClip; import org.wso2.carbon.mdm.services.android.bean.WebClip;
import org.wso2.carbon.mdm.services.android.bean.Wifi; import org.wso2.carbon.mdm.services.android.bean.Wifi;
import org.wso2.carbon.mdm.services.android.bean.WipeData; import org.wso2.carbon.mdm.services.android.bean.WipeData;
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidApplication;
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice;
import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationInstallationBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationInstallationBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUninstallationBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUninstallationBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUpdateBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUpdateBeanWrapper;
@ -49,6 +58,8 @@ import org.wso2.carbon.mdm.services.android.bean.wrapper.VpnBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.WebClipBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.WebClipBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.WifiBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.WifiBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.WipeDataBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.WipeDataBeanWrapper;
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -62,12 +73,31 @@ public class TestUtils {
return activity; return activity;
} }
public static String getDeviceId() {
return "1a2b3c4d5e";
}
public static List<String> getDeviceIds() { public static List<String> getDeviceIds() {
List<String> deviceIds = new ArrayList<>(); List<String> deviceIds = new ArrayList<>();
deviceIds.add("1a2b3c4d5e"); deviceIds.add(getDeviceId());
return deviceIds; return deviceIds;
} }
public static Device getDevice() {
Device device = new Device();
device.setId(1);
device.setName("Test");
device.setDeviceIdentifier(getDeviceId());
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setId(1);
enrolmentInfo.setOwner("admin");
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
device.setEnrolmentInfo(enrolmentInfo);
return device;
}
public static DeviceLockBeanWrapper getDeviceLockBeanWrapper() { public static DeviceLockBeanWrapper getDeviceLockBeanWrapper() {
DeviceLockBeanWrapper deviceLockBeanWrapper = new DeviceLockBeanWrapper(); DeviceLockBeanWrapper deviceLockBeanWrapper = new DeviceLockBeanWrapper();
deviceLockBeanWrapper.setDeviceIDs(getDeviceIds()); deviceLockBeanWrapper.setDeviceIDs(getDeviceIds());
@ -221,4 +251,118 @@ public class TestUtils {
return webClipBeanWrapper; return webClipBeanWrapper;
} }
public static List<AndroidApplication> getAndroidApplications() {
List<AndroidApplication> androidApplications = new ArrayList<>();
AndroidApplication androidApplication = new AndroidApplication();
androidApplications.add(androidApplication);
return androidApplications;
}
public static List<Operation> getSuccessMonitorOperationResponse() {
List<Operation> operations = new ArrayList<>();
Operation operation = new Operation();
operation.setActivityId(getActivity().getActivityId());
operation.setCode(AndroidConstants.OperationCodes.MONITOR);
operation.setId(1);
operation.setOperationResponse("Operation success.");
operation.setStatus(Operation.Status.COMPLETED);
operations.add(operation);
return operations;
}
public static List<Operation> getSuccessApplicationOperationResponse() {
List<Operation> operations = new ArrayList<>();
Operation operation = new Operation();
operation.setActivityId(getActivity().getActivityId());
operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST);
operation.setId(1);
operation.setOperationResponse("[{\"name\":\"Widget%20Preview\",\"package\":\"com.android.widgetpreview\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"com.android.gesture.builder\",\"package\":\"com.android.gesture.builder\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"API%20Demos\",\"package\":\"com.example.android.apis\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"WSO2%20Device%20Management%20Agent\",\"package\":\"org.wso2.iot.agent\",\"version\":\"3.1.21\",\"isSystemApp\":false,\"isActive\":true},{\"name\":\"com.android.smoketest.tests\",\"package\":\"com.android.smoketest.tests\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"Sample%20Soft%20Keyboard\",\"package\":\"com.example.android.softkeyboard\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"Example%20Wallpapers\",\"package\":\"com.example.android.livecubes\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"com.android.smoketest\",\"package\":\"com.android.smoketest\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false}]");
operation.setStatus(Operation.Status.COMPLETED);
operations.add(operation);
return operations;
}
public static List<Operation> getSuccessInfoOperationResponse() {
List<Operation> operations = new ArrayList<>();
Operation operation = new Operation();
operation.setActivityId(getActivity().getActivityId());
operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO);
operation.setId(1);
operation.setOperationResponse("{\"description\":\"generic_x86\",\"deviceIdentifier\":\"1d9612def9d205f9\",\"enrolmentInfo\":null,\"name\":\"generic_x86\",\"properties\":[{\"name\":\"SERIAL\",\"value\":\"unknown\"},{\"name\":\"IMEI\",\"value\":null},{\"name\":\"IMSI\",\"value\":\"310260000000000\"},{\"name\":\"MAC\",\"value\":\"02:00:00:00:00:00\"},{\"name\":\"DEVICE_MODEL\",\"value\":\"Android SDK built for x86\"},{\"name\":\"VENDOR\",\"value\":\"unknown\"},{\"name\":\"OS_VERSION\",\"value\":\"7.1.1\"},{\"name\":\"OS_BUILD_DATE\",\"value\":\"1487782847000\"},{\"name\":\"DEVICE_NAME\",\"value\":\"generic_x86\"},{\"name\":\"LATITUDE\",\"value\":\"6.90988\"},{\"name\":\"LONGITUDE\",\"value\":\"79.85249999999999\"},{\"name\":\"NETWORK_INFO\",\"value\":\"[{\\\"name\\\":\\\"CONNECTION_TYPE\\\",\\\"value\\\":\\\"MOBILE\\\"},{\\\"name\\\":\\\"MOBILE_CONNECTION_TYPE\\\",\\\"value\\\":\\\"LTE\\\"},{\\\"name\\\":\\\"MOBILE_SIGNAL_STRENGTH\\\",\\\"value\\\":\\\"-89\\\"}]\"},{\"name\":\"CPU_INFO\",\"value\":\"[]\"},{\"name\":\"RAM_INFO\",\"value\":\"[{\\\"name\\\":\\\"TOTAL_MEMORY\\\",\\\"value\\\":\\\"1055113216\\\"},{\\\"name\\\":\\\"AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"708997120\\\"},{\\\"name\\\":\\\"THRESHOLD\\\",\\\"value\\\":\\\"150994944\\\"},{\\\"name\\\":\\\"LOW_MEMORY\\\",\\\"value\\\":\\\"false\\\"}]\"},{\"name\":\"BATTERY_INFO\",\"value\":\"[{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"},{\\\"name\\\":\\\"SCALE\\\",\\\"value\\\":\\\"100\\\"},{\\\"name\\\":\\\"BATTERY_VOLTAGE\\\",\\\"value\\\":\\\"0\\\"},{\\\"name\\\":\\\"HEALTH\\\",\\\"value\\\":\\\"GOOD_CONDITION\\\"},{\\\"name\\\":\\\"STATUS\\\",\\\"value\\\":\\\"null\\\"},{\\\"name\\\":\\\"PLUGGED\\\",\\\"value\\\":\\\"AC\\\"}]\"},{\"name\":\"DEVICE_INFO\",\"value\":\"[{\\\"name\\\":\\\"ENCRYPTION_ENABLED\\\",\\\"value\\\":\\\"false\\\"},{\\\"name\\\":\\\"PASSCODE_ENABLED\\\",\\\"value\\\":\\\"true\\\"},{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"},{\\\"name\\\":\\\"INTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.76\\\"},{\\\"name\\\":\\\"INTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.67\\\"},{\\\"name\\\":\\\"EXTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"},{\\\"name\\\":\\\"EXTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"},{\\\"name\\\":\\\"OPERATOR\\\",\\\"value\\\":\\\"Android\\\"},{\\\"name\\\":\\\"PHONE_NUMBER\\\",\\\"value\\\":\\\"15555215554\\\"}]\"}]}");
operation.setStatus(Operation.Status.COMPLETED);
operations.add(operation);
return operations;
}
public static List<Operation> getInProgressOperationResponse() {
List<Operation> operations = new ArrayList<>();
Operation operation = new Operation();
operation.setActivityId(getActivity().getActivityId());
operation.setCode(AndroidConstants.OperationCodes.NOTIFICATION);
operation.setId(1);
operation.setOperationResponse("Operation in progress.");
operation.setStatus(Operation.Status.IN_PROGRESS);
operations.add(operation);
return operations;
}
public static List<Operation> getErrorOperationResponse() {
List<Operation> operations = new ArrayList<>();
Operation operation = new Operation();
operation.setActivityId(getActivity().getActivityId());
operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO);
operation.setId(1);
operation.setOperationResponse("Operation failure.");
operation.setStatus(Operation.Status.ERROR);
operations.add(operation);
return operations;
}
public static DeviceLocation getDeviceLocation() {
DeviceLocation location = new DeviceLocation();
location.setCity("Colombo");
location.setCountry("Sri Lanka");
location.setLatitude(6.9);
location.setLongitude(79.5);
location.setDeviceIdentifier(AndroidDeviceUtils.convertToDeviceIdentifierObject(getDeviceId()));
return location;
}
public static DeviceInfo getDeviceInfo() {
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setDeviceModel("nexus");
deviceInfo.setAvailableRAMMemory(2.0);
deviceInfo.setBatteryLevel(100.0);
deviceInfo.setConnectionType("4G");
deviceInfo.setCpuUsage(1.0);
deviceInfo.setExternalAvailableMemory(2.3);
deviceInfo.setExternalTotalMemory(4.0);
deviceInfo.setInternalAvailableMemory(1.0);
deviceInfo.setInternalTotalMemory(4.0);
deviceInfo.setLocation(getDeviceLocation());
return deviceInfo;
}
public static List<Application> getApplications() {
List<Application> applications = new ArrayList<>();
Application app = new Application();
app.setName("WSO2 IoT Agent");
app.setApplicationIdentifier("org.wos2.iot.agent");
app.setVersion("1.0.0");
app.setPlatform("Android");
applications.add(app);
return applications;
}
public static AndroidDevice getBasicAndroidDevice() {
AndroidDevice androidDevice = new AndroidDevice();
androidDevice.setName(getDevice().getName());
androidDevice.setDescription(getDevice().getDescription());
androidDevice.setDeviceIdentifier(getDeviceId());
androidDevice.setDeviceInfo(getDeviceInfo());
androidDevice.setApplications(getApplications());
androidDevice.setEnrolmentInfo(getDevice().getEnrolmentInfo());
return androidDevice;
}
} }

@ -24,6 +24,7 @@
<test name="API Tests" preserve-order="true"> <test name="API Tests" preserve-order="true">
<classes> <classes>
<class name="org.wso2.carbon.mdm.services.android.DeviceManagementAdminServiceTests" /> <class name="org.wso2.carbon.mdm.services.android.DeviceManagementAdminServiceTests" />
<class name="org.wso2.carbon.mdm.services.android.DeviceManagementServiceTests" />
</classes> </classes>
</test> </test>
</suite> </suite>

Loading…
Cancel
Save