1 package hero.client.test; 2 3 31 import javax.security.auth.login.LoginContext ; 32 import hero.interfaces.ProjectSession; 33 import hero.interfaces.ProjectSessionHome; 34 import hero.interfaces.ProjectSessionUtil; 35 import hero.interfaces.BnNodeValue; 36 import hero.interfaces.UserRegistration; 37 import hero.interfaces.UserRegistrationHome; 38 import hero.interfaces.UserRegistrationUtil; 39 40 import hero.interfaces.AdminSessionHome; 41 import hero.interfaces.AdminSession; 42 import hero.interfaces.AdminSessionUtil; 43 44 import java.util.Collection ; 45 import junit.framework.TestCase; 46 import junit.framework.TestSuite; 47 48 49 public class AdminSessionTests extends TestCase { 50 51 private ProjectSessionHome projectsesh; 52 53 public AdminSessionTests(String testname) { 54 super(testname); 55 } 56 57 public static TestSuite suite() { 58 return new TestSuite(AdminSessionTests.class); 59 } 60 61 public void setUp() throws Exception { 62 } 63 64 public void testGetModels() throws Exception { 65 UserRegistrationHome urHome = UserRegistrationUtil.getHome(); 66 UserRegistration userReg=urHome.create(); 67 userReg.userCreate("userAdmin1","userAdmin1","miguel.valdes-faura@ext.bull.net"); 68 userReg.userCreate("userAdmin2","userAdmin2","miguel.valdes-faura@ext.bull.net"); 69 70 SimpleCallbackHandler handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray()); 71 LoginContext lc = new LoginContext ("TestClient", handler); 72 lc.login(); 73 74 projectsesh=ProjectSessionUtil.getHome(); 75 ProjectSession p = projectsesh.create(); 76 p.initProject("project1"); 77 p.initModel("project2"); 78 79 handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray()); 80 lc = new LoginContext ("TestClient", handler); 81 lc.login(); 82 83 ProjectSession p2 = projectsesh.create(); 84 p2.initModel("project3"); 85 p2.initModel("project4"); 86 87 AdminSessionHome aHome = AdminSessionUtil.getHome(); 88 AdminSession adminsession = aHome.create(); 89 90 Collection models = adminsession.getModels(); 91 assertTrue("Error in getModels, "+models.size(), models.size() == 2); 92 93 handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray()); 94 lc = new LoginContext ("TestClient", handler); 95 lc.login(); 96 } 97 98 public void testInstances() throws Exception { 99 projectsesh=ProjectSessionUtil.getHome(); 100 ProjectSession p = projectsesh.create(); 101 p.initProject("project5"); 102 p.initModel("project6"); 103 104 p.instantiateProject("project6"); 105 p.instantiateProject("project6"); 106 107 SimpleCallbackHandler handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray()); 108 LoginContext lc = new LoginContext ("TestClient", handler); 109 lc.login(); 110 111 ProjectSession p2 = projectsesh.create(); 112 p2.initModel("project7"); 113 p2.initModel("project8"); 114 115 p2.instantiateProject("project7"); 116 p2.instantiateProject("project7"); 117 p2.instantiateProject("project7"); 118 119 handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray()); 120 lc = new LoginContext ("TestClient", handler); 121 lc.login(); 122 123 ProjectSession p3 = projectsesh.create(); 124 p3.instantiateProject("project8"); 125 p3.instantiateProject("project8"); 126 127 handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray()); 128 lc = new LoginContext ("TestClient", handler); 129 lc.login(); 130 131 ProjectSession p4 = projectsesh.create(); 132 p4.instantiateProject("project8"); 133 134 AdminSessionHome aHome = AdminSessionUtil.getHome(); 135 AdminSession adminsession = aHome.create(); 136 137 Collection instances = adminsession.getInstances(); 138 assertTrue("Error in getInstances, "+instances.size(), instances.size() == 6); 139 140 handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray()); 141 lc = new LoginContext ("TestClient", handler); 142 lc.login(); 143 } 144 145 public void testActivities() throws Exception { 146 projectsesh=ProjectSessionUtil.getHome(); 147 ProjectSession p = projectsesh.create(); 148 p.initProject("project9"); 149 p.addNode("node1",1); 150 151 p.initModel("project10"); 152 p.addNode("node1",1); 153 154 p.instantiateProject("project10"); 155 p.instantiateProject("project10"); 156 157 SimpleCallbackHandler handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray()); 158 LoginContext lc = new LoginContext ("TestClient", handler); 159 lc.login(); 160 161 ProjectSession p2 = projectsesh.create(); 162 p2.initModel("project11"); 163 p2.addNode("node1",1); 164 p2.addNode("node2",1); 165 166 p2.initModel("project12"); 167 p2.addNode("node1",1); 168 169 p2.instantiateProject("project11"); 170 p2.instantiateProject("project11"); 171 p2.instantiateProject("project11"); 172 173 handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray()); 174 lc = new LoginContext ("TestClient", handler); 175 lc.login(); 176 177 ProjectSession p3 = projectsesh.create(); 178 p3.instantiateProject("project12"); 179 p3.instantiateProject("project12"); 180 181 handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray()); 182 lc = new LoginContext ("TestClient", handler); 183 lc.login(); 184 185 ProjectSession p4 = projectsesh.create(); 186 p4.instantiateProject("project12"); 187 188 AdminSessionHome aHome = AdminSessionUtil.getHome(); 189 AdminSession adminsession = aHome.create(); 190 191 ProjectSession p5 = projectsesh.create(); 192 p5.initProject("project13"); 193 p5.addNode("node1",1); 194 195 Collection activities = adminsession.getActivities(); 196 assertTrue("Error in getInstances, "+activities.size(), activities.size() == 10); 197 198 handler = new SimpleCallbackHandler("admin", "toto".toCharArray()); 199 lc = new LoginContext ("TestClient", handler); 200 lc.login(); 201 } 202 } 203 | Popular Tags |