forked from community/device-mgt-plugins
parent
16b6c527ef
commit
85fdb3c930
@ -1,250 +1,250 @@
|
||||
/*
|
||||
* 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.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeaturePropertyDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of MobileFeaturePropertyDAO.
|
||||
*/
|
||||
public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOImpl.class);
|
||||
|
||||
public MobileFeaturePropertyDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO AD_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, mblFeatureProperty.getProperty());
|
||||
stmt.setInt(2, mblFeatureProperty.getFeatureID());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Added MobileFeatureProperty " + mblFeatureProperty.getProperty() +
|
||||
" to the MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding property id - '" +
|
||||
mblFeatureProperty.getFeatureID() + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE AD_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setInt(1, mblFeatureProperty.getFeatureID());
|
||||
stmt.setString(2, mblFeatureProperty.getProperty());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updated MobileFeatureProperty " + mblFeatureProperty.getProperty());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating the feature property with property - '" +
|
||||
mblFeatureProperty.getProperty() + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMobileFeatureProperty(String property)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setString(1, property);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleted MobileFeatureProperty " + property + " from MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting feature property with property - " +
|
||||
property;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMobileFeaturePropertiesOfFeature(Integer mblFeatureId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setInt(1, mblFeatureId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleted all MobileFeatureProperties of FeatureId " + mblFeatureId +
|
||||
" from MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting feature properties of feature - " +
|
||||
mblFeatureId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileFeatureProperty getMobileFeatureProperty(String property)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileFeatureProperty mobileFeatureProperty = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, property);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
mobileFeatureProperty = new MobileFeatureProperty();
|
||||
mobileFeatureProperty.setProperty(resultSet.getString(1));
|
||||
mobileFeatureProperty.setFeatureID(resultSet.getInt(2));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetched MobileFeatureProperty " + mobileFeatureProperty.getProperty() +
|
||||
" from MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching property - '" +
|
||||
property + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return mobileFeatureProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileFeatureProperty> getFeaturePropertiesOfFeature(Integer mblFeatureId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileFeatureProperty mobileFeatureProperty;
|
||||
List<MobileFeatureProperty> FeatureProperties = new ArrayList<MobileFeatureProperty>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setInt(1, mblFeatureId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
mobileFeatureProperty = new MobileFeatureProperty();
|
||||
mobileFeatureProperty.setProperty(resultSet.getString(1));
|
||||
mobileFeatureProperty.setFeatureID(resultSet.getInt(2));
|
||||
FeatureProperties.add(mobileFeatureProperty);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetched all MobileFeatureProperties of featureId " + mblFeatureId +
|
||||
" from MDM database.");
|
||||
}
|
||||
return FeatureProperties;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching all feature property.'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
"management metadata repository datasource.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
///*
|
||||
// * 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.dao.impl;
|
||||
//
|
||||
//import org.apache.commons.logging.Log;
|
||||
//import org.apache.commons.logging.LogFactory;
|
||||
//import org.wso2.carbon.device.mgt.mobile.dao.MobileFeaturePropertyDAO;
|
||||
//import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
//import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
//import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty;
|
||||
//
|
||||
//import javax.sql.DataSource;
|
||||
//import java.sql.Connection;
|
||||
//import java.sql.PreparedStatement;
|
||||
//import java.sql.ResultSet;
|
||||
//import java.sql.SQLException;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * Implementation of MobileFeaturePropertyDAO.
|
||||
// */
|
||||
//public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
||||
//
|
||||
// private DataSource dataSource;
|
||||
// private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOImpl.class);
|
||||
//
|
||||
// public MobileFeaturePropertyDAOImpl(DataSource dataSource) {
|
||||
// this.dataSource = dataSource;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean addMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty)
|
||||
// throws MobileDeviceManagementDAOException {
|
||||
// boolean status = false;
|
||||
// Connection conn = null;
|
||||
// PreparedStatement stmt = null;
|
||||
// try {
|
||||
// conn = this.getConnection();
|
||||
// String createDBQuery =
|
||||
// "INSERT INTO AD_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)";
|
||||
//
|
||||
// stmt = conn.prepareStatement(createDBQuery);
|
||||
// stmt.setString(1, mblFeatureProperty.getProperty());
|
||||
// stmt.setInt(2, mblFeatureProperty.getFeatureID());
|
||||
// int rows = stmt.executeUpdate();
|
||||
// if (rows > 0) {
|
||||
// status = true;
|
||||
// if (log.isDebugEnabled()) {
|
||||
// log.debug("Added MobileFeatureProperty " + mblFeatureProperty.getProperty() +
|
||||
// " to the MDM database.");
|
||||
// }
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while adding property id - '" +
|
||||
// mblFeatureProperty.getFeatureID() + "'";
|
||||
// log.error(msg, e);
|
||||
// throw new MobileDeviceManagementDAOException(msg, e);
|
||||
// } finally {
|
||||
// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
// }
|
||||
// return status;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean updateMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty)
|
||||
// throws MobileDeviceManagementDAOException {
|
||||
// boolean status = false;
|
||||
// Connection conn = null;
|
||||
// PreparedStatement stmt = null;
|
||||
// try {
|
||||
// conn = this.getConnection();
|
||||
// String updateDBQuery =
|
||||
// "UPDATE AD_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?";
|
||||
// stmt = conn.prepareStatement(updateDBQuery);
|
||||
// stmt.setInt(1, mblFeatureProperty.getFeatureID());
|
||||
// stmt.setString(2, mblFeatureProperty.getProperty());
|
||||
// int rows = stmt.executeUpdate();
|
||||
// if (rows > 0) {
|
||||
// status = true;
|
||||
// if (log.isDebugEnabled()) {
|
||||
// log.debug("Updated MobileFeatureProperty " + mblFeatureProperty.getProperty());
|
||||
// }
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while updating the feature property with property - '" +
|
||||
// mblFeatureProperty.getProperty() + "'";
|
||||
// log.error(msg, e);
|
||||
// throw new MobileDeviceManagementDAOException(msg, e);
|
||||
// } finally {
|
||||
// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
// }
|
||||
// return status;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean deleteMobileFeatureProperty(String property)
|
||||
// throws MobileDeviceManagementDAOException {
|
||||
// boolean status = false;
|
||||
// Connection conn = null;
|
||||
// PreparedStatement stmt = null;
|
||||
// try {
|
||||
// conn = this.getConnection();
|
||||
// String deleteDBQuery =
|
||||
// "DELETE FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?";
|
||||
// stmt = conn.prepareStatement(deleteDBQuery);
|
||||
// stmt.setString(1, property);
|
||||
// int rows = stmt.executeUpdate();
|
||||
// if (rows > 0) {
|
||||
// status = true;
|
||||
// if (log.isDebugEnabled()) {
|
||||
// log.debug("Deleted MobileFeatureProperty " + property + " from MDM database.");
|
||||
// }
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while deleting feature property with property - " +
|
||||
// property;
|
||||
// log.error(msg, e);
|
||||
// throw new MobileDeviceManagementDAOException(msg, e);
|
||||
// } finally {
|
||||
// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
// }
|
||||
// return status;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean deleteMobileFeaturePropertiesOfFeature(Integer mblFeatureId)
|
||||
// throws MobileDeviceManagementDAOException {
|
||||
// boolean status = false;
|
||||
// Connection conn = null;
|
||||
// PreparedStatement stmt = null;
|
||||
// try {
|
||||
// conn = this.getConnection();
|
||||
// String deleteDBQuery =
|
||||
// "DELETE FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||
// stmt = conn.prepareStatement(deleteDBQuery);
|
||||
// stmt.setInt(1, mblFeatureId);
|
||||
// int rows = stmt.executeUpdate();
|
||||
// if (rows > 0) {
|
||||
// status = true;
|
||||
// if (log.isDebugEnabled()) {
|
||||
// log.debug("Deleted all MobileFeatureProperties of FeatureId " + mblFeatureId +
|
||||
// " from MDM database.");
|
||||
// }
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while deleting feature properties of feature - " +
|
||||
// mblFeatureId;
|
||||
// log.error(msg, e);
|
||||
// throw new MobileDeviceManagementDAOException(msg, e);
|
||||
// } finally {
|
||||
// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
// }
|
||||
// return status;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public MobileFeatureProperty getMobileFeatureProperty(String property)
|
||||
// throws MobileDeviceManagementDAOException {
|
||||
// Connection conn = null;
|
||||
// PreparedStatement stmt = null;
|
||||
// MobileFeatureProperty mobileFeatureProperty = null;
|
||||
// try {
|
||||
// conn = this.getConnection();
|
||||
// String selectDBQuery =
|
||||
// "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?";
|
||||
// stmt = conn.prepareStatement(selectDBQuery);
|
||||
// stmt.setString(1, property);
|
||||
// ResultSet resultSet = stmt.executeQuery();
|
||||
// if (resultSet.next()) {
|
||||
// mobileFeatureProperty = new MobileFeatureProperty();
|
||||
// mobileFeatureProperty.setProperty(resultSet.getString(1));
|
||||
// mobileFeatureProperty.setFeatureID(resultSet.getInt(2));
|
||||
// if (log.isDebugEnabled()) {
|
||||
// log.debug("Fetched MobileFeatureProperty " + mobileFeatureProperty.getProperty() +
|
||||
// " from MDM database.");
|
||||
// }
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while fetching property - '" +
|
||||
// property + "'";
|
||||
// log.error(msg, e);
|
||||
// throw new MobileDeviceManagementDAOException(msg, e);
|
||||
// } finally {
|
||||
// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
// }
|
||||
// return mobileFeatureProperty;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<MobileFeatureProperty> getFeaturePropertiesOfFeature(Integer mblFeatureId)
|
||||
// throws MobileDeviceManagementDAOException {
|
||||
// Connection conn = null;
|
||||
// PreparedStatement stmt = null;
|
||||
// MobileFeatureProperty mobileFeatureProperty;
|
||||
// List<MobileFeatureProperty> FeatureProperties = new ArrayList<MobileFeatureProperty>();
|
||||
// try {
|
||||
// conn = this.getConnection();
|
||||
// String selectDBQuery =
|
||||
// "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||
// stmt = conn.prepareStatement(selectDBQuery);
|
||||
// stmt.setInt(1, mblFeatureId);
|
||||
// ResultSet resultSet = stmt.executeQuery();
|
||||
// while (resultSet.next()) {
|
||||
// mobileFeatureProperty = new MobileFeatureProperty();
|
||||
// mobileFeatureProperty.setProperty(resultSet.getString(1));
|
||||
// mobileFeatureProperty.setFeatureID(resultSet.getInt(2));
|
||||
// FeatureProperties.add(mobileFeatureProperty);
|
||||
// }
|
||||
// if (log.isDebugEnabled()) {
|
||||
// log.debug("Fetched all MobileFeatureProperties of featureId " + mblFeatureId +
|
||||
// " from MDM database.");
|
||||
// }
|
||||
// return FeatureProperties;
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while fetching all feature property.'";
|
||||
// log.error(msg, e);
|
||||
// throw new MobileDeviceManagementDAOException(msg, e);
|
||||
// } finally {
|
||||
// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
// try {
|
||||
// return dataSource.getConnection();
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
// "management metadata repository datasource.";
|
||||
// log.error(msg, e);
|
||||
// throw new MobileDeviceManagementDAOException(msg, e);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,260 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
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.dao.util.MobileDatabaseUtils;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class for holding unit-tests related to MobileFeatureDAO class.
|
||||
*
|
||||
*/
|
||||
public class MobileFeatureDAOTestSuite {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileFeatureDAOTestSuite.class);
|
||||
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_DEVICE_TYPE = "Android";
|
||||
public static final String MBL_FEATURE_UPDATED_CODE = "501B";
|
||||
private TestDBConfiguration testDBConfiguration;
|
||||
private MobileFeatureDAOImpl mblFeatureDAO;
|
||||
private int mblFeatureId;
|
||||
|
||||
@BeforeClass
|
||||
@Parameters("dbType")
|
||||
public void setUpDB(String dbTypeStr) throws Exception {
|
||||
|
||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||
|
||||
switch (dbType) {
|
||||
case H2:
|
||||
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||
PoolProperties properties = new PoolProperties();
|
||||
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||
properties.setUsername(testDBConfiguration.getUsername());
|
||||
properties.setPassword(testDBConfiguration.getPassword());
|
||||
testDataSource.setPoolProperties(properties);
|
||||
mblFeatureDAO = new MobileFeatureDAOImpl(testDataSource);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addMobileFeatureTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
MobileFeature mobileFeature = new MobileFeature();
|
||||
MobileFeature testMblFeature = new MobileFeature();
|
||||
mobileFeature.setCode(MBL_FEATURE_CODE);
|
||||
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
||||
mblFeatureDAO.addFeature(mobileFeature);
|
||||
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String query =
|
||||
"SELECT ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE WHERE CODE = ?";
|
||||
preparedStatement = conn.prepareStatement(query);
|
||||
preparedStatement.setString(1, MBL_FEATURE_CODE);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
testMblFeature.setId(resultSet.getInt(1));
|
||||
testMblFeature.setCode(resultSet.getString(2));
|
||||
testMblFeature.setName(resultSet.getString(3));
|
||||
testMblFeature.setDescription(resultSet.getString(4));
|
||||
testMblFeature.setDeviceType(resultSet.getString(5));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Feature data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
mblFeatureId = testMblFeature.getId();
|
||||
Assert.assertTrue(mblFeatureId > 0, "MobileFeature has added ");
|
||||
Assert.assertEquals(MBL_FEATURE_CODE, testMblFeature.getCode(),
|
||||
"MobileFeature code has persisted ");
|
||||
Assert.assertEquals(MBL_FEATURE_NAME, testMblFeature.getName(),
|
||||
"MobileFeature name has persisted ");
|
||||
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, testMblFeature.getDescription(),
|
||||
"MobileFeature description has persisted ");
|
||||
Assert.assertEquals(MBL_FEATURE_DEVICE_TYPE, testMblFeature.getDeviceType(),
|
||||
"MobileFeature device-type has persisted ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeatureTest" })
|
||||
public void getMobileFeatureByCodeTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
MobileFeature mobileFeature = mblFeatureDAO.getFeatureByCode(MBL_FEATURE_CODE);
|
||||
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
||||
"MobileFeature code has retrieved ");
|
||||
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
||||
"MobileFeature name has retrieved ");
|
||||
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(),
|
||||
"MobileFeature description has retrieved ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeatureTest" })
|
||||
public void getMobileFeatureByIdTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
MobileFeature mobileFeature = mblFeatureDAO.getFeatureById(mblFeatureId);
|
||||
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
||||
"MobileFeature code has retrieved ");
|
||||
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
||||
"MobileFeature name has retrieved ");
|
||||
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(),
|
||||
"MobileFeature description has retrieved ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeatureTest" })
|
||||
public void getAllMobileFeaturesTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
List<MobileFeature> mobileFeatures = mblFeatureDAO.getAllFeatures();
|
||||
Assert.assertNotNull(mobileFeatures, "MobileFeature list is not null");
|
||||
Assert.assertTrue(mobileFeatures.size() > 0, "MobileFeature list has 1 MobileFeature");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeatureTest", "getMobileFeatureByCodeTest",
|
||||
"getMobileFeatureByIdTest", "getAllMobileFeaturesTest" })
|
||||
public void updateMobileFeatureTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
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.updateFeature(mobileFeature);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String query =
|
||||
"SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setString(1, MBL_FEATURE_UPDATED_CODE);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
testMblFeature.setId(resultSet.getInt(1));
|
||||
testMblFeature.setCode(resultSet.getString(2));
|
||||
testMblFeature.setName(resultSet.getString(3));
|
||||
testMblFeature.setDescription(resultSet.getString(4));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in updating Mobile Feature data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
Assert.assertTrue(updated, "MobileFeature has updated");
|
||||
Assert.assertEquals(MBL_FEATURE_UPDATED_CODE, testMblFeature.getCode(),
|
||||
"MobileFeature data has updated ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeatureTest", "getMobileFeatureByCodeTest",
|
||||
"getMobileFeatureByIdTest", "getAllMobileFeaturesTest",
|
||||
"updateMobileFeatureTest" })
|
||||
public void deleteMobileFeatureByIdTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
boolean status = mblFeatureDAO.deleteFeatureById(mblFeatureId);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String query = "SELECT ID, CODE FROM AD_FEATURE WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, mblFeatureId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
status = false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in deleting Mobile Feature data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileFeature has deleted ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeatureTest", "getMobileFeatureByCodeTest",
|
||||
"getMobileFeatureByIdTest", "getAllMobileFeaturesTest",
|
||||
"updateMobileFeatureTest", "deleteMobileFeatureByIdTest" })
|
||||
public void deleteMobileFeatureByCodeTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
MobileFeature mobileFeature = new MobileFeature();
|
||||
mobileFeature.setCode(MBL_FEATURE_CODE);
|
||||
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
||||
mblFeatureDAO.addFeature(mobileFeature);
|
||||
boolean status = mblFeatureDAO.deleteFeatureByCode(MBL_FEATURE_CODE);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String query = "SELECT ID, CODE FROM AD_FEATURE WHERE CODE = ?";
|
||||
preparedStatement = conn.prepareStatement(query);
|
||||
preparedStatement.setString(1, MBL_FEATURE_CODE);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
status = false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in deleting Mobile Feature data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileFeature has deleted ");
|
||||
}
|
||||
}
|
@ -1,241 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
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.dao.impl.MobileFeaturePropertyDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty;
|
||||
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.dao.util.MobileDatabaseUtils;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class for holding unit-tests related to MobileFeaturePropertyDAO class.
|
||||
*
|
||||
*/
|
||||
public class MobileFeaturePropertyDAOTestSuite {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOTestSuite.class);
|
||||
public static final String MBL_FEATURE_NAME = "WIFI";
|
||||
private static final String MBL_FEATURE_CODE = "500A";
|
||||
public static final String MBL_FEATURE_DESCRIPTION = "Wifi config";
|
||||
public static final String MBL_FEATURE_DEVICE_TYPE = "Android";
|
||||
public static final String MBL_FEATURE_PROP_1 = "SSID";
|
||||
public static final String MBL_FEATURE_PROP_2 = "PASSWORD";
|
||||
private TestDBConfiguration testDBConfiguration;
|
||||
private MobileFeatureDAOImpl mblFeatureDAO;
|
||||
private MobileFeaturePropertyDAOImpl mobileFeaturePropertyDAO;
|
||||
private int mblFeatureId;
|
||||
|
||||
@BeforeClass
|
||||
@Parameters("dbType")
|
||||
public void setUpDB(String dbTypeStr) throws Exception {
|
||||
|
||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||
|
||||
switch (dbType) {
|
||||
case H2:
|
||||
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||
PoolProperties properties = new PoolProperties();
|
||||
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||
properties.setUsername(testDBConfiguration.getUsername());
|
||||
properties.setPassword(testDBConfiguration.getPassword());
|
||||
testDataSource.setPoolProperties(properties);
|
||||
mblFeatureDAO = new MobileFeatureDAOImpl(testDataSource);
|
||||
mobileFeaturePropertyDAO = new MobileFeaturePropertyDAOImpl(testDataSource);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addMobileFeaturePropertyTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
List<MobileFeatureProperty> propertyList = new ArrayList<MobileFeatureProperty>();
|
||||
//Add a new MobileFeature to the database
|
||||
MobileFeature mobileFeature = new MobileFeature();
|
||||
mobileFeature.setCode(MBL_FEATURE_CODE);
|
||||
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
||||
mblFeatureDAO.addFeature(mobileFeature);
|
||||
|
||||
MobileFeature persistMblFeature = mblFeatureDAO.getFeatureByCode(MBL_FEATURE_CODE);
|
||||
mblFeatureId = persistMblFeature.getId();
|
||||
//Add 1st property to the feature
|
||||
MobileFeatureProperty mobileFeatureProperty = new MobileFeatureProperty();
|
||||
mobileFeatureProperty.setFeatureID(mblFeatureId);
|
||||
mobileFeatureProperty.setProperty(MBL_FEATURE_PROP_1);
|
||||
boolean status1 = mobileFeaturePropertyDAO.addMobileFeatureProperty(mobileFeatureProperty);
|
||||
|
||||
//Add 2nd property to the feature
|
||||
mobileFeatureProperty.setProperty(MBL_FEATURE_PROP_2);
|
||||
boolean status2 = mobileFeaturePropertyDAO.addMobileFeatureProperty(mobileFeatureProperty);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String query =
|
||||
"SELECT FEATURE_ID, PROPERTY FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(query);
|
||||
preparedStatement.setInt(1, mblFeatureId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
mobileFeatureProperty = new MobileFeatureProperty();
|
||||
mobileFeatureProperty.setFeatureID(resultSet.getInt(1));
|
||||
mobileFeatureProperty.setProperty(resultSet.getString(2));
|
||||
propertyList.add(mobileFeatureProperty);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Feature data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status1, "MobileFeatureProperty1 has added ");
|
||||
Assert.assertTrue(status2, "MobileFeatureProperty2 has added ");
|
||||
Assert.assertTrue(propertyList.size() == 2, "MobileFeatureProperties have retrieved ");
|
||||
|
||||
for (MobileFeatureProperty mblFeatureProperty : propertyList) {
|
||||
Assert.assertNotNull(mblFeatureProperty.getProperty(),
|
||||
"MobileFeatureProperty property has persisted ");
|
||||
Assert.assertNotNull(mblFeatureProperty.getFeatureID(),
|
||||
"MobileFeatureProperty feature-id has persisted ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest" })
|
||||
public void getMobileFeaturePropertyTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
MobileFeatureProperty mobileFeatureProperty =
|
||||
mobileFeaturePropertyDAO.getMobileFeatureProperty(MBL_FEATURE_PROP_1);
|
||||
Assert.assertNotNull(mobileFeatureProperty, "MobileFeatureProperty has retrieved ");
|
||||
Assert.assertEquals(MBL_FEATURE_PROP_1, mobileFeatureProperty.getProperty(),
|
||||
"MobileFeatureProperty property has retrieved ");
|
||||
Assert.assertTrue(mblFeatureId == mobileFeatureProperty.getFeatureID(),
|
||||
"MobileFeatureProperty featureId has retrieved ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest" })
|
||||
public void getFeaturePropertyOfFeatureTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
List<MobileFeatureProperty> mobileFeatureProperties =
|
||||
mobileFeaturePropertyDAO.getFeaturePropertiesOfFeature(mblFeatureId);
|
||||
Assert.assertNotNull(mobileFeatureProperties, "MobileFeatureProperty list has retrieved ");
|
||||
Assert.assertTrue(mobileFeatureProperties.size() == 2,
|
||||
"MobileFeatureProperties have fetched ");
|
||||
for (MobileFeatureProperty mblFeatureProperty : mobileFeatureProperties) {
|
||||
Assert.assertNotNull(mblFeatureProperty.getProperty(),
|
||||
"MobileFeatureProperty property has fetched ");
|
||||
Assert.assertNotNull(mblFeatureProperty.getFeatureID(),
|
||||
"MobileFeatureProperty feature-id has fetched ");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest",
|
||||
"getFeaturePropertyOfFeatureTest" }, expectedExceptions = MobileDeviceManagementDAOException.class)
|
||||
public void updateMobileFeaturePropertyTest() throws MobileDeviceManagementDAOException {
|
||||
//Update 1st property to a non-exist feature
|
||||
MobileFeatureProperty mobileFeatureProperty = new MobileFeatureProperty();
|
||||
mobileFeatureProperty.setFeatureID(2);
|
||||
mobileFeatureProperty.setProperty(MBL_FEATURE_PROP_1);
|
||||
mobileFeaturePropertyDAO.updateMobileFeatureProperty(mobileFeatureProperty);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest",
|
||||
"getFeaturePropertyOfFeatureTest" })
|
||||
public void deleteMobileFeaturePropertyTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
boolean status =
|
||||
mobileFeaturePropertyDAO.deleteMobileFeatureProperty(MBL_FEATURE_PROP_2);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String query =
|
||||
"SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?";
|
||||
preparedStatement = conn.prepareStatement(query);
|
||||
preparedStatement.setString(1, MBL_FEATURE_PROP_2);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
status = false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving MobileFeatureProperty data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileFeatureProperty has deleted ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest",
|
||||
"getFeaturePropertyOfFeatureTest", "updateMobileFeaturePropertyTest",
|
||||
"deleteMobileFeaturePropertyTest" })
|
||||
public void deleteMobileFeaturePropertiesOfFeatureTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
boolean status =
|
||||
mobileFeaturePropertyDAO.deleteMobileFeaturePropertiesOfFeature(mblFeatureId);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String query =
|
||||
"SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(query);
|
||||
preparedStatement.setInt(1, mblFeatureId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
status = false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving MobileFeatureProperty data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileFeatureProperties has deleted ");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue