Adding no database table exists test cases.

revert-70aa11f8
sinthuja 7 years ago
parent 40dd5bee18
commit 258108df64

@ -17,7 +17,8 @@
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>

@ -21,10 +21,7 @@ package org.wso2.carbon.device.mgt.core.common;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.w3c.dom.Document;
@ -59,14 +56,11 @@ import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public abstract class BaseDeviceManagementTest {
private DataSource dataSource;
private static final Log log = LogFactory.getLog(BaseDeviceManagementTest.class);
@BeforeSuite
public void setupDataSource() throws Exception {
@ -77,7 +71,8 @@ public abstract class BaseDeviceManagementTest {
}
protected void initDataSource() throws Exception {
this.dataSource = this.getDataSource(this.readDataSourceConfig());
this.dataSource = this.getDataSource(this.
readDataSourceConfig("src/test/resources/config/datasource/data-source-config.xml"));
DeviceManagementDAOFactory.init(dataSource);
GroupManagementDAOFactory.init(dataSource);
OperationManagementDAOFactory.init(dataSource);
@ -116,7 +111,7 @@ public abstract class BaseDeviceManagementTest {
@BeforeClass
public abstract void init() throws Exception;
private DataSource getDataSource(DataSourceConfig config) {
protected DataSource getDataSource(DataSourceConfig config) {
PoolProperties properties = new PoolProperties();
properties.setUrl(config.getUrl());
properties.setDriverClassName(config.getDriverClassName());
@ -151,9 +146,9 @@ public abstract class BaseDeviceManagementTest {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
}
private DataSourceConfig readDataSourceConfig() throws DeviceManagementException {
protected DataSourceConfig readDataSourceConfig(String configLocation) throws DeviceManagementException {
try {
File file = new File("src/test/resources/config/datasource/data-source-config.xml");
File file = new File(configLocation);
Document doc = DeviceManagerUtil.convertToDocument(file);
JAXBContext testDBContext = JAXBContext.newInstance(DataSourceConfig.class);
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();

@ -0,0 +1,194 @@
/*
* Copyright (c) 2017, 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.core.operation;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
/**
* This is the testcase which covers the methods from {@link OperationManager}
*/
public class OperationManagementNoDBSchemaTests extends BaseDeviceManagementTest {
private static final String DEVICE_TYPE = "NEG_OP_TEST_TYPE";
private static final String DEVICE_ID_PREFIX = "NEG_OP-TEST-DEVICE-ID-";
private static final String COMMAND_OPERATON_CODE = "COMMAND-TEST";
private static final int NO_OF_DEVICES = 5;
private static final String ADMIN_USER = "admin";
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
private OperationManager operationMgtService;
@BeforeClass
public void init() throws Exception {
DataSource datasource = this.getDataSource(this.
readDataSourceConfig("src/test/resources/config/datasource/no-table-data-source-config.xml"));
OperationManagementDAOFactory.init(datasource);
for (int i = 0; i < NO_OF_DEVICES; i++) {
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
}
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
DeviceManagementProviderService deviceMgtService = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider();
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
for (Device device : devices) {
deviceMgtService.enrollDevice(device);
}
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
for (Device device : returnedDevices) {
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
}
}
NotificationStrategy notificationStrategy = new TestNotificationStrategy();
this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy);
}
@Test(description = "add operation", expectedExceptions = OperationManagementException.class)
public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
InvalidDeviceException {
this.operationMgtService.addOperation(
OperationManagementTests.getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
this.deviceIds);
}
@Test(description = "Get operations", expectedExceptions = OperationManagementException.class)
public void getOperations() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
for (DeviceIdentifier deviceIdentifier : deviceIds) {
this.operationMgtService.getOperations(deviceIdentifier);
}
}
@Test(description = "Get Pending operations", expectedExceptions = OperationManagementException.class)
public void getPendingOperations() throws DeviceManagementException, OperationManagementException,
InvalidDeviceException {
for (DeviceIdentifier deviceIdentifier : deviceIds) {
this.operationMgtService.getPendingOperations(deviceIdentifier);
}
}
@Test(description = "Get paginated request", expectedExceptions = OperationManagementException.class)
public void getPaginatedRequestAsAdmin() throws OperationManagementException {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
PaginationRequest request = new PaginationRequest(1, 2);
request.setDeviceType(DEVICE_TYPE);
request.setOwner(ADMIN_USER);
for (DeviceIdentifier deviceIdentifier : deviceIds) {
this.operationMgtService.getOperations(deviceIdentifier, request);
}
PrivilegedCarbonContext.endTenantFlow();
}
@Test(description = "Update operation", expectedExceptions = OperationManagementException.class)
public void updateOperation() throws OperationManagementException {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
Operation operation = OperationManagementTests.getOperation(new CommandOperation(), Operation.Type.COMMAND,
COMMAND_OPERATON_CODE);
operation.setStatus(Operation.Status.COMPLETED);
operation.setOperationResponse("The operation is successfully completed");
this.operationMgtService.updateOperation(deviceIdentifier, operation);
}
@Test(description = "Get next pending operation", expectedExceptions = OperationManagementException.class)
public void getNextPendingOperation() throws OperationManagementException {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
this.operationMgtService.getNextPendingOperation(deviceIdentifier);
}
@Test(description = "get operation by device and operation id",
expectedExceptions = OperationManagementException.class)
public void getOperationByDeviceAndOperationId() throws OperationManagementException {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier, 1);
}
@Test(description = "Get operation by device and status",
expectedExceptions = OperationManagementException.class)
public void getOperationsByDeviceAndStatus() throws OperationManagementException, DeviceManagementException {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier,
Operation.Status.PENDING);
}
@Test(description = "Get operation by operation id", expectedExceptions = OperationManagementException.class)
public void getOperation() throws OperationManagementException, DeviceManagementException {
this.operationMgtService.getOperation(1);
}
@Test(description = "Get operation activity", expectedExceptions = OperationManagementException.class)
public void getOperationActivity() throws OperationManagementException {
this.operationMgtService.getOperationByActivityId
(DeviceManagementConstants.OperationAttributes.ACTIVITY + "1");
}
@Test(description = "Get operation by activity id and device",
expectedExceptions = OperationManagementException.class)
public void getOperationByActivityIdAndDevice() throws OperationManagementException {
this.operationMgtService.getOperationByActivityIdAndDevice(
DeviceManagementConstants.OperationAttributes.ACTIVITY + "1", this.deviceIds.get(0));
}
@Test(description = "Get activities updated after some time",
expectedExceptions = OperationManagementException.class)
public void getOperationUpdatedAfterWithLimitAndOffset() throws OperationManagementException {
this.operationMgtService.getActivitiesUpdatedAfter(System.currentTimeMillis() / 1000, 10, 0);
}
@Test(description = "Get activity count updated after",
expectedExceptions = OperationManagementException.class)
public void getActivityCountUpdatedAfter() throws OperationManagementException {
this.operationMgtService.getActivityCountUpdatedAfter(System.currentTimeMillis() / 1000);
}
@AfterClass
public void resetDatabase() throws DeviceManagementException {
OperationManagementDAOFactory.init(this.getDataSource(this.
readDataSourceConfig("src/test/resources/config/datasource/data-source-config.xml")));
}
}

@ -45,6 +45,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ Copyright (c) 2017, 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.
-->
<DataSourceConfig>
<Url>jdbc:h2:mem:nodb-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true</Url>
<DriverClassName>org.h2.Driver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -1,4 +1,3 @@
<!--
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
@ -41,9 +40,10 @@
<class name="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServiceTest"/>
<class name="org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceTest"/>
<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementTests"/>
<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementNoDBSchemaTests"/>
<class name="org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceTest"/>
<class name="org.wso2.carbon.device.mgt.core.operation.ScheduledTaskOperationTests"/>
<class name="org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceTest" />
<class name="org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceTest"/>
<class name="org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImplTests"/>
<class name="org.wso2.carbon.device.mgt.core.push.notification.mgt.task.PushNotificationSchedulerTaskTest"/>
<class name="org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerServiceTest"/>

Loading…
Cancel
Save