Merge branch 'master' of github.com:wso2/product-mdm

Conflicts:
	components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java
merge-requests/1/head
Dulitha Wijewantha 10 years ago
commit 899662c5d5

@ -1,7 +1,7 @@
product-cdm
product-mdm
===========
WSO2 MOBILE DEVICE MANAGER
WSO2 Mobile Device Manager (WSO2 MDM) is a comprehensive platform that helps solve mobile computing challenges enterprises face today when dealing with both corporate owned, personally enabled (COPE) devices and employee owned devices as part of a bring your own device (BYOD) program.
Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 EMM offers a single enterprise-grade platform.
Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 MDM offers a single enterprise-grade platform.

@ -67,6 +67,17 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>

@ -32,7 +32,7 @@ public interface MobileDeviceOperationMappingDAO {
* @return The status of the operation. If the insert was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean addMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation)
boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation)
throws MobileDeviceManagementDAOException;
/**
@ -42,7 +42,7 @@ public interface MobileDeviceOperationMappingDAO {
* @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean updateMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation)
boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation)
throws MobileDeviceManagementDAOException;
/**
@ -53,7 +53,7 @@ public interface MobileDeviceOperationMappingDAO {
* @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean updateMobileDeviceOperationToInProgress(String deviceId, int operationId)
boolean updateMobileDeviceOperationMappingToInProgress(String deviceId, int operationId)
throws MobileDeviceManagementDAOException;
/**
@ -64,7 +64,7 @@ public interface MobileDeviceOperationMappingDAO {
* @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean updateMobileDeviceOperationToCompleted(String deviceId, int operationId)
boolean updateMobileDeviceOperationMappingToCompleted(String deviceId, int operationId)
throws MobileDeviceManagementDAOException;
/**
@ -75,7 +75,7 @@ public interface MobileDeviceOperationMappingDAO {
* @return The status of the operation. If the deletion was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean deleteMobileDeviceOperation(String deviceId, int operationId)
boolean deleteMobileDeviceOperationMapping(String deviceId, int operationId)
throws MobileDeviceManagementDAOException;
/**
@ -87,7 +87,7 @@ public interface MobileDeviceOperationMappingDAO {
* deviceId and operationId.
* @throws MobileDeviceManagementDAOException
*/
MobileDeviceOperationMapping getMobileDeviceOperation(String deviceId, int operationId)
MobileDeviceOperationMapping getMobileDeviceOperationMapping(String deviceId, int operationId)
throws MobileDeviceManagementDAOException;
/**
@ -96,7 +96,7 @@ public interface MobileDeviceOperationMappingDAO {
* @return Device operation mapping object list.
* @throws MobileDeviceManagementDAOException
*/
List<MobileDeviceOperationMapping> getAllMobileDeviceOperationsOfDevice(String deviceId)
List<MobileDeviceOperationMapping> getAllMobileDeviceOperationNappingsOfDevice(String deviceId)
throws MobileDeviceManagementDAOException;
/**
@ -105,6 +105,6 @@ public interface MobileDeviceOperationMappingDAO {
* @return Device operation mapping object list.
* @throws MobileDeviceManagementDAOException
*/
List<MobileDeviceOperationMapping> getAllPendingOperationsOfMobileDevice(String deviceId)
List<MobileDeviceOperationMapping> getAllPendingOperationMappingsOfMobileDevice(String deviceId)
throws MobileDeviceManagementDAOException;
}

