forked from community/device-mgt-plugins
commit
b17b514d11
@ -1,7 +1,7 @@
|
|||||||
product-cdm
|
product-mdm
|
||||||
===========
|
===========
|
||||||
WSO2 MOBILE DEVICE MANAGER
|
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.
|
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.
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed 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;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.apimgt.api.APIManagementException;
|
||||||
|
import org.wso2.carbon.apimgt.api.APIProvider;
|
||||||
|
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
|
||||||
|
import org.wso2.carbon.core.ServerStartupObserver;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.config.APIConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.util.DeviceManagementAPIPublisherUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MobileDeviceManagementStartupObserver implements ServerStartupObserver {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementStartupObserver.class);
|
||||||
|
|
||||||
|
public void completingServerStartup() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void completedServerStartup() {
|
||||||
|
try {
|
||||||
|
this.initAPIConfigs();
|
||||||
|
/* Publish all mobile device management related JAX-RS services as APIs */
|
||||||
|
this.publishAPIs();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Error occurred while publishing Mobile Device Management related APIs", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initAPIConfigs() throws DeviceManagementException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing Mobile Device Management related APIs");
|
||||||
|
}
|
||||||
|
List<APIConfig> apiConfigs =
|
||||||
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
||||||
|
getApiPublisherConfig().getAPIs();
|
||||||
|
for (APIConfig apiConfig : apiConfigs) {
|
||||||
|
try {
|
||||||
|
APIProvider provider =
|
||||||
|
APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
|
||||||
|
apiConfig.init(provider);
|
||||||
|
} catch (APIManagementException e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while initializing API Config '" +
|
||||||
|
apiConfig.getName() + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void publishAPIs() throws DeviceManagementException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Publishing Mobile Device Management related APIs");
|
||||||
|
}
|
||||||
|
List<APIConfig> apiConfigs =
|
||||||
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
||||||
|
getApiPublisherConfig().getAPIs();
|
||||||
|
for (APIConfig apiConfig : apiConfigs) {
|
||||||
|
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Successfully published API '" + apiConfig.getName() + "' with the context '" +
|
||||||
|
apiConfig.getContext() + "' and version '" + apiConfig.getVersion() + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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,282 @@
|
|||||||
|
/*
|
||||||
|
* 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.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
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_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) {
|
||||||
|
log.error("Error in retrieving Mobile Feature data ", 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) {
|
||||||
|
log.error("Error in deleting Mobile Feature data ", 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) {
|
||||||
|
log.error("Error in deleting Mobile Feature data ", 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) {
|
||||||
|
log.error("Error in updating Mobile Feature data ", 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
2
components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeaturePropertyDAOTestSuite.java → components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java
2
components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeaturePropertyDAOTestSuite.java → components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java
@ -1,45 +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.
|
|
||||||
* /
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.License;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* License Management related JAX RS APIs
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Produces({ "application/json", "application/xml" })
|
|
||||||
@Consumes({ "application/json", "application/xml" })
|
|
||||||
public class Licenses {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Licenses.class);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
public License getLicense(String deviceType) throws AndroidAgentException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package org.wso2.cdmserver.mobileservices.android;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.*;
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a Test class
|
|
||||||
*/
|
|
||||||
@Produces({"application/json", "application/xml"})
|
|
||||||
@Consumes({"application/json", "application/xml"})
|
|
||||||
public class Test {
|
|
||||||
|
|
||||||
@GET
|
|
||||||
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() throws DeviceManagementException{
|
|
||||||
|
|
||||||
Device dev = new Device();
|
|
||||||
dev.setName("test1");
|
|
||||||
dev.setDateOfEnrolment(11111111L);
|
|
||||||
dev.setDateOfLastUpdate(992093209L);
|
|
||||||
dev.setDescription("sassasaas");
|
|
||||||
|
|
||||||
ArrayList<Device> listdevices = new ArrayList<Device>();
|
|
||||||
listdevices.add(dev);
|
|
||||||
throw new DeviceManagementException("test ex");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue