Unit tests, application update

revert-70aa11f8
manoj 9 years ago
parent 6daa71771c
commit de17217303

@ -43,10 +43,7 @@ public class DeviceManagementPluginRepository {
throw new DeviceManagementException("Error occurred while adding device management provider '" +
deviceType + "'");
}
providers.put(deviceType, provider);
System.out.println("@plugin Repo:"+deviceType);
System.out.println("@plugin Repo:"+providers.size());
}
public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
@ -55,7 +52,6 @@ public class DeviceManagementPluginRepository {
}
public DeviceManagementService getDeviceManagementService(String type) {
System.out.println("@plugin get:"+providers.get(type).toString());
return providers.get(type);
}

@ -41,6 +41,7 @@ import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations;
import org.wso2.carbon.device.mgt.core.dao.*;
import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub;
import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
@ -62,6 +63,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
private DeviceDAO deviceDAO;
private ApplicationDAO applicationDAO;
private ApplicationMappingDAO applicationMappingDAO;
private boolean isTest;
private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1";
@ -88,6 +90,14 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO();
}
ApplicationManagerProviderServiceImpl(DeviceManagementPluginRepository pluginRepository, boolean testMode) {
this.pluginRepository = pluginRepository;
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO();
isTest = testMode;
}
@Override
public Application[] getApplications(String domain, int pageNumber, int size)
throws ApplicationManagementException {
@ -171,7 +181,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
public void updateApplicationListInstalledInDevice(
DeviceIdentifier deviceIdentifier, List<Application> applications) throws ApplicationManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
int tenantId = getTenantId();
try {
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
@ -205,12 +215,24 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
}
}
private int getTenantId() {
int tenantId = 0;
if (isTest){
tenantId = DeviceManagerUtil.currentTenant.get();
}else{
tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
}
return tenantId;
}
@Override
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
throws ApplicationManagementException {
Device device = null;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
int tenantId = getTenantId();
device = deviceDAO.getDevice(deviceIdentifier, tenantId);
return applicationDAO.getInstalledApplications(device.getId());
}catch (DeviceManagementDAOException deviceDaoEx) {

@ -101,8 +101,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
System.out.println("dms________"+device.getType());
boolean status = dms.enrollDevice(device);
try {
if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) {

@ -21,72 +21,64 @@ import org.wso2.carbon.device.mgt.common.*;
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.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
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.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import java.util.List;
public class TestDeviceManagementService implements DeviceManager {
public class TestDeviceManagementService implements DeviceManagementService {
private String providerType;
public TestDeviceManagementService(String deviceType){
providerType = deviceType;
}
@Override public FeatureManager getFeatureManager() {
return null;
@Override
public String getType() {
return providerType;
}
@Override public boolean enrollDevice(Device device) throws DeviceManagementException {
return false;
}
@Override
public void init() throws DeviceManagementException {
@Override public boolean modifyEnrollment(Device device) throws DeviceManagementException {
return false;
}
@Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
@Override
public DeviceManager getDeviceManager() {
return new TestDeviceManager();
}
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
@Override
public ApplicationManager getApplicationManager() {
return null;
}
@Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
@Override
public Application[] getApplications(String domain, int pageNumber, int size)
throws ApplicationManagementException {
return new Application[0];
}
@Override public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
return false;
}
@Override
public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, String status)
throws ApplicationManagementException {
@Override public List<Device> getAllDevices() throws DeviceManagementException {
return null;
}
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
@Override
public String getApplicationStatus(DeviceIdentifier deviceId, Application application)
throws ApplicationManagementException {
return null;
}
@Override public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
throws DeviceManagementException {
return false;
}
@Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException {
return false;
}
@Override public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
}
@Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws ApplicationManagementException {
@Override public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status)
throws DeviceManagementException {
return false;
}
}

@ -101,6 +101,8 @@ public abstract class BaseDeviceManagementTest {
conn.setAutoCommit(false);
this.cleanupEnrolmentData(conn);
this.cleanApplicationMappingData(conn);
this.cleanApplicationData(conn);
this.cleanupDeviceData(conn);
this.cleanupDeviceTypeData(conn);
@ -127,6 +129,31 @@ public abstract class BaseDeviceManagementTest {
}
}
private void cleanApplicationMappingData(Connection conn) throws SQLException{
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement("DELETE FROM DM_DEVICE_APPLICATION_MAPPING");
stmt.execute();
} finally {
if (stmt != null) {
stmt.close();
}
}
}
private void cleanApplicationData(Connection conn) throws SQLException{
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement("DELETE FROM DM_APPLICATION");
stmt.execute();
} finally {
if (stmt != null) {
stmt.close();
}
}
}
private void cleanupEnrolmentData(Connection conn) throws SQLException {
PreparedStatement stmt = null;
try {

@ -14,7 +14,7 @@ public class TestDataHolder {
public static DeviceType initialTestDeviceType;
public static String TEST_DEVICE_TYPE = "Test";
public static Integer SUPER_TENANT_ID = -1234;
public static ThreadLocal<Integer> tenant = new ThreadLocal<Integer>();
public static String initialDeviceIdentifier = "12345";
public static Device generateDummyDeviceData(String deviceType){
@ -30,7 +30,6 @@ public class TestDataHolder {
device.setDeviceIdentifier("12345");
device.setType(deviceType);
return device;
}
public static DeviceType generateDeviceTypeData(String devTypeName){

@ -1,60 +0,0 @@
package org.wso2.carbon.device.mgt.core.service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
public class ApplicationManagementProviderServiceTests extends BaseDeviceManagementTest{
private static final Log log = LogFactory.getLog(ApplicationManagementProviderServiceTests.class);
@BeforeClass
@Override
public void init() throws Exception {
this.initDatSource();
}
@Test
public void testAddApplications() {
/* ArrayList<Application> sourceApplications = new ArrayList<Application>();
sourceApplications.add(TestDataHolder.generateApplicationDummyData("Test App2"));
sourceApplications.add(TestDataHolder.generateApplicationDummyData("Test App3"));
DeviceManagementTests deviceManagementDAOTests = new DeviceManagementTests();
deviceManagementDAOTests.testAddDeviceTest();
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.openConnection();
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while adding application", e);
} finally {
try {
DeviceManagementDAOFactory.closeConnection();
} catch (DeviceManagementDAOException e) {
log.warn("Error occurred while closing the connection", e);
}
}
*//* Retrieving the application by its name *//*
Application target = null;
try {
target = this.getApplication(source.getApplicationIdentifier(), -1234);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving application info";
log.error(msg, e);
Assert.fail(msg, e);
}
Assert.assertEquals(target.getApplicationIdentifier(), source.getApplicationIdentifier(), "Application added is not as same as " +
"what's " +
"retrieved");*/
}
}

@ -26,16 +26,13 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
DeviceManagementProviderService deviceManagementProviderService = null;
@BeforeClass
@Override
public void init() throws Exception {
initDatSource();
}
@Test
@Test
public void testEnrollment() {
try {
@ -46,10 +43,12 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
deviceManagementProviderService = new DeviceManagementProviderServiceImpl(deviceManagementPluginRepository,
true);
DeviceManagerUtil.registerDeviceType(TestDataHolder.TEST_DEVICE_TYPE);
TestDataHolder.tenant.set(TestDataHolder.SUPER_TENANT_ID);
DeviceManagerUtil.currentTenant.set(TestDataHolder.SUPER_TENANT_ID);
Device device = TestDataHolder.generateDummyDeviceData(TestDataHolder.TEST_DEVICE_TYPE);
boolean isEnrolled = deviceManagementProviderService.enrollDevice(device);
Assert.assertEquals(isEnrolled,true,"Enrolment fail");
if (isEnrolled){
TestDataHolder.initialTestDevice = device;
}
@ -69,6 +68,5 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@AfterClass
public void cleanResources(){
// PrivilegedCarbonContext.endTenantFlow();
}
}

@ -18,7 +18,7 @@
-->
<DataSourceConfig>
<Url>jdbc:h2:mem:cdm-test-db;DB_CLOSE_DELAY=-1</Url>
<Url>jdbc:h2:mem:cdm-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true</Url>
<DriverClassName>org.h2.Driver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>

@ -34,6 +34,7 @@
<test name="Service Unit Tests" preserve-order="true">
<classes>
<class name="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceTest"/>
<class name="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServiceTest"/>
</classes>
</test>
</suite>

@ -27,7 +27,6 @@ public class APIMapperContextListener implements LifecycleListener {
@Override
public void lifecycleEvent(LifecycleEvent lifecycleEvent) {
if (Lifecycle.AFTER_INIT_EVENT.equals(lifecycleEvent.getType())) {
System.out.println("Deployeddd");
}
}

Loading…
Cancel
Save