revert-70aa11f8
prabathabey 10 years ago
commit 518892fedd

@ -78,6 +78,10 @@
<groupId>org.wso2.carbon</groupId> <groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId> <artifactId>org.wso2.carbon.logging</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -24,4 +24,27 @@ public class Feature {
private String name; private String name;
private Object attribute; private Object attribute;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getAttribute() {
return attribute;
}
public void setAttribute(Object attribute) {
this.attribute = attribute;
}
} }

@ -25,4 +25,27 @@ public class Policy {
private String policyName; private String policyName;
private List<Feature> featuresList; private List<Feature> featuresList;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPolicyName() {
return policyName;
}
public void setPolicyName(String policyName) {
this.policyName = policyName;
}
public List<Feature> getFeaturesList() {
return featuresList;
}
public void setFeaturesList(List<Feature> featuresList) {
this.featuresList = featuresList;
}
} }

@ -0,0 +1,56 @@
/*
* Copyright (c) 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.policy.mgt.common.impl;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.spi.PolicyManagerService;
public class PolicyManagement implements PolicyManagerService {
@Override
public int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException {
return 0;
}
@Override
public int addPolicyToDeviceType(String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException {
return 0;
}
@Override
public int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException {
return 0;
}
@Override
public Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException {
return null;
}
@Override
public Policy getPolicyOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException {
return null;
}
@Override
public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException {
return null;
}
}

@ -18,7 +18,9 @@
package org.wso2.carbon.policy.mgt.common.spi; package org.wso2.carbon.policy.mgt.common.spi;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
/** /**
* This interface defines the policy management which should be implemented by the plugins * This interface defines the policy management which should be implemented by the plugins
@ -35,7 +37,7 @@ public interface PolicyManagerService {
* @param policy * @param policy
*/ */
void addPolicyToDevice(String deviceId, String deviceType, Policy policy); int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException;
/** /**
* This method adds a policy to device type by the related device type plugins. * This method adds a policy to device type by the related device type plugins.
@ -43,14 +45,14 @@ public interface PolicyManagerService {
* @param policy * @param policy
*/ */
void addPolicyToDeviceType(String deviceType,Policy policy); int addPolicyToDeviceType(String deviceType,Policy policy) throws FeatureManagementException, PolicyManagementException;
/** /**
* This method adds the policy to specific role. * This method adds the policy to specific role.
* @param roleName * @param roleName
* @param policy * @param policy
*/ */
void addPolicyToRole(String roleName, Policy policy); int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException;
// Policy getPolicy(); // Policy getPolicy();
@ -61,7 +63,7 @@ public interface PolicyManagerService {
* @return Policy * @return Policy
*/ */
Policy getPolicyOfDevice(String deviceId, String deviceType); Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException;
/** /**
* This method returns the device type specific policy. * This method returns the device type specific policy.
@ -69,7 +71,7 @@ public interface PolicyManagerService {
* @return Policy * @return Policy
*/ */
Policy getPolicyOfDeviceType(String deviceType); Policy getPolicyOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException;
/** /**
* This method returns the role specific policy. * This method returns the role specific policy.
@ -77,7 +79,7 @@ public interface PolicyManagerService {
* @return * @return
*/ */
Policy getPolicyOfRole(String roleName); Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException;
} }

@ -0,0 +1,59 @@
/*
* Copyright (c) 2005-2014, 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.wos2.carbon.policy.mgt.common;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.wos2.carbon.policy.mgt.common.utils.PolicyCreator;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.impl.PolicyManagement;
public class PolicyManagementTestCase {
private static final Log log = LogFactory.getLog(PolicyManagementTestCase.class);
PolicyCreator creator = new PolicyCreator();
Policy policy = creator.getPolicy();
private PolicyManagement policyManagement = new PolicyManagement();
@Test(groups = "policy.mgt.test", description = "Testing the first test case with testng.")
public void testPolicy() {
Assert.assertEquals("A", "A");
}
@Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device")
public void testAddPolicy() {
try {
Assert.assertEquals(policyManagement.addPolicyToDevice("1212-ESDD-12ER-7890", "MD", policy), 0);
} catch (FeatureManagementException e) {
log.error("Feature management exception happened.", e);
Assert.fail();
} catch (PolicyManagementException e) {
log.error("Policy management exception happened.", e);
Assert.fail();
}
}
}

@ -0,0 +1,55 @@
/*
* Copyright (c) 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.wos2.carbon.policy.mgt.common.utils;
import org.wso2.carbon.policy.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.Policy;
import java.util.ArrayList;
import java.util.List;
public class PolicyCreator {
private Policy policy = new Policy();
public PolicyCreator() {
createPolicy();
}
private void createPolicy() {
Feature feature = new Feature();
feature.setName("Camera");
feature.setCode("502A");
feature.setAttribute("disable");
List<Feature> featureList = new ArrayList<Feature>();
featureList.add(feature);
policy.setFeaturesList(featureList);
policy.setPolicyName("Camera_related_policy");
}
public Policy getPolicy() {
return policy;
}
}
Loading…
Cancel
Save