@ -33,7 +33,7 @@ public interface MobileFeatureDAO {
* @return The status of the operation. If the insert was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
boolean addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
/**
* Update a feature in the feature table.
@ -42,7 +42,7 @@ public interface MobileFeatureDAO {
* @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
boolean updateMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
/**
* Delete a feature from feature table when the feature id is given.
@ -51,7 +51,7 @@ public interface MobileFeatureDAO {
* @return The status of the operation. If the operationId was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean deleteFeatureById(String featureId) throws MobileDeviceManagementDAOException;
boolean deleteMobileFeatureById(int featureId) throws MobileDeviceManagementDAOException;
/**
* Delete a feature from feature table when the feature code is given.
@ -60,7 +60,7 @@ public interface MobileFeatureDAO {
* @return The status of the operation. If the operationId was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean deleteFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException;
boolean deleteMobileFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException;
/**
* Retrieve a given feature from feature table when the feature id is given.
@ -69,7 +69,7 @@ public interface MobileFeatureDAO {
* @return Feature object that holds data of the feature represented by featureId.
* @throws MobileDeviceManagementDAOException
*/
MobileFeature getFeatureById(String featureId) throws MobileDeviceManagementDAOException;
MobileFeature getMobileFeatureById(int featureId) throws MobileDeviceManagementDAOException;
/**
* Retrieve a given feature from feature table when the feature code is given.
@ -78,7 +78,7 @@ public interface MobileFeatureDAO {
* @return Feature object that holds data of the feature represented by featureCode.
* @throws MobileDeviceManagementDAOException
*/
MobileFeature getFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException;
MobileFeature getMobileFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException;
/**
* Retrieve all the features from plugin specific database.
@ -86,7 +86,6 @@ public interface MobileFeatureDAO {
* @return Feature object list.
* @throws MobileDeviceManagementDAOException
*/
List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException;
/**
* Retrieve all the features from plugin specific database for a Device Type.
@ -94,6 +93,7 @@ public interface MobileFeatureDAO {
* @return Feature object list.
* @throws MobileDeviceManagementDAOException
*/
List<MobileFeature> getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException;
List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException;
List<MobileFeature> getAllMobileFeatures() throws MobileDeviceManagementDAOException;
}

