KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensourcestrategies > crmsfa > test > SecurityTests


1 /*
2  * Copyright (c) 2006 - 2007 Open Source Strategies, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the Honest Public License.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * Honest Public License for more details.
11  *
12  * You should have received a copy of the Honest Public License
13  * along with this program; if not, write to Funambol,
14  * 643 Bair Island Road, Suite 305 - Redwood City, CA 94063, USA
15  */

16 /* Copyright (c) 2005-2006 Open Source Strategies, Inc. */
17
18 package com.opensourcestrategies.crmsfa.test;
19
20 import org.ofbiz.base.util.UtilMisc;
21
22 import org.ofbiz.entity.GenericDelegator;
23 import org.ofbiz.entity.GenericEntityException;
24 import org.ofbiz.entity.GenericValue;
25 import org.ofbiz.security.Security;
26 import org.ofbiz.security.SecurityFactory;
27
28 import junit.framework.TestCase;
29
30 import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;
31
32 /**
33  * This is a class of unit tests for CRM/SFA application's security permissions.
34  * To run these, edit ${ofbiz.home}/base/config/test-containers.xml and add the line
35  * <property name="crm-security" value="com.opensourcestrategies.crmsfa.test.SecurityTests"/>
36  * to <container name="junit-container" class="org.ofbiz.base.container.JunitContainer">
37  *
38  * Then, from the command prompt, do either
39  * $ java -jar ofbiz.jar -test
40  *
41  * or
42  * $ ant run-tests
43  *
44  * This will be run along with other test suites, such as those for the entity engine or the service engine
45  *
46  * This test suite requires crmsfa/data/CRMSFADemoData.xml and CRMSFASecurityData.xml to be installed
47  *
48  * Also, make sure that your "test" delegator is set to the correct datasource in framework/entity/config/entityengine.xml
49  *
50  * @author sichen
51  *
52  */

