diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
index fb5e95c2db8..24ea5e33b67 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
@@ -86,6 +86,10 @@
org.json.wso2
json
+
+ org.wso2.carbon
+ org.wso2.carbon.securevault
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/config/AnalyticsConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/config/AnalyticsConfiguration.java
index 8c08d5eccf4..b758d4cf1c8 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/config/AnalyticsConfiguration.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/config/AnalyticsConfiguration.java
@@ -98,8 +98,12 @@ public class AnalyticsConfiguration {
}
public static void init() throws DataPublisherConfigurationException {
+ init(AnalyticsConfiguration.DEVICE_ANALYTICS_CONFIG_PATH);
+ }
+
+ public static void init(String analyticsConfigPath) throws DataPublisherConfigurationException {
try {
- File authConfig = new File(AnalyticsConfiguration.DEVICE_ANALYTICS_CONFIG_PATH);
+ File authConfig = new File(analyticsConfigPath);
Document doc = DataPublisherUtil.convertToDocument(authConfig);
/* Un-marshaling device analytics configuration */
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/java/org/wso2/carbon/device/mgt/analytics/data/publisher/BaseAnalyticsDataPublisherTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/java/org/wso2/carbon/device/mgt/analytics/data/publisher/BaseAnalyticsDataPublisherTest.java
new file mode 100644
index 00000000000..3d42a3020b3
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/java/org/wso2/carbon/device/mgt/analytics/data/publisher/BaseAnalyticsDataPublisherTest.java
@@ -0,0 +1,57 @@
+/*
+* 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.analytics.data.publisher;
+
+import org.testng.annotations.BeforeSuite;
+import org.wso2.carbon.base.MultitenantConstants;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+
+import java.io.File;
+
+public class BaseAnalyticsDataPublisherTest {
+
+ @BeforeSuite
+ public void init() {
+ setUpCarbonHome();
+ }
+
+ private void setUpCarbonHome() {
+ if (System.getProperty("carbon.home") == null) {
+ File file = new File("src/test/resources/carbon-home");
+ if (file.exists()) {
+ System.setProperty("carbon.home", file.getAbsolutePath());
+ }
+ file = new File("carbon-home");
+ if (file.exists()) {
+ System.setProperty("carbon.home", file.getAbsolutePath());
+ }
+ file = new File("../../resources/carbon-home");
+ if (file.exists()) {
+ System.setProperty("carbon.home", file.getAbsolutePath());
+ }
+ file = new File("../../../resources/carbon-home");
+ if (file.exists()) {
+ System.setProperty("carbon.home", file.getAbsolutePath());
+ }
+ }
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants
+ .SUPER_TENANT_DOMAIN_NAME);
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DataPublisherConfigTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DataPublisherConfigTest.java
new file mode 100644
index 00000000000..99c7c628fbc
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DataPublisherConfigTest.java
@@ -0,0 +1,47 @@
+/*
+* 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.analytics.data.publisher;
+
+import junit.framework.Assert;
+import org.testng.annotations.Test;
+import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration;
+import org.wso2.carbon.device.mgt.analytics.data.publisher.config.InvalidConfigurationStateException;
+import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
+
+public class DataPublisherConfigTest extends BaseAnalyticsDataPublisherTest {
+
+ @Test(description = "Validating the behaviour od getInstance of the config before calling the init",
+ expectedExceptions = InvalidConfigurationStateException.class)
+ public void testGetInstanceWithoutInit(){
+ AnalyticsConfiguration.getInstance();
+ }
+
+ public void testInitWithInvalidConfig() throws DataPublisherConfigurationException {
+ AnalyticsConfiguration.init();
+ }
+
+ @Test (description = "Validating the init method with all required params", dependsOnMethods = "testGetInstanceWithoutInit")
+ public void testInit() throws DataPublisherConfigurationException {
+ AnalyticsConfiguration.init();
+ AnalyticsConfiguration analyticsConfiguration = AnalyticsConfiguration.getInstance();
+ Assert.assertEquals(analyticsConfiguration.getAdminPassword(), "testuserpwd");
+ Assert.assertEquals(analyticsConfiguration.getAdminUsername(), "testuser");
+ Assert.assertEquals(analyticsConfiguration.getReceiverServerUrl(), "tcp://localhost:7615");
+ Assert.assertTrue(analyticsConfiguration.isEnable());
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml
new file mode 100644
index 00000000000..31752cf9b44
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml
@@ -0,0 +1,656 @@
+
+
+
+
+
+
+
+
+ ${product.name}
+
+
+ ${product.key}
+
+
+ ${product.version}
+
+
+
+
+
+
+
+
+ local:/${carbon.context}/services/
+
+
+
+
+
+
+ ${default.server.role}
+
+
+
+
+
+
+ org.wso2.carbon
+
+
+ /
+
+
+
+
+
+
+
+
+ 15
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+ 9999
+
+ 11111
+
+
+
+
+
+ 10389
+
+ 8000
+
+
+
+
+
+ 10500
+
+
+
+
+
+
+ org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory
+
+
+
+
+
+
+
+
+ java
+
+
+
+
+
+
+
+
+
+ false
+
+
+ false
+
+
+ 600
+
+
+
+ false
+
+
+
+
+
+
+
+ 30
+
+
+
+
+
+
+
+
+ 15
+
+
+
+
+
+ ${carbon.home}/repository/deployment/server/
+
+
+ 15
+
+
+ ${carbon.home}/repository/conf/axis2/axis2.xml
+
+
+ 30000
+
+
+ ${carbon.home}/repository/deployment/client/
+
+ ${carbon.home}/repository/conf/axis2/axis2_client.xml
+
+ true
+
+
+
+
+
+
+
+
+
+ admin
+ Default Administrator Role
+
+
+ user
+ Default User Role
+
+
+
+
+
+
+
+
+
+
+
+ ${carbon.home}/repository/resources/security/wso2carbon.jks
+
+ JKS
+
+ wso2carbon
+
+ wso2carbon
+
+ wso2carbon
+
+
+
+
+
+ ${carbon.home}/repository/resources/security/client-truststore.jks
+
+ JKS
+
+ wso2carbon
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UserManager
+
+
+ false
+
+
+
+
+
+
+ ${carbon.home}/tmp/work
+
+
+
+
+
+ true
+
+
+ 10
+
+
+ 30
+
+
+
+
+
+ 100
+
+
+
+ keystore
+ certificate
+ *
+
+ org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor
+
+
+
+
+ jarZip
+
+ org.wso2.carbon.ui.transports.fileupload.JarZipUploadExecutor
+
+
+
+ dbs
+
+ org.wso2.carbon.ui.transports.fileupload.DBSFileUploadExecutor
+
+
+
+ tools
+
+ org.wso2.carbon.ui.transports.fileupload.ToolsFileUploadExecutor
+
+
+
+ toolsAny
+
+ org.wso2.carbon.ui.transports.fileupload.ToolsAnyFileUploadExecutor
+
+
+
+
+
+
+ - info
+ org.wso2.carbon.core.transports.util.InfoProcessor
+
+
+ - wsdl
+ org.wso2.carbon.core.transports.util.Wsdl11Processor
+
+
+ - wsdl2
+ org.wso2.carbon.core.transports.util.Wsdl20Processor
+
+
+ - xsd
+ org.wso2.carbon.core.transports.util.XsdProcessor
+
+
+
+
+
+ false
+ false
+ true
+ svn
+ http://svnrepo.example.com/repos/
+ username
+ password
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${require.carbon.servlet}
+
+
+
+
+ true
+
+
+
+
+
+
+ default repository
+ ${p2.repo.url}
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+ true
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/etc/device-analytics-config-invalid.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/etc/device-analytics-config-invalid.xml
new file mode 100644
index 00000000000..99667d3cb54
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/etc/device-analytics-config-invalid.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+ tcp://localhost:7615
+ testuser
+ testuserpwd
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/etc/device-analytics-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/etc/device-analytics-config.xml
new file mode 100644
index 00000000000..8edea74667b
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/etc/device-analytics-config.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+ true
+ tcp://localhost:7615
+ testuser
+ testuserpwd
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/registry.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/registry.xml
new file mode 100644
index 00000000000..a226ae80a81
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/carbon-home/repository/conf/registry.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+ wso2registry
+ false
+ true
+ /
+
+
+ jdbc:h2:./target/databasetest/CARBON_TEST
+
+ org.h2.Driver
+ 80
+ 60000
+ 5
+
+
+ false
+
+
+
+ true
+ true
+ true
+ true
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/testng.xml
new file mode 100644
index 00000000000..0c032caff25
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/test/resources/testng.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
index 4f7611215c6..87481961f43 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
@@ -300,11 +300,6 @@
org.wso2.carbon.apimgt.annotations
provided
-
- org.wso2.carbon.devicemgt
- org.wso2.carbon.device.mgt.analytics.dashboard
- provided
-
org.wso2.orbit.com.fasterxml.jackson.core
jackson-annotations
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java
index 21261bef2b6..466d92becf2 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java
@@ -44,7 +44,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
-import org.wso2.carbon.email.sender.core.service.EmailSenderServiceImpl;
import org.wso2.carbon.registry.core.config.RegistryContext;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
@@ -85,7 +84,7 @@ public abstract class BaseDeviceManagementTest {
NotificationManagementDAOFactory.init(dataSource);
}
- protected void initServices() throws DeviceManagementException, RegistryException {
+ private void initServices() throws DeviceManagementException, RegistryException, AxisFault {
DeviceConfigurationManager.getInstance().initConfig();
DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl();
DeviceManagementServiceComponent.notifyStartupListeners();
@@ -108,17 +107,10 @@ public abstract class BaseDeviceManagementTest {
return context.getEmbeddedRegistryService();
}
- private ConfigurationContextService getConfigContextService() throws RegistryException {
- ConfigurationContext context =
- null;
- try {
- context = ConfigurationContextFactory.createConfigurationContextFromFileSystem
- ("src/test/resources/carbon-home/repository/conf/axis2/axis2.xml");
- } catch (AxisFault axisFault) {
- axisFault.printStackTrace();
- }
- ConfigurationContextService service = new ConfigurationContextService(context, null);
- return service;
+ private ConfigurationContextService getConfigContextService() throws RegistryException, AxisFault {
+ ConfigurationContext context = ConfigurationContextFactory.createConfigurationContextFromFileSystem
+ ("src/test/resources/carbon-home/repository/conf/axis2/axis2.xml");
+ return new ConfigurationContextService(context, null);
}
@BeforeClass
@@ -183,47 +175,6 @@ public abstract class BaseDeviceManagementTest {
}
}
- public void deleteData() {
- Connection conn = null;
- try {
- conn = getDataSource().getConnection();
- conn.setAutoCommit(false);
- String[] cleanupTables = new String[]{"DM_NOTIFICATION","DM_DEVICE_OPERATION_RESPONSE","DM_ENROLMENT_OP_MAPPING", "DM_CONFIG_OPERATION",
- "DM_POLICY_OPERATION", "DM_COMMAND_OPERATION", "DM_PROFILE_OPERATION", "DM_DEVICE_GROUP_MAP",
- "DM_GROUP", "DM_ENROLMENT", "DM_DEVICE_APPLICATION_MAPPING",
- "DM_APPLICATION", "DM_DEVICE", "DM_DEVICE_TYPE"};
- for (String table : cleanupTables) {
- this.cleanData(conn, table);
- }
- conn.commit();
- } catch (SQLException e) {
- try {
- if (conn != null) {
- conn.rollback();
- }
- } catch (SQLException e1) {
- log.error("Error occurred while roll-backing the transaction", e);
- }
- String msg = "Error occurred while cleaning up temporary data generated during test execution";
- log.error(msg, e);
- Assert.fail(msg, e);
- } finally {
- if (conn != null) {
- try {
- conn.close();
- } catch (SQLException e) {
- log.warn("Error occurred while closing the connection", e);
- }
- }
- }
- }
-
- private void cleanData(Connection conn, String tableName) throws SQLException {
- try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + tableName)) {
- stmt.execute();
- }
- }
-
protected DataSource getDataSource() {
return dataSource;
}
diff --git a/pom.xml b/pom.xml
index 949aaa1ea96..4bf590b242d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -402,6 +402,12 @@
+
+ org.wso2.carbon
+ org.wso2.carbon.securevault
+ ${carbon.kernel.version}
+ test
+
org.wso2.carbon.governance
org.wso2.carbon.governance.api