Adding more testcases, and cleaning up the code.

4.x.x
sinthuja 7 years ago
parent ef6e7df656
commit b7e682a0bc

@ -74,14 +74,6 @@
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.databridge.commons</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.registry</groupId>
<artifactId>org.wso2.carbon.registry.indexing</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.registry</groupId>
<artifactId>org.wso2.carbon.registry.common</artifactId>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
@ -90,6 +82,11 @@
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.securevault</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -122,9 +119,6 @@
org.wso2.carbon.context;version="${carbon.kernel.version.range}",
org.wso2.carbon.utils;version="${carbon.kernel.version.range}",
org.wso2.carbon.databridge.*;version="${carbon.analytics.common.version.range}",
org.wso2.carbon.registry.core.*;resolution:=optional,
org.wso2.carbon.registry.common.*;version="${carbon.registry.imp.pkg.version.range}",
org.wso2.carbon.registry.indexing.*; version="${carbon.registry.imp.pkg.version.range}",
org.json;version="${commons-json.version}",
javax.xml.*,
javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional,

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.analytics.data.publisher;
import org.w3c.dom.Document;
import org.wso2.carbon.databridge.agent.DataPublisher;
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
import javax.xml.XMLConstants;
@ -28,6 +29,9 @@ import java.io.File;
public class DataPublisherUtil {
private DataPublisherUtil(){
}
public static Document convertToDocument(File file) throws DataPublisherConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);

@ -1,63 +0,0 @@
/*
* Copyright (c) 2016, 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.internal;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
import org.wso2.carbon.registry.indexing.service.TenantIndexingLoader;
public class DataPublisherDataHolder {
private static DataPublisherDataHolder thisInstance = new DataPublisherDataHolder();
private TenantRegistryLoader tenantRegistryLoader;
private TenantIndexingLoader indexLoader;
private RegistryService registryService;
private DataPublisherDataHolder() {
}
public static DataPublisherDataHolder getInstance() {
return thisInstance;
}
public void setTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader){
this.tenantRegistryLoader = tenantRegistryLoader;
}
public TenantRegistryLoader getTenantRegistryLoader(){
return tenantRegistryLoader;
}
public void setIndexLoaderService(TenantIndexingLoader indexLoader) {
this.indexLoader = indexLoader;
}
public TenantIndexingLoader getIndexLoaderService(){
return indexLoader;
}
public RegistryService getRegistryService() {
return registryService;
}
public void setRegistryService(RegistryService registryService) {
this.registryService = registryService;
}
}

@ -26,30 +26,10 @@ import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration;
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherServiceImpl;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
import org.wso2.carbon.registry.indexing.service.TenantIndexingLoader;
/**
* @scr.component name="org.wso2.carbon.device.mgt.analytics.data.publisher.internal.DataPublisherServiceComponent"
* immediate="true"
* @scr.reference name="registry.service"
* interface="org.wso2.carbon.registry.core.service.RegistryService"
* cardinality="1..1"
* policy="dynamic"
* bind="setRegistryService"
* unbind="unsetRegistryService"
* @scr.reference name="tenant.registryloader"
* interface="org.wso2.carbon.registry.core.service.TenantRegistryLoader"
* cardinality="1..1" policy="dynamic"
* bind="setTenantRegistryLoader"
* unbind="unsetTenantRegistryLoader"
* @scr.reference name="tenant.indexloader"
* interface="org.wso2.carbon.registry.indexing.service.TenantIndexingLoader"
* cardinality="1..1"
* policy="dynamic"
* bind="setIndexLoader"
* unbind="unsetIndexLoader"
*/
public class DataPublisherServiceComponent {
@ -62,11 +42,9 @@ public class DataPublisherServiceComponent {
log.debug("Initializing device analytics bundle");
}
AnalyticsConfiguration.init();
BundleContext bundleCtx = componentCtx.getBundleContext();
this.analyticsServiceRef =
bundleCtx.registerService(EventsPublisherService.class, new EventsPublisherServiceImpl(), null);
if (log.isDebugEnabled()) {
log.debug("Device management analytics bundle has been successfully initialized");
}
@ -86,35 +64,4 @@ public class DataPublisherServiceComponent {
log.debug("Device analytics bundle has been successfully deactivated");
}
}
protected void setRegistryService(RegistryService registryService) {
if (registryService != null && log.isDebugEnabled()) {
log.debug("Registry service initialized");
}
DataPublisherDataHolder.getInstance().setRegistryService(registryService);
}
protected void unsetRegistryService(RegistryService registryService) {
DataPublisherDataHolder.getInstance().setRegistryService(null);
}
protected void setTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader) {
DataPublisherDataHolder.getInstance().setTenantRegistryLoader(tenantRegistryLoader);
}
protected void unsetTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader) {
DataPublisherDataHolder.getInstance().setTenantRegistryLoader(null);
}
protected void setIndexLoader(TenantIndexingLoader indexLoader) {
if (indexLoader != null && log.isDebugEnabled()) {
log.debug("IndexLoader service initialized");
}
DataPublisherDataHolder.getInstance().setIndexLoaderService(indexLoader);
}
protected void unsetIndexLoader(TenantIndexingLoader indexLoader) {
DataPublisherDataHolder.getInstance().setIndexLoaderService(null);
}
}

