Removing some hack used to workaround issues that popped up while writing unit tests upon tenant-enabled code

revert-70aa11f8
prabathabey 9 years ago
parent 15d56e29c3
commit e4fd0607e8

@ -180,10 +180,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
@Override
public void updateApplicationListInstalledInDevice(
DeviceIdentifier deviceIdentifier, List<Application> applications) throws ApplicationManagementException {
int tenantId = getTenantId();
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManagementDAOFactory.beginTransaction();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
@ -248,30 +246,17 @@ 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 {
public List<Application> getApplicationListForDevice(
DeviceIdentifier deviceId) throws ApplicationManagementException {
Device device = null;
try {
int tenantId = getTenantId();
device = deviceDAO.getDevice(deviceIdentifier, tenantId);
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
device = deviceDAO.getDevice(deviceId, tenantId);
return applicationDAO.getInstalledApplications(device.getId());
}catch (DeviceManagementDAOException deviceDaoEx) {
String errorMsg = "Error occured while fetching the Application List of device : " + device.getId();
log.error(errorMsg, deviceDaoEx);
throw new ApplicationManagementException(errorMsg, deviceDaoEx);
} catch (DeviceManagementDAOException e) {
throw new ApplicationManagementException("Error occured while fetching the Application List of '" +
deviceId.getType() + "' device carrying the identifier'" + deviceId.getId(), e);
}
}

@ -53,7 +53,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private DeviceTypeDAO deviceTypeDAO;
private EnrolmentDAO enrolmentDAO;
private DeviceManagementPluginRepository pluginRepository;
private boolean isTest = false;
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
private int tenantId;
@ -75,7 +74,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test){
this.pluginRepository = pluginRepo;
initDataAccessObjects();
isTest = test;
}
private void initDataAccessObjects() {
@ -108,7 +106,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} else {
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE);
}
int tenantId = getTenantId();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManagementDAOFactory.beginTransaction();
@ -724,14 +722,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.getConnection();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
allDevices = deviceDAO.getDevicesByStatus(status, tenantId);
} catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while fetching the list of devices that matches to status: '"
+ status + "'";
log.error(errorMsg, e);
throw new DeviceManagementException(errorMsg, e);
throw new DeviceManagementException(
"Error occurred while fetching the list of devices that matches to status: '" + status + "'", e);
} finally {
try {
DeviceManagementDAOFactory.closeConnection();
} catch (DeviceManagementDAOException e) {
@ -753,19 +747,4 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return devices;
}
private int getTenantId() {
ThreadLocal<Integer> tenantId = new ThreadLocal<Integer>();
int tenant = 0;
if (isTest){
tenant = DeviceManagerUtil.currentTenant.get();
}else{
tenant = CarbonContext.getThreadLocalCarbonContext().getTenantId();
}
return tenant;
}
}

@ -49,7 +49,6 @@ import java.util.*;
public final class DeviceManagerUtil {
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
public static ThreadLocal<Integer> currentTenant = new ThreadLocal<Integer>();
enum HTTPMethod {
GET, POST, DELETE, PUT, OPTIONS

@ -58,7 +58,6 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
deviceManagementProviderService = new DeviceManagementProviderServiceImpl(deviceManagementPluginRepository,
true);
DeviceManagerUtil.registerDeviceType(TestDataHolder.TEST_DEVICE_TYPE);
DeviceManagerUtil.currentTenant.set(TestDataHolder.SUPER_TENANT_ID);
Device device = TestDataHolder.generateDummyDeviceData(TestDataHolder.TEST_DEVICE_TYPE);
boolean isEnrolled = deviceManagementProviderService.enrollDevice(device);

Loading…
Cancel
Save