1 19 20 package com.sslexplorer.policies; 21 22 import static org.junit.Assert.assertEquals; 23 24 import org.junit.BeforeClass; 25 import org.junit.Test; 26 27 import com.sslexplorer.core.UserDatabaseManager; 28 import com.sslexplorer.policyframework.Policy; 29 import com.sslexplorer.realms.Realm; 30 import com.sslexplorer.testcontainer.AbstractTest; 31 32 34 public class PoliciesTest extends AbstractTest { 35 36 37 40 @BeforeClass 41 public static void oneTimeSetUp() throws Exception { 42 setUp(""); 43 } 44 45 48 @Test 49 public void createPolicy() throws Exception { 50 Realm realm = getUserService().getRealm(1); 51 assertEquals("There should be only one policy", getPolicyService().getPolicies().size(), 1); 52 Policy policy = getPolicyService().createPolicy("Policy A", "Policy A description", Policy.TYPE_NORMAL, realm.getRealmID()); 53 assertEquals("There should be only two policies", getPolicyService().getPolicies().size(), 2); 54 getPolicyService().deletePolicy(policy.getResourceId()); 55 assertEquals("There should be only one policy", getPolicyService().getPolicies().size(), 1); 56 } 57 58 61 @Test 62 public void updatePolicyName() throws Exception { 63 String newPolicyName = "NewName"; 64 Realm realm = getUserService().getRealm(1); 65 Policy policy = createPolicy(realm); 66 policy.setResourceName(newPolicyName); 67 getPolicyService().updatePolicy(policy); 68 Policy updatedPolicy = getPolicyService().getPolicy(policy.getResourceId()); 69 assertEquals("The new policy name should be " + newPolicyName, newPolicyName, updatedPolicy.getResourceName()); 70 getPolicyService().deletePolicy(policy.getResourceId()); 71 } 72 73 76 @Test 77 public void updatePolicyDescription() throws Exception { 78 String newPolicyDescription = "NewDescription"; 79 Realm realm = getUserService().getRealm(1); 80 Policy policy = createPolicy(realm); 81 policy.setResourceDescription(newPolicyDescription); 82 getPolicyService().updatePolicy(policy); 83 Policy updatedPolicy = getPolicyService().getPolicy(policy.getResourceId()); 84 assertEquals("The new policy description should be " + newPolicyDescription, newPolicyDescription, updatedPolicy.getResourceDescription()); 85 getPolicyService().deletePolicy(policy.getResourceId()); 86 } 87 88 91 @Test 92 public void checkPolicyRetrieval() throws Exception { 93 Realm realm = getUserService().getRealm(1); 94 Policy policy = createPolicy(realm); 95 Policy retrievedById = getPolicyService().getPolicy(policy.getResourceId()); 96 Policy retrievedByName = getPolicyService().getPolicyByName(policy.getResourceName(), realm.getResourceId()); 97 assertEquals("The policies should be the same.", retrievedById, retrievedByName); 98 getPolicyService().deletePolicy(policy.getResourceId()); 99 } 100 101 105 public static UserDatabaseManager getUserService() throws Exception { 106 return UserDatabaseManager.getInstance(); 107 } 108 109 private static Policy createPolicy(Realm realm) throws Exception { 110 return createPolicy("Policy A", "Policy A description", Policy.TYPE_NORMAL, realm); 111 } 112 113 private static Policy createPolicy(String name, String description, int type, Realm realm) throws Exception { 114 return getPolicyService().createPolicy(name, description, type, realm.getRealmID()); 115 } 116 } | Popular Tags |