@ -21,13 +21,17 @@ import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.databridge.agent.AgentHolder;
import org.wso2.carbon.databridge.agent.exception.DataEndpointAgentConfigurationException;
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;
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherServiceImpl;
import java.io.File;
import java.lang.reflect.Field;
import java.net.URL;
/**
* This test class will test the methods that are exposed from {@link EventsPublisherService}
@ -89,6 +93,39 @@ public class EventPublisherServiceTest extends BaseAnalyticsDataPublisherTest {
publishAsTenant(new Object[0]);
}
@Test(description = "Publishing with invalid data publisher config",
dependsOnMethods = {"publishAsTenantWithEmptyMetaData", "publishAsTenantWithNoMetaData"},
expectedExceptions = DataPublisherConfigurationException.class)
public void publishWithDataEndpointConfigException() throws DataPublisherConfigurationException,
NoSuchFieldException, IllegalAccessException {
AnalyticsConfiguration analyticsConfiguration = AnalyticsConfiguration.getInstance();
analyticsConfiguration.setReceiverServerUrl("");
Field dataPublisherField = DeviceDataPublisher.class.getDeclaredField("deviceDataPublisher");
dataPublisherField.setAccessible(true);
dataPublisherField.set(dataPublisherField, null);
publishAsTenant(getEventProps());
}
@Test(description = "Publishing with invalid data publisher config",
dependsOnMethods = "publishWithDataEndpointConfigException",
expectedExceptions = DataPublisherConfigurationException.class)
public void publishWithDataAgentConfigException() throws DataPublisherConfigurationException,
NoSuchFieldException, IllegalAccessException, DataEndpointAgentConfigurationException {
AnalyticsConfiguration.init();
Field defaultAgentName = AgentHolder.getInstance().getClass().getDeclaredField("defaultDataEndpointAgentName");
defaultAgentName.setAccessible(true);
defaultAgentName.set(AgentHolder.getInstance(), "dummyAgent");
publishAsTenant(getEventProps());
}
@Test(description = "Publishing with invalid data publisher config",
dependsOnMethods = "publishWithDataAgentConfigException")
public void publishWithDataEndpointException() throws DataPublisherConfigurationException,
NoSuchFieldException, IllegalAccessException, DataEndpointAgentConfigurationException {
AnalyticsConfiguration.init();
}
private void publishAsTenant(Object[] metaData) throws DataPublisherConfigurationException {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(TENANT_DOMAIN, true);

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
* 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..
-->
<DataAgentsConfiguration>
<Agent>
<Name>Thrift</Name>
<DataEndpointClass>org.wso2.carbon.databridge.agent.endpoint.thrift.ThriftDataEndpointNoClass</DataEndpointClass>
<TrustSore>src/test/resources/client-truststore.jks</TrustSore>
<TrustSorePassword>wso2carbon</TrustSorePassword>
<QueueSize>32768</QueueSize>
<BatchSize>200</BatchSize>
<CorePoolSize>1</CorePoolSize>
<SocketTimeoutMS>30000</SocketTimeoutMS>
<MaxPoolSize>1</MaxPoolSize>
<KeepAliveTimeInPool>20</KeepAliveTimeInPool>
<ReconnectionInterval>30</ReconnectionInterval>
<MaxTransportPoolSize>250</MaxTransportPoolSize>
<MaxIdleConnections>250</MaxIdleConnections>
<EvictionTimePeriod>5500</EvictionTimePeriod>
<MinIdleTimeInPool>5000</MinIdleTimeInPool>
<SecureMaxTransportPoolSize>250</SecureMaxTransportPoolSize>
<SecureMaxIdleConnections>250</SecureMaxIdleConnections>
<SecureEvictionTimePeriod>5500</SecureEvictionTimePeriod>
<SecureMinIdleTimeInPool>5000</SecureMinIdleTimeInPool>
<!--<sslEnabledProtocols>TLSv1,TLSv1.1,TLSv1.2</sslEnabledProtocols>-->
<!--<ciphers>SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA</ciphers>-->
</Agent>
<Agent>
<Name>Binary</Name>
<DataEndpointClass>org.wso2.carbon.databridge.agent.endpoint.binary.BinaryDataEndpoint</DataEndpointClass>
<TrustSore>src/test/resources/client-truststore.jks</TrustSore>
<TrustSorePassword>wso2carbon</TrustSorePassword>
<QueueSize>32768</QueueSize>
<BatchSize>200</BatchSize>
<CorePoolSize>1</CorePoolSize>
<MaxPoolSize>1</MaxPoolSize>
<SocketTimeoutMS>30000</SocketTimeoutMS>
<KeepAliveTimeInPool>20</KeepAliveTimeInPool>
<ReconnectionInterval>30</ReconnectionInterval>
<MaxTransportPoolSize>250</MaxTransportPoolSize>
<MaxIdleConnections>250</MaxIdleConnections>
<EvictionTimePeriod>5500</EvictionTimePeriod>
<MinIdleTimeInPool>5000</MinIdleTimeInPool>
<SecureMaxTransportPoolSize>250</SecureMaxTransportPoolSize>
<SecureMaxIdleConnections>250</SecureMaxIdleConnections>
<SecureEvictionTimePeriod>5500</SecureEvictionTimePeriod>
<SecureMinIdleTimeInPool>5000</SecureMinIdleTimeInPool>
<!--<sslEnabledProtocols>TLSv1,TLSv1.1,TLSv1.2</sslEnabledProtocols>-->
<!--<ciphers>SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA</ciphers>-->
</Agent>
</DataAgentsConfiguration>
Loading…
Cancel
Save