forked from community/device-mgt-core
Adding the DAO layers for the policy administration, Test cases are added for H2 database type and MySql, This is having the initial cut of the policy and profile saving
parent
92d0faf079
commit
c13b942f0e
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.policy.mgt.common;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public class Profile {
|
||||
|
||||
private int profileId;
|
||||
private String profileName;
|
||||
private int tenantId;
|
||||
private DeviceType deviceType;
|
||||
private Timestamp createdDate;
|
||||
private Timestamp updatedDate;
|
||||
private List<Feature> featuresList; // Features included in the policies.
|
||||
|
||||
public DeviceType getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(DeviceType deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public List<Feature> getFeaturesList() {
|
||||
return featuresList;
|
||||
}
|
||||
|
||||
public void setFeaturesList(List<Feature> featuresList) {
|
||||
this.featuresList = featuresList;
|
||||
}
|
||||
|
||||
public int getProfileId() {
|
||||
return profileId;
|
||||
}
|
||||
|
||||
public void setProfileId(int profileId) {
|
||||
this.profileId = profileId;
|
||||
}
|
||||
|
||||
public String getProfileName() {
|
||||
return profileName;
|
||||
}
|
||||
|
||||
public void setProfileName(String profileName) {
|
||||
this.profileName = profileName;
|
||||
}
|
||||
|
||||
public Timestamp getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(Timestamp createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public Timestamp getUpdatedDate() {
|
||||
return updatedDate;
|
||||
}
|
||||
|
||||
public void setUpdatedDate(Timestamp updatedDate) {
|
||||
this.updatedDate = updatedDate;
|
||||
}
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS `WSO2CDM` DEFAULT CHARACTER SET latin1 ;
|
||||
USE `WSO2CDM` ;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_TYPE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` (
|
||||
`ID` VARCHAR(20) NOT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`NAME` VARCHAR(100) NULL DEFAULT NULL ,
|
||||
`DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL ,
|
||||
`DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL ,
|
||||
`OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`STATUS` VARCHAR(15) NULL DEFAULT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL ,
|
||||
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
`OWNER` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`TENANT_ID` INT(11) NULL DEFAULT '0' ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_PROFILE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE` (
|
||||
`ID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`TENANT_ID` INT NOT NULL ,
|
||||
`CREATED_TIME` DATETIME NOT NULL ,
|
||||
`UPDATED_TIME` DATETIME NOT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`TENANT_ID` INT(11) NOT NULL ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`DEVICE_ID` INT(11) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_POLICY_DEVICE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_TYPE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_DEVICE_TYPE_POLICY` (`POLICY_ID` ASC) ,
|
||||
INDEX `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(256) NOT NULL ,
|
||||
`CODE` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`EVALUVATION_RULE` VARCHAR(60) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_POLICY_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
`FEATURE_ID` INT(11) NOT NULL ,
|
||||
`CONTENT` BLOB NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `fk_DM_POLICY_FEATURES_DM_FEATURES1` (`FEATURE_ID` ASC) ,
|
||||
INDEX `FK_DM_PROFILE_DM_POLICY_FEATURES` (`PROFILE_ID` ASC) ,
|
||||
CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1`
|
||||
FOREIGN KEY (`FEATURE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_FEATURES` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_ROLE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_ROLE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`ROLE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_ROLE_POLICY_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_LOCATION`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_LOCATION` (
|
||||
`LAT` VARCHAR(45) NOT NULL ,
|
||||
`LONG` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
INDEX `FK_DM_POLICY_DM_LOCATION` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_LOCATION`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_TIME`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_TIME` (
|
||||
`STARTING_TIME` DATETIME NOT NULL ,
|
||||
`ENDING_TIME` DATETIME NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
INDEX `FK_DM_POLICY_DM_TIME` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_TIME`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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.policy.mgt.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.common.DBTypes;
|
||||
import org.wso2.carbon.policy.mgt.core.common.TestDBConfiguration;
|
||||
import org.wso2.carbon.policy.mgt.core.common.TestDBConfigurations;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.util.FeatureCreator;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
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.Statement;
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyDAOTestCase {
|
||||
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(PolicyDAOTestCase.class);
|
||||
|
||||
@BeforeClass
|
||||
@Parameters("dbType")
|
||||
public void setUpDB(String dbTypeStr) throws Exception {
|
||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||
TestDBConfiguration dbConfig = getTestDBConfiguration(dbType);
|
||||
PoolProperties properties = new PoolProperties();
|
||||
|
||||
log.info("Database Type : " + dbTypeStr);
|
||||
|
||||
switch (dbType) {
|
||||
|
||||
case MySql:
|
||||
|
||||
log.info("Mysql Called..................................................." + dbTypeStr);
|
||||
|
||||
properties.setUrl(dbConfig.getConnectionUrl());
|
||||
properties.setDriverClassName(dbConfig.getDriverClass());
|
||||
properties.setUsername(dbConfig.getUserName());
|
||||
properties.setPassword(dbConfig.getPwd());
|
||||
dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties);
|
||||
PolicyManagementDAOFactory.init(dataSource);
|
||||
break;
|
||||
|
||||
case H2:
|
||||
|
||||
properties.setUrl(dbConfig.getConnectionUrl());
|
||||
properties.setDriverClassName(dbConfig.getDriverClass());
|
||||
properties.setUsername(dbConfig.getUserName());
|
||||
properties.setPassword(dbConfig.getPwd());
|
||||
dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties);
|
||||
this.initH2SQLScript();
|
||||
PolicyManagementDAOFactory.init(dataSource);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws PolicyManagerDAOException,
|
||||
PolicyManagementException {
|
||||
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
|
||||
Document doc;
|
||||
TestDBConfigurations dbConfigs;
|
||||
|
||||
doc = PolicyManagerUtil.convertToDocument(deviceMgtConfig);
|
||||
JAXBContext testDBContext;
|
||||
|
||||
try {
|
||||
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
|
||||
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
|
||||
dbConfigs = (TestDBConfigurations) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
throw new PolicyManagerDAOException("Error parsing test db configurations", e);
|
||||
}
|
||||
for (TestDBConfiguration config : dbConfigs.getDbTypesList()) {
|
||||
if (config.getDbType().equals(dbType.toString())) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void initH2SQLScript() throws Exception {
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
conn = this.getDataSource().getConnection();
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'");
|
||||
} finally {
|
||||
TestUtils.cleanupResources(conn, stmt, null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void initMySQlSQLScript() throws Exception {
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
conn = this.getDataSource().getConnection();
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateMySqlTestDB.sql'");
|
||||
} finally {
|
||||
TestUtils.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
private DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFeatures() throws PolicyManagerDAOException, PolicyManagementException, FeatureManagementException {
|
||||
|
||||
PolicyDAOImpl policyDAO = new PolicyDAOImpl();
|
||||
List<Feature> featureList = FeatureCreator.getFeatureList();
|
||||
for (Feature feature : featureList) {
|
||||
policyDAO.addFeature(feature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.policy.mgt.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TestUtils.class);
|
||||
|
||||
public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing result set", e);
|
||||
}
|
||||
}
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing prepared statement", e);
|
||||
}
|
||||
}
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing database connection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.common;
|
||||
|
||||
|
||||
public enum DBTypes {
|
||||
Oracle("Oracle"),H2("H2"),MySql("MySql");
|
||||
|
||||
String dbName ;
|
||||
DBTypes(String dbStrName) {
|
||||
dbName = dbStrName;
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "DBType")
|
||||
public class TestDBConfiguration {
|
||||
|
||||
private String connectionUrl;
|
||||
private String driverClass;
|
||||
private String userName;
|
||||
private String pwd;
|
||||
|
||||
@Override public String toString() {
|
||||
return "TestDBConfiguration{" +
|
||||
"connectionUrl='" + connectionUrl + '\'' +
|
||||
", driverClass='" + driverClass + '\'' +
|
||||
", userName='" + userName + '\'' +
|
||||
", pwd='" + pwd + '\'' +
|
||||
", dbType='" + dbType + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
private String dbType;
|
||||
|
||||
@XmlElement(name = "connectionurl", nillable = false)
|
||||
public String getConnectionUrl() {
|
||||
return connectionUrl;
|
||||
}
|
||||
|
||||
public void setConnectionUrl(String connectionUrl) {
|
||||
this.connectionUrl = connectionUrl;
|
||||
}
|
||||
|
||||
@XmlElement(name = "driverclass", nillable = false)
|
||||
public String getDriverClass() {
|
||||
return driverClass;
|
||||
}
|
||||
|
||||
public void setDriverClass(String driverClass) {
|
||||
this.driverClass = driverClass;
|
||||
}
|
||||
|
||||
@XmlElement(name = "userName", nillable = false)
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "pwd", nillable = false)
|
||||
public String getPwd() {
|
||||
return pwd;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
this.pwd = pwd;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "typeName")
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "DeviceMgtTestDBConfigurations")
|
||||
public class TestDBConfigurations {
|
||||
|
||||
private List<TestDBConfiguration> dbTypesList;
|
||||
|
||||
@XmlElement(name = "DBType")
|
||||
public List<TestDBConfiguration> getDbTypesList() {
|
||||
return dbTypesList;
|
||||
}
|
||||
|
||||
public void setDbTypesList(List<TestDBConfiguration> dbTypesList) {
|
||||
this.dbTypesList = dbTypesList;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.util;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FeatureCreator {
|
||||
|
||||
public static List<Feature> getFeatureList() {
|
||||
|
||||
Feature feature1 = new Feature();
|
||||
feature1.setName("Camera");
|
||||
feature1.setCode("C001");
|
||||
feature1.setDescription("Camera");
|
||||
feature1.setRuleValue("permit_override");
|
||||
|
||||
|
||||
Feature feature2 = new Feature();
|
||||
feature2.setName("LOCK");
|
||||
feature2.setCode("L001");
|
||||
feature2.setDescription("Lock the phone");
|
||||
feature2.setRuleValue("deny_override");
|
||||
|
||||
|
||||
Feature feature3 = new Feature();
|
||||
feature3.setName("WIFI");
|
||||
feature3.setCode("W001");
|
||||
feature3.setDescription("Wifi configuration for the device");
|
||||
feature3.setRuleValue("all_available");
|
||||
|
||||
Feature feature4 = new Feature();
|
||||
feature4.setName("RING");
|
||||
feature4.setCode("R001");
|
||||
feature4.setDescription("Ring the mobile");
|
||||
feature4.setRuleValue("first_applicable");
|
||||
|
||||
Feature feature5 = new Feature();
|
||||
feature5.setName("LDAP");
|
||||
feature5.setCode("L002");
|
||||
feature5.setDescription("LDAP Configurations");
|
||||
feature5.setRuleValue("all_available");
|
||||
|
||||
|
||||
Feature feature6 = new Feature();
|
||||
feature6.setName("VPN");
|
||||
feature6.setCode("V001");
|
||||
feature6.setDescription("VPN config for accessing the company network from out side");
|
||||
feature6.setRuleValue("all_available");
|
||||
|
||||
|
||||
Feature feature7 = new Feature();
|
||||
feature7.setName("PASSWORD");
|
||||
feature7.setCode("P001");
|
||||
feature7.setDescription("Setting the password for the mobile");
|
||||
feature7.setRuleValue("first_applicable");
|
||||
|
||||
Feature feature8 = new Feature();
|
||||
feature8.setName("WIPE");
|
||||
feature8.setCode("W002");
|
||||
feature8.setDescription("Wiping the company profile created to access the company secure data");
|
||||
feature8.setRuleValue("permit_override");
|
||||
|
||||
Feature feature9 = new Feature();
|
||||
feature9.setName("ENCRYPTION");
|
||||
feature9.setCode("E001");
|
||||
feature9.setDescription("Adding the encryption for the phone and SD card.");
|
||||
feature9.setRuleValue("permit_override");
|
||||
|
||||
Feature feature10 = new Feature();
|
||||
feature10.setName("APP");
|
||||
feature10.setCode("A001");
|
||||
feature10.setDescription("Installing an application to the phone");
|
||||
feature10.setRuleValue("permit_override");
|
||||
|
||||
Feature feature11 = new Feature();
|
||||
feature11.setName("EMAIL");
|
||||
feature11.setCode("E002");
|
||||
feature11.setDescription("Email configurations of the phone.");
|
||||
feature11.setRuleValue("all_applicable");
|
||||
|
||||
List<Feature> featureList = new ArrayList<Feature>();
|
||||
featureList.add(feature1);
|
||||
featureList.add(feature2);
|
||||
featureList.add(feature3);
|
||||
featureList.add(feature4);
|
||||
featureList.add(feature5);
|
||||
featureList.add(feature6);
|
||||
featureList.add(feature7);
|
||||
featureList.add(feature8);
|
||||
featureList.add(feature9);
|
||||
featureList.add(feature10);
|
||||
featureList.add(feature11);
|
||||
|
||||
return featureList;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#
|
||||
# Copyright 2009 WSO2, Inc. (http://wso2.com)
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#
|
||||
# This is the log4j configuration file used by WSO2 Carbon
|
||||
#
|
||||
# IMPORTANT : Please do not remove or change the names of any
|
||||
# of the Appenders defined here. The layout pattern & log file
|
||||
# can be changed using the WSO2 Carbon Management Console, and those
|
||||
# settings will override the settings in this file.
|
||||
#
|
||||
|
||||
log4j.rootLogger=DEBUG, STD_OUT
|
||||
|
||||
# Redirect log messages to console
|
||||
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.STD_OUT.Target=System.out
|
||||
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
@ -0,0 +1,213 @@
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE_TYPE`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE` (
|
||||
`ID` VARCHAR(20) NOT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`NAME` VARCHAR(100) NULL DEFAULT NULL ,
|
||||
`DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL ,
|
||||
`DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL ,
|
||||
`OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`STATUS` VARCHAR(15) NULL DEFAULT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL ,
|
||||
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
`OWNER` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`TENANT_ID` INT(11) NULL DEFAULT '0' ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_PROFILE`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_PROFILE` (
|
||||
`ID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`TENANT_ID` INT NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT NOT NULL ,
|
||||
`CREATED_TIME` DATETIME NOT NULL ,
|
||||
`UPDATED_TIME` DATETIME NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `DM_PROFILE_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`TENANT_ID` INT(11) NOT NULL ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`DEVICE_ID` VARCHAR(20) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `FK_POLICY_DEVICE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_DEVICE_POLICY`
|
||||
FOREIGN KEY (`DEVICE_ID` )
|
||||
REFERENCES `DM_DEVICE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE_TYPE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(256) NOT NULL ,
|
||||
`CODE` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`EVALUVATION_RULE` VARCHAR(60) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) );
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_PROFILE_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_PROFILE_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
`FEATURE_ID` INT(11) NOT NULL ,
|
||||
`CONTENT` BLOB NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1`
|
||||
FOREIGN KEY (`FEATURE_ID` )
|
||||
REFERENCES `DM_FEATURES` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_ROLE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`ROLE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `FK_ROLE_POLICY_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_LOCATION`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_LOCATION (
|
||||
`LAT` VARCHAR(45) NOT NULL ,
|
||||
`LONG` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_LOCATION`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_TIME`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_TIME (
|
||||
`STARTING_TIME` DATETIME NOT NULL ,
|
||||
`ENDING_TIME` DATETIME NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_TIME`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
;
|
||||
|
@ -0,0 +1,247 @@
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
|
||||
|
||||
DROP SCHEMA IF EXISTS `WSO2CDM` ;
|
||||
CREATE SCHEMA IF NOT EXISTS `WSO2CDM` DEFAULT CHARACTER SET latin1 ;
|
||||
USE `WSO2CDM` ;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_TYPE`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` (
|
||||
`ID` VARCHAR(20) NOT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`NAME` VARCHAR(100) NULL DEFAULT NULL ,
|
||||
`DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL ,
|
||||
`DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL ,
|
||||
`OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`STATUS` VARCHAR(15) NULL DEFAULT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL ,
|
||||
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
`OWNER` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`TENANT_ID` INT(11) NULL DEFAULT '0' ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_PROFILE`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE` (
|
||||
`ID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`TENANT_ID` INT NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT NOT NULL ,
|
||||
`CREATED_TIME` DATETIME NOT NULL ,
|
||||
`UPDATED_TIME` DATETIME NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `DM_PROFILE_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `DM_PROFILE_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`TENANT_ID` INT(11) NOT NULL ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`DEVICE_ID` VARCHAR(20) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC) ,
|
||||
INDEX `FK_DEVICE_DEVICE_POLICY` (`DEVICE_ID` ASC) ,
|
||||
CONSTRAINT `FK_POLICY_DEVICE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_DEVICE_POLICY`
|
||||
FOREIGN KEY (`DEVICE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_TYPE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_DEVICE_TYPE_POLICY` (`POLICY_ID` ASC) ,
|
||||
INDEX `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_FEATURES` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(256) NOT NULL ,
|
||||
`CODE` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`EVALUVATION_RULE` VARCHAR(60) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_PROFILE_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
`FEATURE_ID` INT(11) NOT NULL ,
|
||||
`CONTENT` BLOB NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `fk_DM_POLICY_FEATURES_DM_FEATURES1` (`FEATURE_ID` ASC) ,
|
||||
INDEX `FK_DM_PROFILE_DM_POLICY_FEATURES` (`PROFILE_ID` ASC) ,
|
||||
CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1`
|
||||
FOREIGN KEY (`FEATURE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_FEATURES` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_ROLE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_ROLE_POLICY` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_ROLE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`ROLE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_ROLE_POLICY_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_LOCATION`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_LOCATION` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_LOCATION` (
|
||||
`LAT` VARCHAR(45) NOT NULL ,
|
||||
`LONG` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
INDEX `FK_DM_POLICY_DM_LOCATION` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_LOCATION`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_TIME`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_TIME` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_TIME` (
|
||||
`STARTING_TIME` DATETIME NOT NULL ,
|
||||
`ENDING_TIME` DATETIME NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
INDEX `FK_DM_POLICY_DM_TIME` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_TIME`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtTestDBConfigurations>
|
||||
<DBType typeName="MySql">
|
||||
<connectionurl>jdbc:mysql://10.100.0.47:3306/WSO2CDM</connectionurl>
|
||||
<driverclass>com.mysql.jdbc.Driver</driverclass>
|
||||
<userName>root</userName>
|
||||
<pwd>root</pwd>
|
||||
</DBType>
|
||||
<DBType typeName="H2">
|
||||
<connectionurl>jdbc:h2:mem:cdm-test-db;DB_CLOSE_DELAY=-1</connectionurl>
|
||||
<driverclass>org.h2.Driver</driverclass>
|
||||
<userName>wso2carbon</userName>
|
||||
<pwd>wso2carbon</pwd>
|
||||
</DBType>
|
||||
</DeviceMgtTestDBConfigurations>
|
@ -0,0 +1,31 @@
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
|
||||
<suite name="CDM-core-initializer">
|
||||
<parameter name="useDefaultListeners" value="false"/>
|
||||
|
||||
<test name="DAO Unit Tests" preserve-order="true">
|
||||
<parameter name="dbType" value="H2"/>
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
Loading…
Reference in new issue