@ -32,7 +32,7 @@ public interface MobileFeaturePropertyDAO {
* @return The status of the operation. If the insert was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean addFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
boolean addMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
throws MobileDeviceManagementDAOException;
/**
@ -42,7 +42,7 @@ public interface MobileFeaturePropertyDAO {
* @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean updateFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
boolean updateMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
throws MobileDeviceManagementDAOException;
/**
@ -52,7 +52,7 @@ public interface MobileFeaturePropertyDAO {
* @return The status of the operation. If the operationId was successful or not.
* @throws MobileDeviceManagementDAOException
*/
boolean deleteFeatureProperty(String property) throws MobileDeviceManagementDAOException;
boolean deleteMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException;
/**
* Retrieve a given feature property from feature property table.
@ -61,7 +61,7 @@ public interface MobileFeaturePropertyDAO {
* @return Feature property object that holds data of the feature property represented by propertyId.
* @throws MobileDeviceManagementDAOException
*/
MobileFeatureProperty getFeatureProperty(String property) throws MobileDeviceManagementDAOException;
MobileFeatureProperty getMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException;
/**
* Retrieve a list of feature property corresponds to a feature id .

@ -100,7 +100,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
stmt.setString(6, mobileDevice.getModel());
stmt.setString(7, mobileDevice.getVendor());
stmt.setString(8, mobileDevice.getLatitude());
stmt.setString(8, mobileDevice.getLongitude());
stmt.setString(9, mobileDevice.getLongitude());
int rows = stmt.executeUpdate();
if(rows>0){
status = true;

@ -45,7 +45,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
}
@Override
public boolean addMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation)
public boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -81,7 +81,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
}
@Override
public boolean updateMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation)
public boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -114,7 +114,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
}
@Override
public boolean updateMobileDeviceOperationToInProgress(String deviceId, int operationId)
public boolean updateMobileDeviceOperationMappingToInProgress(String deviceId, int operationId)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -147,7 +147,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
}
@Override
public boolean updateMobileDeviceOperationToCompleted(String deviceId,
public boolean updateMobileDeviceOperationMappingToCompleted(String deviceId,
int operationId)
throws MobileDeviceManagementDAOException {
boolean status = false;
@ -181,7 +181,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
}
@Override
public boolean deleteMobileDeviceOperation(String deviceId, int operationId)
public boolean deleteMobileDeviceOperationMapping(String deviceId, int operationId)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -210,7 +210,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
}
@Override
public MobileDeviceOperationMapping getMobileDeviceOperation(String deviceId, int operationId)
public MobileDeviceOperationMapping getMobileDeviceOperationMapping(String deviceId,
int operationId)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
@ -246,7 +247,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
}
@Override
public List<MobileDeviceOperationMapping> getAllMobileDeviceOperationsOfDevice(String deviceId)
public List<MobileDeviceOperationMapping> getAllMobileDeviceOperationNappingsOfDevice(
String deviceId)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
@ -282,7 +284,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
}
@Override
public List<MobileDeviceOperationMapping> getAllPendingOperationsOfMobileDevice(String deviceId)
public List<MobileDeviceOperationMapping> getAllPendingOperationMappingsOfMobileDevice(
String deviceId)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;

@ -44,7 +44,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
public boolean addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
PreparedStatement stmt = null;
@ -74,7 +74,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public boolean updateFeature(MobileFeature mobileFeature)
public boolean updateMobileFeature(MobileFeature mobileFeature)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -105,7 +105,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public boolean deleteFeatureByCode(String featureCode)
public boolean deleteMobileFeatureByCode(String featureCode)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -131,7 +131,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public boolean deleteFeatureById(String featureId)
public boolean deleteMobileFeatureById(int featureId)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -141,7 +141,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
String deleteDBQuery =
"DELETE FROM MBL_FEATURE WHERE FEATURE_ID = ?";
stmt = conn.prepareStatement(deleteDBQuery);
stmt.setString(1, featureId);
stmt.setInt(1, featureId);
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
@ -157,7 +157,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public MobileFeature getFeatureByCode(String featureCode)
public MobileFeature getMobileFeatureByCode(String featureCode)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
@ -190,7 +190,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public MobileFeature getFeatureById(String featureID)
public MobileFeature getMobileFeatureById(int featureID)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
@ -200,7 +200,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
String selectDBQuery =
"SELECT FEATURE_ID,DEVICE_TYPE, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE FEATURE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, featureID);
stmt.setInt(1, featureID);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
mobileFeature = new MobileFeature();
@ -223,7 +223,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
public List<MobileFeature> getAllMobileFeatures() throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileFeature mobileFeature;
@ -254,7 +254,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public List<MobileFeature> getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException {
public List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileFeature mobileFeature;

@ -44,7 +44,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
}
@Override
public boolean addFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
public boolean addMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -73,7 +73,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
}
@Override
public boolean updateFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
public boolean updateMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -101,7 +101,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
}
@Override
public boolean deleteFeatureProperty(String property)
public boolean deleteMobileFeatureProperty(String property)
throws MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
@ -128,7 +128,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
}
@Override
public MobileFeatureProperty getFeatureProperty(String property)
public MobileFeatureProperty getMobileFeatureProperty(String property)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;

@ -22,13 +22,13 @@ package org.wso2.carbon.device.mgt.mobile.dto;
public class MobileFeatureProperty {
private String property;
private String featureID;
private Integer featureID;
public String getFeatureID() {
public Integer getFeatureID() {
return featureID;
}
public void setFeatureID(String featureID) {
public void setFeatureID(Integer featureID) {
this.featureID = featureID;
}

@ -57,7 +57,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
mobileDeviceOperationMapping.setDeviceId(deviceIdentifier.getId());
mobileDeviceOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW);
status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.addMobileDeviceOperation(
.addMobileDeviceOperationMapping(
mobileDeviceOperationMapping);
}
}
@ -79,7 +79,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
MobileOperation mobileOperation = null;
try {
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.getAllMobileDeviceOperationsOfDevice(
.getAllMobileDeviceOperationNappingsOfDevice(
deviceIdentifier
.getId());
if (mobileDeviceOperationMappings.size() > 0) {
@ -119,7 +119,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
try {
//Get the list of pending operations for the given device
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.getAllPendingOperationsOfMobileDevice(
.getAllPendingOperationMappingsOfMobileDevice(
deviceIdentifier
.getId());
//Go through each operation mapping for retrieving the data corresponding to each operation
@ -140,7 +140,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
operation.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS);
operation.setSentDate(new Date().getTime());
MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.updateMobileDeviceOperationToInProgress(
.updateMobileDeviceOperationMappingToInProgress(
operation.getDeviceId(),
operation.getOperationId());
}
@ -160,7 +160,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
MobileFeaturePropertyDAO featurePropertyDAO = MobileDeviceManagementDAOFactory.getFeaturePropertyDAO();
List<Feature> features = new ArrayList<Feature>();
try {
List<MobileFeature> mobileFeatures = featureDAO.getFeatureByDeviceType(deviceType);
List<MobileFeature> mobileFeatures = featureDAO.getMobileFeatureByDeviceType(deviceType);
for (MobileFeature mobileFeature : mobileFeatures) {
Feature feature = new Feature();
feature.setId(mobileFeature.getId());

@ -55,6 +55,7 @@ import java.util.List;
*/
public class MobileDeviceManagementServiceComponent {
private static final String SETUP_COMMAND = "setup";
private ServiceRegistration androidServiceRegRef;
private ServiceRegistration iOSServiceRegRef;
private ServiceRegistration windowsServiceRegRef;
@ -77,7 +78,7 @@ public class MobileDeviceManagementServiceComponent {
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
MobileDeviceManagementDAOFactory.init();
String setupOption = System.getProperty("setup");
String setupOption = System.getProperty(SETUP_COMMAND);
if (setupOption != null) {
if (log.isDebugEnabled()) {
log.debug(

@ -1,139 +0,0 @@
/*
* Copyright (c) 2014, 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.device.mgt.mobile.impl.dao;
import org.apache.commons.dbcp.BasicDataSource;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl;
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Iterator;
public class FeatureDAOTestSuite {
private TestDBConfiguration testDBConfiguration;
private Connection conn = null;
private Statement stmt = null;
private MobileFeatureDAOImpl featureDAO;
@BeforeClass
@Parameters("dbType")
public void setUpDB(String dbTypeStr) throws Exception {
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
testDBConfiguration = getTestDBConfiguration(dbType);
switch (dbType) {
case H2:
createH2DB(testDBConfiguration);
BasicDataSource testDataSource = new BasicDataSource();
testDataSource.setDriverClassName(testDBConfiguration.getDriverClass());
testDataSource.setUrl(testDBConfiguration.getConnectionUrl());
testDataSource.setUsername(testDBConfiguration.getUserName());
testDataSource.setPassword(testDBConfiguration.getPwd());
featureDAO = new MobileFeatureDAOImpl(testDataSource);
default:
}
}
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws
MobileDeviceManagementDAOException,
DeviceManagementException {
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
Document doc = null;
testDBConfiguration = null;
TestDBConfigurations testDBConfigurations = null;
doc = MobileDeviceManagementUtil.convertToDocument(deviceMgtConfig);
JAXBContext testDBContext = null;
try {
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc);
} catch (JAXBException e) {
throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e);
}
Iterator<TestDBConfiguration> itrDBConfigs =
testDBConfigurations.getDbTypesList().iterator();
while (itrDBConfigs.hasNext()) {
testDBConfiguration = itrDBConfigs.next();
if (testDBConfiguration.getDbType().equals(dbType.toString())) {
break;
}
}
return testDBConfiguration;
}
private void createH2DB(TestDBConfiguration testDBConf) throws Exception {
Class.forName(testDBConf.getDriverClass());
conn = DriverManager.getConnection(testDBConf.getConnectionUrl());
stmt = conn.createStatement();
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'");
stmt.close();
conn.close();
}
@Test
public void addFeature() throws MobileDeviceManagementDAOException, DeviceManagementException {
MobileFeature mobileFeature = new MobileFeature();
mobileFeature.setCode("Camera");
mobileFeature.setDescription("Camera enable or disable");
mobileFeature.setName("Camera");
boolean added = featureDAO.addFeature(mobileFeature);
// Long deviceId = null;
// try {
// conn = DeviceManagementDAOFactory.getDataSource().getConnection();
// stmt = conn.createStatement();
// ResultSet resultSet = stmt
// .executeQuery("SELECT ID from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'");
//
// while (resultSet.next()) {
// deviceId = resultSet.getLong(1);
// }
// conn.close();
// } catch (SQLException sqlEx) {
// throw new DeviceManagementDAOException("error in fetch device by device identification id", sqlEx);
// }
Assert.assertTrue(added, "Device Id is null");
}
}

@ -0,0 +1,275 @@
/*
* Copyright (c) 2014, 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.device.mgt.mobile.impl.dao;
import org.apache.commons.dbcp.BasicDataSource;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl;
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
import org.wso2.carbon.device.mgt.mobile.impl.TestUtils;
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.sql.*;
import java.util.Iterator;
import java.util.List;
public class MobileFeatureDAOTestSuite {
public static final String MBL_FEATURE_NAME = "Camera";
private static final String MBL_FEATURE_CODE = "500A";
public static final String MBL_FEATURE_DESCRIPTION = "Camera enable or disable";
public static final String MBL_FEATURE_UPDATED_CODE = "501B";
private TestDBConfiguration testDBConfiguration;
private Connection conn = null;
private Statement stmt = null;
private MobileFeatureDAOImpl mblFeatureDAO;
private int mblFeatureId;
@BeforeClass
@Parameters("dbType")
public void setUpDB(String dbTypeStr) throws Exception {
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
testDBConfiguration = getTestDBConfiguration(dbType);
switch (dbType) {
case H2:
createH2DB(testDBConfiguration);
BasicDataSource testDataSource = new BasicDataSource();
testDataSource.setDriverClassName(testDBConfiguration.getDriverClass());
testDataSource.setUrl(testDBConfiguration.getConnectionUrl());
testDataSource.setUsername(testDBConfiguration.getUserName());
testDataSource.setPassword(testDBConfiguration.getPwd());
mblFeatureDAO = new MobileFeatureDAOImpl(testDataSource);
default:
}
}
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws
MobileDeviceManagementDAOException,
DeviceManagementException {
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
Document doc = null;
testDBConfiguration = null;
TestDBConfigurations testDBConfigurations = null;
doc = MobileDeviceManagementUtil.convertToDocument(deviceMgtConfig);
JAXBContext testDBContext = null;
try {
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc);
} catch (JAXBException e) {
throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e);
}
Iterator<TestDBConfiguration> itrDBConfigs =
testDBConfigurations.getDbTypesList().iterator();
while (itrDBConfigs.hasNext()) {
testDBConfiguration = itrDBConfigs.next();
if (testDBConfiguration.getDbType().equals(dbType.toString())) {
break;
}
}
return testDBConfiguration;
}
private void createH2DB(TestDBConfiguration testDBConf) throws Exception {
Class.forName(testDBConf.getDriverClass());
conn = DriverManager.getConnection(testDBConf.getConnectionUrl());
stmt = conn.createStatement();
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'");
stmt.close();
conn.close();
}
@Test
public void addMobileFeatureTest()
throws MobileDeviceManagementDAOException {
MobileFeature mobileFeature = new MobileFeature();
MobileFeature testMblFeature = new MobileFeature();
mobileFeature.setCode(MBL_FEATURE_CODE);
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
mobileFeature.setName(MBL_FEATURE_NAME);
boolean added = mblFeatureDAO.addMobileFeature(mobileFeature);
try {
conn = DriverManager.getConnection(testDBConfiguration.getConnectionUrl());
stmt = conn.createStatement();
ResultSet resultSet = stmt
.executeQuery(
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = '500A'");
while (resultSet.next()) {
testMblFeature.setId(resultSet.getInt(1));
testMblFeature.setCode(resultSet.getString(2));
testMblFeature.setName(resultSet.getString(3));
testMblFeature.setDescription(resultSet.getString(4));
}
conn.close();
} catch (SQLException e) {
throw new MobileDeviceManagementDAOException("Error in retrieving Mobile Feature data ",
e);
} finally {
TestUtils.cleanupResources(conn, stmt, null);
}
mblFeatureId = testMblFeature.getId();
Assert.assertTrue(added, "MobileFeature is added");
Assert.assertEquals(MBL_FEATURE_CODE, testMblFeature.getCode(),
"MobileFeature code has persisted successfully");
Assert.assertEquals(MBL_FEATURE_NAME, testMblFeature.getName(),
"MobileFeature name has persisted successfully");
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, testMblFeature.getDescription(),
"MobileFeature description has persisted successfully");
}
@Test(dependsOnMethods = { "addMobileFeatureTest" })
public void getMobileFeatureByCodeTest()
throws MobileDeviceManagementDAOException {
MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureByCode(MBL_FEATURE_CODE);
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
"MobileFeature code has retrieved successfully");
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
"MobileFeature name has retrieved successfully");
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(),
"MobileFeature description has retrieved successfully");
}
@Test(dependsOnMethods = { "addMobileFeatureTest" })
public void deleteMobileFeatureByCodeTest()
throws MobileDeviceManagementDAOException {
boolean status = mblFeatureDAO.deleteMobileFeatureByCode(MBL_FEATURE_CODE);
try {
conn = DriverManager.getConnection(testDBConfiguration.getConnectionUrl());
stmt = conn.createStatement();
ResultSet resultSet = stmt
.executeQuery(
"SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE CODE = '500A'");
while (resultSet.next()) {
status = false;
}
conn.close();
} catch (SQLException e) {
throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ",
e);
} finally {
TestUtils.cleanupResources(conn, stmt, null);
}
Assert.assertTrue(status, "MobileFeature has deleted successfully");
}
@Test(dependsOnMethods = { "addMobileFeatureTest" })
public void getMobileFeatureByIdTest()
throws MobileDeviceManagementDAOException {
MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureById(mblFeatureId);
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
"MobileFeature code has retrieved successfully");
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
"MobileFeature name has retrieved successfully");
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(),
"MobileFeature description has retrieved successfully");
}
@Test(dependsOnMethods = { "addMobileFeatureTest" })
public void getAllMobileFeaturesTest()
throws MobileDeviceManagementDAOException {
List<MobileFeature> mobileFeatures = mblFeatureDAO.getAllMobileFeatures();
Assert.assertNotNull(mobileFeatures, "MobileFeature list is not null");
Assert.assertTrue(mobileFeatures.size() > 0, "MobileFeature list has 1 MobileFeature");
}
@Test(dependsOnMethods = { "addMobileFeatureTest" })
public void deleteMobileFeatureByIdTest()
throws MobileDeviceManagementDAOException {
boolean status = mblFeatureDAO.deleteMobileFeatureById(mblFeatureId);
try {
conn = DriverManager.getConnection(testDBConfiguration.getConnectionUrl());
stmt = conn.createStatement();
ResultSet resultSet = stmt
.executeQuery(
"SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE FEATURE_ID = " +
mblFeatureId);
while (resultSet.next()) {
status = false;
}
conn.close();
} catch (SQLException e) {
throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ",
e);
} finally {
TestUtils.cleanupResources(conn, stmt, null);
}
Assert.assertTrue(status, "MobileFeature has deleted successfully");
}
@Test(dependsOnMethods = { "deleteMobileFeatureByCodeTest", "addMobileFeatureTest" })
public void updateMobileFeatureTest()
throws MobileDeviceManagementDAOException {
MobileFeature mobileFeature = new MobileFeature();
MobileFeature testMblFeature = new MobileFeature();
mobileFeature.setCode(MBL_FEATURE_UPDATED_CODE);
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
mobileFeature.setName(MBL_FEATURE_NAME);
mobileFeature.setId(mblFeatureId);
boolean updated = mblFeatureDAO.updateMobileFeature(mobileFeature);
try {
conn = DriverManager.getConnection(testDBConfiguration.getConnectionUrl());
stmt = conn.createStatement();
ResultSet resultSet = stmt
.executeQuery(
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = " +
MBL_FEATURE_UPDATED_CODE);
while (resultSet.next()) {
testMblFeature.setId(resultSet.getInt(1));
testMblFeature.setCode(resultSet.getString(2));
testMblFeature.setName(resultSet.getString(3));
testMblFeature.setDescription(resultSet.getString(4));
}
conn.close();
} catch (SQLException e) {
throw new MobileDeviceManagementDAOException("Error in updating Mobile Feature data ",
e);
} finally {
TestUtils.cleanupResources(conn, stmt, null);
}
Assert.assertTrue(updated, "MobileFeature has updated");
Assert.assertEquals(MBL_FEATURE_UPDATED_CODE, testMblFeature.getCode(),
"MobileFeature data has updated successfully");
}
}

@ -42,6 +42,7 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` (
`OPERATION_ID` INT NOT NULL ,
`SENT_DATE` BIGINT NULL ,
`RECEIVED_DATE` BIGINT NULL ,
`STATUS` VARCHAR(10) NOT NULL ,
PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) ,
CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE`
FOREIGN KEY (`DEVICE_ID` )

@ -18,10 +18,18 @@
<suite name="CDM-Mobile-Tests">
<parameter name="useDefaultListeners" value="false"/>
<test name="DAO Unit Tests" preserve-order="true">
<test name="Config Unit Tests" preserve-order="true">
<parameter name="dbType" value="H2"/>
<classes>
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.FeatureDAOTestSuite"/>
<class name="org.wso2.carbon.device.mgt.mobile.impl.MobileDeviceManagementConfigTests"/>
</classes>
</test>
<!--test name="DAO Unit Tests" preserve-order="true">
<parameter name="dbType" value="H2"/>
<classes>
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.MobileFeatureDAOTestSuite"/>
</classes>
</test-->
</suite>

@ -125,7 +125,8 @@
<classpath refid="maven.compile.classpath"/>
<classpath refid="maven.runtime.classpath"/>
<fileset file="${basedir}/../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/cdm/h2.sql"/>
<fileset
file="${basedir}/../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/cdm/h2.sql"/>
</sql>
<echo
message="##################### END ####################"/>
@ -159,7 +160,8 @@
<classpath refid="maven.compile.classpath"/>
<classpath refid="maven.runtime.classpath"/>
<fileset file="${basedir}/../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/identity/application-mgt/h2.sql"/>
<fileset
file="${basedir}/../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/identity/application-mgt/h2.sql"/>
</sql>
<echo
message="##################### END ####################"/>
@ -193,7 +195,8 @@
<classpath refid="maven.compile.classpath"/>
<classpath refid="maven.runtime.classpath"/>
<fileset file="${basedir}/../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/apimgt/h2.sql"/>
<fileset
file="${basedir}/../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/apimgt/h2.sql"/>
</sql>
<echo
message="##################### END ####################"/>

@ -219,20 +219,54 @@
</featureArtifactDef>
<!-- registry features -->
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.core.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.core.server.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.ui.menu.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.resource.properties.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.associations.dependencies.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.community.features.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.community.features.server.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.extensions.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.ws.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.ui.menu.governance.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.registry.contentsearch.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.core.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.core.server.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.ui.menu.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.resource.properties.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.associations.dependencies.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.community.features.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.community.features.server.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.extensions.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.ws.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.ui.menu.governance.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.registry.contentsearch.feature:${carbon.platform.version}
</featureArtifactDef>
<!--Governance Feature-->
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.governance.metadata.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>org.wso2.carbon:org.wso2.carbon.governance.lifecycle.management.feature:${carbon.platform.version}</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.governance.metadata.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.governance.lifecycle.management.feature:${carbon.platform.version}
</featureArtifactDef>
<featureArtifactDef>
org.wso2.carbon:org.wso2.carbon.identity.self.registration.server.feature:${carbon.platform.version}
</featureArtifactDef>
</featureArtifacts>
</configuration>
</execution>
@ -369,7 +403,9 @@
<version>${carbon.platform.version}</version>
</feature>
<feature>
<id>org.wso2.carbon.identity.application.authentication.framework.server.feature.group</id>
<id>
org.wso2.carbon.identity.application.authentication.framework.server.feature.group
</id>
<version>${carbon.platform.version}</version>
</feature>
<feature>
@ -393,6 +429,12 @@
<version>${carbon.platform.version}</version>
</feature>
<feature>
<id>org.wso2.carbon.identity.self.registration.server.feature.group</id>
<version>${carbon.platform.version}</version>
</feature>
<!-- registry features -->
<feature>

Loading…
Cancel
Save