KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > ActionImplTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.action;
18
19 import java.util.List JavaDoc;
20
21 import org.alfresco.service.cmr.action.Action;
22 import org.alfresco.service.cmr.action.ActionCondition;
23 import org.alfresco.util.GUID;
24
25 /**
26  * @author Roy Wetherall
27  */

28 public class ActionImplTest extends BaseParameterizedItemImplTest
29 {
30     private static final String JavaDoc ID_COND1 = "idCond1";
31     private static final String JavaDoc ID_COND2 = "idCond2";
32     private static final String JavaDoc ID_COND3 = "idCond3";
33     private static final String JavaDoc NAME_COND1 = "nameCond1";
34     private static final String JavaDoc NAME_COND2 = "nameCond2";
35     private static final String JavaDoc NAME_COND3 = "nameCond3";
36
37     /**
38      * @see org.alfresco.repo.rule.common.RuleItemImplTest#create()
39      */

40     @Override JavaDoc
41     protected ParameterizedItemImpl create()
42     {
43         return new ActionImpl(
44                 ID,
45                 NAME,
46                 null,
47                 this.paramValues);
48     }
49     
50     public void testGetRuleActionDefintion()
51     {
52         Action temp = (Action)create();
53         assertEquals(NAME, temp.getActionDefinitionName());
54     }
55     
56     public void testSimpleProperties()
57     {
58         Action action = (Action)create();
59         
60         // Check the default values
61
assertFalse(action.getExecuteAsychronously());
62         assertNull(action.getCompensatingAction());
63         
64         // Set some values
65
action.setTitle("title");
66         action.setDescription("description");
67         action.setExecuteAsynchronously(true);
68         Action compensatingAction = new ActionImpl(GUID.generate(), "actionDefintionName", null);
69         action.setCompensatingAction(compensatingAction);
70         
71         // Check the values have been set
72
assertEquals("title", action.getTitle());
73         assertEquals("description", action.getDescription());
74         assertTrue(action.getExecuteAsychronously());
75         assertEquals(compensatingAction, action.getCompensatingAction());
76     }
77     
78     public void testActionConditions()
79     {
80         ActionCondition cond1 = new ActionConditionImpl(ID_COND1, NAME_COND1, this.paramValues);
81         ActionCondition cond2 = new ActionConditionImpl(ID_COND2, NAME_COND2, this.paramValues);
82         ActionCondition cond3 = new ActionConditionImpl(ID_COND3, NAME_COND3, this.paramValues);
83         
84         Action action = (Action)create();
85         
86         // Check has no conditions
87
assertFalse(action.hasActionConditions());
88         List JavaDoc<ActionCondition> noConditions = action.getActionConditions();
89         assertNotNull(noConditions);
90         assertEquals(0, noConditions.size());
91     
92         // Add the conditions to the action
93
action.addActionCondition(cond1);
94         action.addActionCondition(cond2);
95         action.addActionCondition(cond3);
96         
97         // Check that the conditions are there and in the correct order
98
assertTrue(action.hasActionConditions());
99         List JavaDoc<ActionCondition> actionConditions = action.getActionConditions();
100         assertNotNull(actionConditions);
101         assertEquals(3, actionConditions.size());
102         int counter = 0;
103         for (ActionCondition condition : actionConditions)
104         {
105             if (counter == 0)
106             {
107                 assertEquals(cond1, condition);
108             }
109             else if (counter == 1)
110             {
111                 assertEquals(cond2, condition);
112             }
113             else if (counter == 2)
114             {
115                 assertEquals(cond3, condition);
116             }
117             counter+=1;
118         }
119         assertEquals(cond1, action.getActionCondition(0));
120         assertEquals(cond2, action.getActionCondition(1));
121         assertEquals(cond3, action.getActionCondition(2));
122         
123         // Check remove
124
action.removeActionCondition(cond3);
125         assertEquals(2, action.getActionConditions().size());
126         
127         // Check set
128
action.setActionCondition(1, cond3);
129         assertEquals(cond1, action.getActionCondition(0));
130         assertEquals(cond3, action.getActionCondition(1));
131         
132         // Check index of
133
assertEquals(0, action.indexOfActionCondition(cond1));
134         assertEquals(1, action.indexOfActionCondition(cond3));
135         
136         // Test insert
137
action.addActionCondition(1, cond2);
138         assertEquals(3, action.getActionConditions().size());
139         assertEquals(cond1, action.getActionCondition(0));
140         assertEquals(cond2, action.getActionCondition(1));
141         assertEquals(cond3, action.getActionCondition(2));
142         
143         // Check remote all
144
action.removeAllActionConditions();
145         assertFalse(action.hasActionConditions());
146         assertEquals(0, action.getActionConditions().size());
147     }
148 }
149
Popular Tags