53 public class SecurityTests extends TestCase {
54     
55     public static final String JavaDoc module = SecurityTests.class.getName();
56     public static final String JavaDoc DELEGATOR = "test";
57     private GenericDelegator delegator = null;
58     private Security security = null;
59     
60     public SecurityTests (String JavaDoc name) {
61         super(name);
62     }
63     
64     protected void setUp() throws Exception JavaDoc {
65         this.delegator = GenericDelegator.getGenericDelegator(DELEGATOR);
66         this.security = SecurityFactory.getInstance(delegator);
67     }
68     
69     // DemoSalesManager for DemoAccount1
70

71     /**
72      * This is a template for a security unit case. This tests if DemoSalesManager userLogin has permission to update
73      * DemoAccount1
74      * @throws Exception
75      */

76     public void testDemoAccount1DemoSalesManagerUpdate() throws Exception JavaDoc {
77         try {
78             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
79             boolean hasPermission = false;
80             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) {
81                 hasPermission = true;
82             }
83             TestCase.assertEquals("DemoSalesManager has update permission for DemoAccount1", true, hasPermission);
84         } catch (GenericEntityException ex) {
85             TestCase.fail(ex.getMessage());
86         }
87     }
88     public void testDemoAccount1DemoSalesManagerView() throws Exception JavaDoc {
89         try {
90             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
91             boolean hasPermission = false;
92             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) {
93                 hasPermission = true;
94             }
95             TestCase.assertEquals("DemoSalesManager has view permission for DemoAccount1", true, hasPermission);
96         } catch (GenericEntityException ex) {
97             TestCase.fail(ex.getMessage());
98         }
99     }
100     public void testDemoAccount1DemoSalesManagerDeactivate() throws Exception JavaDoc {
101         try {
102             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
103             boolean hasPermission = false;
104             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) {
105                 hasPermission = true;
106             }
107             TestCase.assertEquals("DemoSalesManager has deactivate permission for DemoAccount1", true, hasPermission);
108         } catch (GenericEntityException ex) {
109             TestCase.fail(ex.getMessage());
110         }
111     }
112     public void testDemoAccount1DemoSalesManagerReassign() throws Exception JavaDoc {
113         try {
114             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
115             boolean hasPermission = false;
116             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) {
117                 hasPermission = true;
118             }
119             TestCase.assertEquals("DemoSalesManager has reassign permission for DemoAccount1", true, hasPermission);
120         } catch (GenericEntityException ex) {
121             TestCase.fail(ex.getMessage());
122         }
123     }
124     
125     // DemoSalesRep1 for DemoAccount1
126
public void testDemoAccount1DemoSalesRep1View() throws Exception JavaDoc {
127         try {
128             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
129             boolean hasPermission = false;
130             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) {
131                 hasPermission = true;
132             }
133             TestCase.assertEquals("DemoSalesRep1 has view permission for DemoAccount1", true, hasPermission);
134         } catch (GenericEntityException ex) {
135             TestCase.fail(ex.getMessage());
136         }
137     }
138     public void testDemoAccount1DemoSalesRep1Update() throws Exception JavaDoc {
139         try {
140             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
141             boolean hasPermission = false;
142             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) {
143                 hasPermission = true;
144             }
145             TestCase.assertEquals("DemoSalesRep1 has update permission for DemoAccount1", false, hasPermission);
146         } catch (GenericEntityException ex) {
147             TestCase.fail(ex.getMessage());
148         }
149     }
150     public void testDemoAccount1DemoSalesRep1Deactivate() throws Exception JavaDoc {
151         try {
152             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
153             boolean hasPermission = false;
154             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) {
155                 hasPermission = true;
156             }
157             TestCase.assertEquals("DemoSalesRep1 has deactivate permission for DemoAccount1", false, hasPermission);
158         } catch (GenericEntityException ex) {
159             TestCase.fail(ex.getMessage());
160         }
161     }
162     public void testDemoAccount1DemoSalesRep1Reassign() throws Exception JavaDoc {
163         try {
164             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
165             boolean hasPermission = false;
166             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) {
167                 hasPermission = true;
168             }
169             TestCase.assertEquals("DemoSalesRep1 has reassign permission for DemoAccount1", false, hasPermission);
170         } catch (GenericEntityException ex) {
171             TestCase.fail(ex.getMessage());
172         }
173     }
174     
175     // DemoSalesRep2 for DemoAccount1
176
public void testDemoAccount1DemoSalesRep2View() throws Exception JavaDoc {
177         try {
178             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));
179             boolean hasPermission = false;
180             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) {
181                 hasPermission = true;
182             }
183             TestCase.assertEquals("DemoSalesRep2 has view permission for DemoAccount1", true, hasPermission);
184         } catch (GenericEntityException ex) {
185             TestCase.fail(ex.getMessage());
186         }
187     }
188     public void testDemoAccount1DemoSalesRep2Update() throws Exception JavaDoc {
189         try {
190             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));
191             boolean hasPermission = false;
192             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) {
193                 hasPermission = true;
194             }
195             TestCase.assertEquals("DemoSalesRep2 has update permission for DemoAccount1", true, hasPermission);
196         } catch (GenericEntityException ex) {
197             TestCase.fail(ex.getMessage());
198         }
199     }
200     public void testDemoAccount1DemoSalesRep2Deactivate() throws Exception JavaDoc {
201         try {
202             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));
203             boolean hasPermission = false;
204             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) {
205                 hasPermission = true;
206             }
207             TestCase.assertEquals("DemoSalesRep2 has deactivate permission for DemoAccount1", false, hasPermission);
208         } catch (GenericEntityException ex) {
209             TestCase.fail(ex.getMessage());
210         }
211     }
212     public void testDemoAccount1DemoSalesRep2Reassign() throws Exception JavaDoc {
213         try {
214             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));
215             boolean hasPermission = false;
216             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) {
217                 hasPermission = true;
218             }
219             TestCase.assertEquals("DemoSalesRep2 has reassign permission for DemoAccount1", false, hasPermission);
220         } catch (GenericEntityException ex) {
221             TestCase.fail(ex.getMessage());
222         }
223     }
224     
225     // DemoSalesRep3 for DemoAccount1
226
public void testDemoAccount1DemoSalesRep3View() throws Exception JavaDoc {
227         try {
228             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3"));
229             boolean hasPermission = false;
230             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) {
231                 hasPermission = true;
232             }
233             TestCase.assertEquals("DemoSalesRep3 has view permission for DemoAccount1", true, hasPermission);
234         } catch (GenericEntityException ex) {
235             TestCase.fail(ex.getMessage());
236         }
237     }
238     public void testDemoAccount1DemoSalesRep3Update() throws Exception JavaDoc {
239         try {
240             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3"));
241             boolean hasPermission = false;
242             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) {
243                 hasPermission = true;
244             }
245             TestCase.assertEquals("DemoSalesRep3 has update permission for DemoAccount1", true, hasPermission);
246         } catch (GenericEntityException ex) {
247             TestCase.fail(ex.getMessage());
248         }
249     }
250     public void testDemoAccount1DemoSalesRep3Deactivate() throws Exception JavaDoc {
251         try {
252             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3"));
253             boolean hasPermission = false;
254             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) {
255                 hasPermission = true;
256             }
257             TestCase.assertEquals("DemoSalesRep3 has deactivate permission for DemoAccount1", true, hasPermission);
258         } catch (GenericEntityException ex) {
259             TestCase.fail(ex.getMessage());
260         }
261     }
262     public void testDemoAccount1DemoSalesRep3Reassign() throws Exception JavaDoc {
263         try {
264             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3"));
265             boolean hasPermission = false;
266             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) {
267                 hasPermission = true;
268             }
269             TestCase.assertEquals("DemoSalesRep3 has reassign permission for DemoAccount1", true, hasPermission);
270         } catch (GenericEntityException ex) {
271             TestCase.fail(ex.getMessage());
272         }
273     }
274     
275     // DemoSalesManager for DemoContact1
276
public void testDemoContact1DemoSalesManagerView() throws Exception JavaDoc {
277         try {
278             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
279             boolean hasPermission = false;
280             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_VIEW", userLogin, "DemoContact1")) {
281                 hasPermission = true;
282             }
283             TestCase.assertEquals("DemoSalesManager has view permission for DemoContact1", true, hasPermission);
284         } catch (GenericEntityException ex) {
285             TestCase.fail(ex.getMessage());
286         }
287     }
288     public void testDemoContact1DemoSalesManagerUpdate() throws Exception JavaDoc {
289         try {
290             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
291             boolean hasPermission = false;
292             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_UPDATE", userLogin, "DemoContact1")) {
293                 hasPermission = true;
294             }
295             TestCase.assertEquals("DemoSalesManager has update permission for DemoContact1", true, hasPermission);
296         } catch (GenericEntityException ex) {
297             TestCase.fail(ex.getMessage());
298         }
299     }
300     public void testDemoContact1DemoSalesManagerDeactivate() throws Exception JavaDoc {
301         try {
302             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
303             boolean hasPermission = false;
304             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_DEACTIVATE", userLogin, "DemoContact1")) {
305                 hasPermission = true;
306             }
307             TestCase.assertEquals("DemoSalesManager has deactivate permission for DemoContact1", true, hasPermission);
308         } catch (GenericEntityException ex) {
309             TestCase.fail(ex.getMessage());
310         }
311     }
312     public void testDemoContact1DemoSalesManagerReassign() throws Exception JavaDoc {
313         try {
314             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
315             boolean hasPermission = false;
316             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) {
317                 hasPermission = true;
318             }
319             TestCase.assertEquals("DemoSalesManager has reassign permission for DemoContact1", true, hasPermission);
320         } catch (GenericEntityException ex) {
321             TestCase.fail(ex.getMessage());
322         }
323     }
324     public void testDemoContact2DemoSalesManagerReassign() throws Exception JavaDoc {
325         try {
326             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
327             boolean hasPermission = false;
328             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) {
329                 hasPermission = true;
330             }
331             TestCase.assertEquals("DemoSalesManager has reassign permission for DemoContact2", true, hasPermission);
332         } catch (GenericEntityException ex) {
333             TestCase.fail(ex.getMessage());
334         }
335     }
336     
337     // DemoSalesRep1 for DemoContact1
338
public void testDemoContact1DemoSalesRep1View() throws Exception JavaDoc {
339         try {
340             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
341             boolean hasPermission = false;
342             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_VIEW", userLogin, "DemoContact1")) {
343                 hasPermission = true;
344             }
345             TestCase.assertEquals("DemoSalesRep1 has view permission for DemoContact1", true, hasPermission);
346         } catch (GenericEntityException ex) {
347             TestCase.fail(ex.getMessage());
348         }
349     }
350     public void testDemoContact1DemoSalesRep1Update() throws Exception JavaDoc {
351         try {
352             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
353             boolean hasPermission = false;
354             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_UPDATE", userLogin, "DemoContact1")) {
355                 hasPermission = true;
356             }
357             TestCase.assertEquals("DemoSalesRep1 has update permission for DemoContact1", false, hasPermission);
358         } catch (GenericEntityException ex) {
359             TestCase.fail(ex.getMessage());
360         }
361     }
362     public void testDemoContact1DemoSalesRep1Deactivate() throws Exception JavaDoc {
363         try {
364             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
365             boolean hasPermission = false;
366             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_DEACTIVATE", userLogin, "DemoContact1")) {
367                 hasPermission = true;
368             }
369             TestCase.assertEquals("DemoSalesRep1 has deactivate permission for DemoContact1", false, hasPermission);
370         } catch (GenericEntityException ex) {
371             TestCase.fail(ex.getMessage());
372         }
373     }
374     public void testDemoContact1DemoSalesRep1Reassign() throws Exception JavaDoc {
375         try {
376             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
377             boolean hasPermission = false;
378             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) {
379                 hasPermission = true;
380             }
381             TestCase.assertEquals("DemoSalesRep1 has reassign permission for DemoContact1", false, hasPermission);
382         } catch (GenericEntityException ex) {
383             TestCase.fail(ex.getMessage());
384         }
385     }
386     public void testDemoContact2DemoSalesRep1Reassign() throws Exception JavaDoc {
387         try {
388             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
389             boolean hasPermission = false;
390             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact2")) {
391                 hasPermission = true;
392             }
393             TestCase.assertEquals("DemoSalesRep1 has reassign permission for DemoContact2", false, hasPermission);
394         } catch (GenericEntityException ex) {
395             TestCase.fail(ex.getMessage());
396         }
397     }
398     // DemoSalesRep2 for DemoContact1
399
public void testDemoContact1DemoSalesRep2View() throws Exception JavaDoc {
400         try {
401             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));
402             boolean hasPermission = false;
403             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_VIEW", userLogin, "DemoContact1")) {
404                 hasPermission = true;
405             }
406             TestCase.assertEquals("DemoSalesRep2 has view permission for DemoContact1", true, hasPermission);
407         } catch (GenericEntityException ex) {
408             TestCase.fail(ex.getMessage());
409         }
410     }
411     public void testDemoContact1DemoSalesRep2Update() throws Exception JavaDoc {
412         try {
413             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));
414             boolean hasPermission = false;
415             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_UPDATE", userLogin, "DemoContact1")) {
416                 hasPermission = true;
417             }
418             TestCase.assertEquals("DemoSalesRep2 has update permission for DemoContact1", true, hasPermission);
419         } catch (GenericEntityException ex) {
420             TestCase.fail(ex.getMessage());
421         }
422     }
423     public void testDemoContact1DemoSalesRep2Deactivate() throws Exception JavaDoc {
424         try {
425             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));
426             boolean hasPermission = false;
427             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_DEACTIVATE", userLogin, "DemoContact1")) {
428                 hasPermission = true;
429             }
430             TestCase.assertEquals("DemoSalesRep2 has deactivate permission for DemoContact1", false, hasPermission);
431         } catch (GenericEntityException ex) {
432             TestCase.fail(ex.getMessage());
433         }
434     }
435     public void testDemoContact1DemoSalesRep2Reassign() throws Exception JavaDoc {
436         try {
437             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));
438             boolean hasPermission = false;
439             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) {
440                 hasPermission = true;
441             }
442             TestCase.assertEquals("DemoSalesRep2 has reassign permission for DemoContact1", false, hasPermission);
443         } catch (GenericEntityException ex) {
444             TestCase.fail(ex.getMessage());
445         }
446     }
447     public void testDemoContact2DemoSalesRep2Reassign() throws Exception JavaDoc {
448         try {
449             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2"));
450             boolean hasPermission = false;
451             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact2")) {
452                 hasPermission = true;
453             }
454             TestCase.assertEquals("DemoSalesRep2 has reassign permission for DemoContact2", false, hasPermission);
455         } catch (GenericEntityException ex) {
456             TestCase.fail(ex.getMessage());
457         }
458     }
459
460     // DemoSalesRep3 for DemoContact1
461
public void testDemoContact1DemoSalesRep3View() throws Exception JavaDoc {
462         try {
463             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3"));
464             boolean hasPermission = false;
465             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_VIEW", userLogin, "DemoContact1")) {
466                 hasPermission = true;
467             }
468             TestCase.assertEquals("DemoSalesRep3 has view permission for DemoContact1", true, hasPermission);
469         } catch (GenericEntityException ex) {
470             TestCase.fail(ex.getMessage());
471         }
472     }
473     public void testDemoContact1DemoSalesRep3Update() throws Exception JavaDoc {
474         try {
475             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3"));
476             boolean hasPermission = false;
477             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_UPDATE", userLogin, "DemoContact1")) {
478                 hasPermission = true;
479             }
480             TestCase.assertEquals("DemoSalesRep3 has update permission for DemoContact1", true, hasPermission);
481         } catch (GenericEntityException ex) {
482             TestCase.fail(ex.getMessage());
483         }
484     }
485     public void testDemoContact1DemoSalesRep3Deactivate() throws Exception JavaDoc {
486         try {
487             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3"));
488             boolean hasPermission = false;
489             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_DEACTIVATE", userLogin, "DemoContact1")) {
490                 hasPermission = true;
491             }
492             TestCase.assertEquals("DemoSalesRep3 has deactivate permission for DemoContact1", false, hasPermission);
493         } catch (GenericEntityException ex) {
494             TestCase.fail(ex.getMessage());
495         }
496     }
497     public void testDemoContact1DemoSalesRep3Reassign() throws Exception JavaDoc {
498         try {
499             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3"));
500             boolean hasPermission = false;
501             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) {
502                 hasPermission = true;
503             }
504             TestCase.assertEquals("DemoSalesRep3 has reassign permission for DemoContact1", false, hasPermission);
505         } catch (GenericEntityException ex) {
506             TestCase.fail(ex.getMessage());
507         }
508     }
509     public void testDemoContact2DemoSalesRep3Reassign() throws Exception JavaDoc {
510         try {
511             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3"));
512             boolean hasPermission = false;
513             if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact2")) {
514                 hasPermission = true;
515             }
516             TestCase.assertEquals("DemoSalesRep3 has reassign permission for DemoContact2", false, hasPermission);
517         } catch (GenericEntityException ex) {
518             TestCase.fail(ex.getMessage());
519         }
520     }
521
522     /**
523      * Test the CrmsfaSecurity.hasActivityPermission() method.
524      */

