mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding addition test cases for extensions
This commit is contained in:
parent
4ceafdbb42
commit
c02afcff27
@ -122,6 +122,11 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.sling</groupId>
|
||||
<artifactId>org.apache.sling.testing.osgi-mock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -54,7 +54,6 @@ public class DefaultPolicyMonitoringManager implements PolicyMonitoringManager {
|
||||
if (!complianceFeature.isCompliant()) {
|
||||
nonComplianceFeatures.add(complianceFeature);
|
||||
nonComplianceData.setStatus(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
nonComplianceData.setComplianceFeatures(nonComplianceFeatures);
|
||||
|
||||
@ -44,11 +44,18 @@ public class DeviceTypeExtensionServiceComponent {
|
||||
private static final Log log = LogFactory.getLog(DeviceTypeExtensionServiceComponent.class);
|
||||
|
||||
protected void activate(ComponentContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Activating DeviceType Deployer Service Component");
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Activating DeviceType Deployer Service Component");
|
||||
}
|
||||
ctx.getBundleContext()
|
||||
.registerService(DeviceTypeGeneratorService.class, new DeviceTypeGeneratorServiceImpl(), null);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Device Type Extension Service Component successfully activated");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while initializing device type extension component ", e);
|
||||
}
|
||||
ctx.getBundleContext().registerService(DeviceTypeGeneratorService.class, new DeviceTypeGeneratorServiceImpl()
|
||||
, null);
|
||||
}
|
||||
|
||||
protected void deactivate(ComponentContext ctx) {
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.internal;
|
||||
|
||||
import org.apache.sling.testing.mock.osgi.MockOsgi;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class DeviceTypeExtensionServiceComponentTest {
|
||||
@Test(description = "This test case tests the behaviour of the Service Component when there is a possible "
|
||||
+ "exception")
|
||||
public void testActivateWithException() {
|
||||
DeviceTypeExtensionServiceComponent deviceTypeExtensionServiceComponent = new
|
||||
DeviceTypeExtensionServiceComponent();
|
||||
deviceTypeExtensionServiceComponent.activate(null);
|
||||
}
|
||||
|
||||
@Test(description = "This test case tests the behaviour of the Service Component when the pre-conditions are "
|
||||
+ "satisfied")
|
||||
public void testActivateWithoutException() {
|
||||
DeviceTypeExtensionServiceComponent deviceTypeExtensionServiceComponent = new
|
||||
DeviceTypeExtensionServiceComponent();
|
||||
deviceTypeExtensionServiceComponent.activate(MockOsgi.newComponentContext());
|
||||
}
|
||||
}
|
||||
@ -24,10 +24,16 @@ import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeConfigIdentifier;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.policy.mgt.DefaultPolicyMonitoringManager;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceSchemaInitializer;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils;
|
||||
import org.wso2.carbon.device.mgt.extensions.license.mgt.file.FileSystemBasedLicenseManager;
|
||||
@ -36,6 +42,8 @@ import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedL
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is a test case for testing common utilities used.
|
||||
@ -123,4 +131,26 @@ public class UtilsTest {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(4);
|
||||
DeviceTypeUtils.getConfigurationRegistry();
|
||||
}
|
||||
|
||||
@Test(description = "This test case tests DefaultPolicyMonitoringManager functionality")
|
||||
public void testDefaultPolicyMonitoringManager() throws PolicyComplianceException {
|
||||
List<ComplianceFeature> complianceFeatures = new ArrayList<>();
|
||||
ComplianceFeature complianceFeature = new ComplianceFeature();
|
||||
complianceFeature.setCompliance(true);
|
||||
complianceFeatures.add(complianceFeature);
|
||||
|
||||
ComplianceFeature nonCompliant = new ComplianceFeature();
|
||||
nonCompliant.setCompliance(false);
|
||||
complianceFeatures.add(nonCompliant);
|
||||
DefaultPolicyMonitoringManager policyMonitoringManager = new DefaultPolicyMonitoringManager();
|
||||
NonComplianceData nonComplianceData = policyMonitoringManager
|
||||
.checkPolicyCompliance(new DeviceIdentifier("android", "test"), null, complianceFeatures);
|
||||
Policy policy = new Policy();
|
||||
Assert.assertNull(nonComplianceData.getComplianceFeatures(),
|
||||
"When policy is null policy manager returns a " + "list of non-compilance features");
|
||||
nonComplianceData = policyMonitoringManager
|
||||
.checkPolicyCompliance(new DeviceIdentifier("android", "test"), policy, complianceFeatures);
|
||||
Assert.assertEquals(nonComplianceData.getComplianceFeatures().size(), 1,
|
||||
"Non-compliant feature count does " + "not match with expected count");
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,9 +19,7 @@
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
|
||||
<suite name="DeviceManagementExtensions">
|
||||
<parameter name="useDefaultListeners" value="false"/>
|
||||
|
||||
<test name="DeviceType Manager Service Test Cases" preserve-order="true">
|
||||
<test name="DeviceType Manager Service Test Cases" parallel="none">
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.device.mgt.extensions.device.type.template.BaseExtensionsTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeManagerServiceTest"/>
|
||||
@ -30,6 +28,7 @@
|
||||
<class name="org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceDAODefinitionNegativeTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeManagerNegativeTest" />
|
||||
<class name="org.wso2.carbon.device.mgt.extensions.utils.UtilsTest" />
|
||||
<class name="org.wso2.carbon.device.mgt.extensions.internal.DeviceTypeExtensionServiceComponentTest"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user