From eff3efb72c2d7a3eed1b0860f1fcb94763e634a7 Mon Sep 17 00:00:00 2001 From: megala21 Date: Wed, 27 Sep 2017 20:51:19 +0530 Subject: [PATCH] Refactoring --- .../pom.xml | 24 +++----- .../template/dao/DeviceTypePluginDAOImpl.java | 27 +++++---- ...rviceAndDeviceTypeGeneratorServceTest.java | 34 ++++++++--- .../device/mgt/extensions/utils/Utils.java | 1 - .../src/test/resources/android_sense.xml | 17 +----- .../src/test/resources/arduino.xml | 2 +- .../carbon-home/repository/conf/carbon.xml | 2 +- .../carbon-home/repository/conf/registry.xml | 58 +------------------ .../user-test/user-mgt-registry-test.xml | 32 +++++----- pom.xml | 20 +++++++ 10 files changed, 88 insertions(+), 129 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index 58b1f600a7..f070641070 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -83,27 +83,19 @@ test - commons-dbcp.wso2 - commons-dbcp - 1.4.0.wso2v1 - test + commons-dbcp.wso2 + commons-dbcp + test + + + commons-pool.wso2 + commons-pool + test - - commons-pool.wso2 - commons-pool - 1.5.6.wso2v1 - org.wso2.carbon.governance org.wso2.carbon.governance.registry.extensions - 4.7.8 test - - - org.slf4j - jcl-over-slf4j - - org.wso2.carbon.registry diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java index a71d8c0185..e705661daa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java @@ -252,21 +252,24 @@ public class DeviceTypePluginDAOImpl implements PluginDAO { } private void initializeDbQueries() { - selectDBQueryForGetDevice = "SELECT " + getDeviceTableColumnNames() + " FROM " + - deviceDAODefinition.getDeviceTableName() + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?"; + selectDBQueryForGetDevice = + "SELECT " + getDeviceTableColumnNames() + " FROM " + deviceDAODefinition.getDeviceTableName() + + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?"; - createDBqueryForAddDevice = "INSERT INTO " + deviceDAODefinition.getDeviceTableName() + "(" - + deviceDAODefinition.getPrimaryKey() + " , " + getDeviceTableColumnNames() + ") VALUES (" - + getPreparedInputString(deviceDAODefinition.getColumnNames().size() + 1) + ")"; + createDBqueryForAddDevice = + "INSERT INTO " + deviceDAODefinition.getDeviceTableName() + "(" + deviceDAODefinition.getPrimaryKey() + + " , " + getDeviceTableColumnNames() + ") VALUES (" + getPreparedInputString( + deviceDAODefinition.getColumnNames().size() + 1) + ")"; updateDBQueryForUpdateDevice = "UPDATE " + deviceDAODefinition.getDeviceTableName() + " SET " - + getDeviceTableColumnNamesForUpdateQuery() + " WHERE " + deviceDAODefinition.getPrimaryKey() - + " = ?"; + + getDeviceTableColumnNamesForUpdateQuery() + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?"; - deleteDBQueryToRemoveDevicd = "DELETE FROM " + deviceDAODefinition.getDeviceTableName() - + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?"; + deleteDBQueryToRemoveDevicd = + "DELETE FROM " + deviceDAODefinition.getDeviceTableName() + " WHERE " + deviceDAODefinition + .getPrimaryKey() + " = ?"; - selectDBQueryToGetAllDevice = "SELECT " + getDeviceTableColumnNames() + "," + deviceDAODefinition.getPrimaryKey() + - " FROM " + deviceDAODefinition.getDeviceTableName(); + selectDBQueryToGetAllDevice = + "SELECT " + getDeviceTableColumnNames() + "," + deviceDAODefinition.getPrimaryKey() + " FROM " + + deviceDAODefinition.getDeviceTableName(); } -} \ No newline at end of file +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java index 1ba7f30113..461b9d9f72 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java @@ -1,3 +1,21 @@ +/* + * 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.extensions.device.type.template; import org.testng.Assert; @@ -72,8 +90,7 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { @Test(description = "This test case tests the enrollment of newly added device type") public void testEnrollDevice() throws DeviceManagementException { String deviceId = "testdevice1"; - Device sampleDevice1 = new Device(deviceId, androidSenseDeviceType, "test", "testdevice", - null, null, null); + Device sampleDevice1 = new Device(deviceId, androidSenseDeviceType, "test", "testdevice", null, null, null); Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager().enrollDevice(sampleDevice1), "Enrollment of " + androidSenseDeviceType + " device failed"); Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager() @@ -83,10 +100,10 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { @Test(description = "This test case tests the populate device management service method") public void testPopulateDeviceManagementService() { - DeviceManagementService deviceManagementService = deviceTypeGeneratorService.populateDeviceManagementService - (sampleDeviceType, deviceTypeMetaDefinition); - Assert.assertEquals(deviceManagementService.getType(), sampleDeviceType, "DeviceTypeGeneration for the " - + "sample device type failed"); + DeviceManagementService deviceManagementService = deviceTypeGeneratorService + .populateDeviceManagementService(sampleDeviceType, deviceTypeMetaDefinition); + Assert.assertEquals(deviceManagementService.getType(), sampleDeviceType, + "DeviceTypeGeneration for the " + "sample device type failed"); } /** @@ -113,8 +130,8 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { .getPushNotificationProvider(); PushNotificationConfig pushNotificationConfig = new PushNotificationConfig(pushNotificationProvider.getType(), pushNotificationProvider.isScheduled(), null); - org.wso2.carbon.device.mgt.extensions.device.type.template.config.License license = androidSenseDeviceTypeConfiguration - .getLicense(); + org.wso2.carbon.device.mgt.extensions.device.type.template.config.License license = + androidSenseDeviceTypeConfiguration.getLicense(); License androidSenseLicense = new License(); androidSenseLicense.setText(license.getText()); androidSenseLicense.setLanguage(license.getLanguage()); @@ -138,4 +155,3 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { deviceTypeMetaDefinition.setFeatures(features); } } - diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java index 732110f0e4..0e6c37cd1b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java @@ -151,7 +151,6 @@ public class Utils { deviceDAODefinition = new DeviceDAODefinition(deviceDefinitionTable); } } - } return deviceDAODefinition; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_sense.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_sense.xml index 096f0472a1..fbc58a1115 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_sense.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_sense.xml @@ -22,29 +22,14 @@ Add Keywords Send keywords to the device - - - - - Add Threshold Send Threshold to the device - - - - - Remove words Remove Threshold from the device - - - - - @@ -62,4 +47,4 @@ This is license text - \ No newline at end of file + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml index d5a4426572..eb12e9ccb3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml @@ -40,4 +40,4 @@ This is license text - \ No newline at end of file + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml index f24ee57be2..31752cf9b4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml @@ -1,7 +1,7 @@ - - - - - - - - false - - + + true - admin - - admin - admin - - everyone + admin + + admin + admin + + everyone false 500 - jdbc:h2:target/databasetest/CARBON_TEST - org.h2.Driver - 50 - 60000 - 5 + jdbc:h2:target/databasetest/CARBON_TEST + org.h2.Driver + 50 + 60000 + 5 org.wso2.carbon.user.core.tenant.JDBCTenantManager @@ -62,9 +62,9 @@ true + class="org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager"> true - + login diff --git a/pom.xml b/pom.xml index 7605ee88d8..4163efbdff 100644 --- a/pom.xml +++ b/pom.xml @@ -1538,6 +1538,24 @@ ${power.mock.version} test + + commons-dbcp.wso2 + commons-dbcp + ${commons.dbcp.version} + test + + + org.wso2.carbon.governance + org.wso2.carbon.governance.registry.extensions + ${carbon.governance.version} + test + + + org.slf4j + jcl-over-slf4j + + + @@ -1968,6 +1986,8 @@ 0.7.5.201505241946 1.0b3 1.7.0 + 1.4.0.wso2v1 +