525     public void testDemoTask1DemoSalesManagerView() throws Exception JavaDoc {
526         try {
527             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
528             boolean hasPermission = false;
529             if (CrmsfaSecurity.hasActivityPermission(security, "_VIEW", userLogin, "DemoTask1", "DemoAccount1", null, null)) {
530                 hasPermission = true;
531             }
532             TestCase.assertEquals("DemoSalesManager can view DemoTask1 which is associated with DemoAccount1", true, hasPermission);
533         } catch (GenericEntityException ex) {
534             TestCase.fail(ex.getMessage());
535         }
536     }
537     public void testDemoTask1DemoSalesManagerUpdate() throws Exception JavaDoc {
538         try {
539             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
540             boolean hasPermission = false;
541             if (CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, "DemoTask1", "DemoAccount1", null, null)) {
542                 hasPermission = true;
543             }
544             TestCase.assertEquals("DemoSalesManager can update DemoTask1 which is associated with DemoAccount1", true, hasPermission);
545         } catch (GenericEntityException ex) {
546             TestCase.fail(ex.getMessage());
547         }
548     }
549     public void testDemoTask1DemoSalesManagerClose() throws Exception JavaDoc {
550         try {
551             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
552             boolean hasPermission = false;
553             if (CrmsfaSecurity.hasActivityPermission(security, "_CLOSE", userLogin, "DemoTask1", "DemoAccount1", null, null)) {
554                 hasPermission = true;
555             }
556             TestCase.assertEquals("DemoSalesManager can close DemoTask1 which is associated with DemoAccount1", true, hasPermission);
557         } catch (GenericEntityException ex) {
558             TestCase.fail(ex.getMessage());
559         }
560     }
561     public void testDemoTask1DemoSalesRep1View() throws Exception JavaDoc {
562         try {
563             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
564             boolean hasPermission = false;
565             if (CrmsfaSecurity.hasActivityPermission(security, "_VIEW", userLogin, "DemoTask1", "DemoAccount1", null, null)) {
566                 hasPermission = true;
567             }
568             TestCase.assertEquals("DemoSalesRep1 can view DemoTask1 which is associated with DemoAccount1", true, hasPermission);
569         } catch (GenericEntityException ex) {
570             TestCase.fail(ex.getMessage());
571         }
572     }
573     public void testDemoTask1DemoSalesRep1Update() throws Exception JavaDoc {
574         try {
575             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
576             boolean hasPermission = false;
577             if (CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, "DemoTask1", "DemoAccount1", null, null)) {
578                 hasPermission = true;
579             }
580             TestCase.assertEquals("DemoSalesRep1 can update DemoTask1 which is associated with DemoAccount1", false, hasPermission);
581         } catch (GenericEntityException ex) {
582             TestCase.fail(ex.getMessage());
583         }
584     }
585     public void testDemoTask1DemoSalesRep1Close() throws Exception JavaDoc {
586         try {
587             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
588             boolean hasPermission = false;
589             if (CrmsfaSecurity.hasActivityPermission(security, "_CLOSE", userLogin, "DemoTask1", "DemoAccount1", null, null)) {
590                 hasPermission = true;
591             }
592             TestCase.assertEquals("DemoSalesRep1 can close DemoTask1 which is associated with DemoAccount1", false, hasPermission);
593         } catch (GenericEntityException ex) {
594             TestCase.fail(ex.getMessage());
595         }
596     }
597
598     /**
599      * Test the CrmsfaSecurity.hasCasePermission() method.
600      */

601     public void testDemoCase1DemoSalesManagerView() throws Exception JavaDoc {
602         try {
603             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
604             boolean hasPermission = false;
605             if (CrmsfaSecurity.hasCasePermission(security, "_VIEW", userLogin, "DemoCase1")) {
606                 hasPermission = true;
607             }
608             TestCase.assertEquals("DemoSalesManager can view DemoCase1", true, hasPermission);
609         } catch (GenericEntityException ex) {
610             TestCase.fail(ex.getMessage());
611         }
612     }
613     public void testDemoCase1DemoSalesManagerUpdate() throws Exception JavaDoc {
614         try {
615             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
616             boolean hasPermission = false;
617             if (CrmsfaSecurity.hasCasePermission(security, "_UPDATE", userLogin, "DemoCase1")) {
618                 hasPermission = true;
619             }
620             TestCase.assertEquals("DemoSalesManager can update DemoCase1", true, hasPermission);
621         } catch (GenericEntityException ex) {
622             TestCase.fail(ex.getMessage());
623         }
624     }
625
626     public void testDemoCase1DemoSalesManagerClose() throws Exception JavaDoc {
627         try {
628             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager"));
629             boolean hasPermission = false;
630             if (CrmsfaSecurity.hasCasePermission(security, "_CLOSE", userLogin, "DemoCase1")) {
631                 hasPermission = true;
632             }
633             TestCase.assertEquals("DemoSalesManager can close DemoCase1", true, hasPermission);
634         } catch (GenericEntityException ex) {
635             TestCase.fail(ex.getMessage());
636         }
637     }
638     public void testDemoCase1DemoSalesRep1View() throws Exception JavaDoc {
639         try {
640             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
641             boolean hasPermission = false;
642             if (CrmsfaSecurity.hasCasePermission(security, "_VIEW", userLogin, "DemoCase1")) {
643                 hasPermission = true;
644             }
645             TestCase.assertEquals("DemoSalesRep1 can view DemoCase1", true, hasPermission);
646         } catch (GenericEntityException ex) {
647             TestCase.fail(ex.getMessage());
648         }
649     }
650     public void testDemoCase1DemoSalesRep1Update() throws Exception JavaDoc {
651         try {
652             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
653             boolean hasPermission = false;
654             if (CrmsfaSecurity.hasCasePermission(security, "_UPDATE", userLogin, "DemoCase1")) {
655                 hasPermission = true;
656             }
657             TestCase.assertEquals("DemoSalesRep1 can update DemoCase1", false, hasPermission);
658         } catch (GenericEntityException ex) {
659             TestCase.fail(ex.getMessage());
660         }
661     }
662     public void testDemoCase1DemoSalesRep1Close() throws Exception JavaDoc {
663         try {
664             GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1"));
665             boolean hasPermission = false;
666             if (CrmsfaSecurity.hasCasePermission(security, "_CLOSE", userLogin, "DemoCase1")) {
667                 hasPermission = true;
668             }
669             TestCase.assertEquals("DemoSalesRep1 can close DemoCase1", false, hasPermission);
670         } catch (GenericEntityException ex) {
671             TestCase.fail(ex.getMessage());
672         }
673     }
674 }
675
Popular Tags