KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > webservice > test > ActionServiceSystemTest


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.webservice.test;
18
19 import org.alfresco.webservice.action.Action;
20 import org.alfresco.webservice.action.ActionExecutionResult;
21 import org.alfresco.webservice.action.ActionItemDefinition;
22 import org.alfresco.webservice.action.ActionItemDefinitionType;
23 import org.alfresco.webservice.action.ActionServiceSoapBindingStub;
24 import org.alfresco.webservice.action.ParameterDefinition;
25 import org.alfresco.webservice.action.Rule;
26 import org.alfresco.webservice.action.RuleType;
27 import org.alfresco.webservice.types.NamedValue;
28 import org.alfresco.webservice.types.Node;
29 import org.alfresco.webservice.types.Predicate;
30 import org.alfresco.webservice.types.Reference;
31 import org.alfresco.webservice.util.Constants;
32 import org.alfresco.webservice.util.WebServiceFactory;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 /**
37  * @author Roy Wetherall
38  */

39 public class ActionServiceSystemTest extends BaseWebServiceSystemTest
40 {
41     private static Log logger = LogFactory.getLog(ActionServiceSystemTest.class);
42     
43     private ActionServiceSoapBindingStub actionService = null;
44     
45     public ActionServiceSystemTest()
46     {
47         this.actionService = WebServiceFactory.getActionService();
48     }
49     
50     public void testGetActionDefinitions() throws Exception JavaDoc
51     {
52         ActionItemDefinition[] definitions = this.actionService.getActionDefinitions();
53         assertNotNull(definitions);
54         assertTrue(definitions.length > 0);
55         
56         if (logger.isDebugEnabled() == true)
57         {
58             // Output the names and titles of the action definitions
59
System.out.println("Action definitions:");
60             for (ActionItemDefinition definition : definitions)
61             {
62                 System.out.println(definition.getName() + " - " + definition.getTitle());
63             }
64             System.out.println("");
65         }
66     }
67     
68     public void testGetConditionDefinitions() throws Exception JavaDoc
69     {
70         ActionItemDefinition[] definitions = this.actionService.getConditionDefinitions();
71         assertNotNull(definitions);
72         assertTrue(definitions.length > 0);
73         
74         if (logger.isDebugEnabled() == true)
75         {
76             // Output the names and titles of the action definitions
77
System.out.println("Condition definitions:");
78             for (ActionItemDefinition definition : definitions)
79             {
80                 System.out.println(definition.getName() + " - " + definition.getTitle());
81             }
82             System.out.println("");
83         }
84     }
85     
86     public void testGetActionItemDefinition() throws Exception JavaDoc
87     {
88         // Get an action
89
ActionItemDefinition actionDefinition = this.actionService.getActionItemDefinition("add-features", ActionItemDefinitionType.action);
90         assertNotNull(actionDefinition);
91         assertEquals("add-features", actionDefinition.getName());
92         assertNotNull(actionDefinition.getTitle());
93         assertNotNull(actionDefinition.getDescription());
94         assertEquals(ActionItemDefinitionType.action, actionDefinition.getType());
95         assertTrue(actionDefinition.isAdHocPropertiesAllowed());
96         assertNotNull(actionDefinition.getParameterDefinition());
97         
98         // Check that the parameters are correct
99
assertTrue(actionDefinition.getParameterDefinition().length == 1);
100         ParameterDefinition param = actionDefinition.getParameterDefinition()[0];
101         assertEquals("aspect-name", param.getName());
102         assertTrue(param.isIsMandatory());
103         assertEquals("{http://www.alfresco.org/model/dictionary/1.0}qname", param.getType());
104         
105         // Get a condition
106
ActionItemDefinition conditionDefintion = this.actionService.getActionItemDefinition("no-condition", ActionItemDefinitionType.condition);
107         assertNotNull(conditionDefintion);
108         assertEquals("no-condition", conditionDefintion.getName());
109         assertNotNull(conditionDefintion.getTitle());
110         assertNotNull(conditionDefintion.getDescription());
111         assertEquals(ActionItemDefinitionType.condition, conditionDefintion.getType());
112         assertFalse(conditionDefintion.isAdHocPropertiesAllowed());
113         assertNull(conditionDefintion.getParameterDefinition());
114         
115         // Check what happens when bad name provided
116
ActionItemDefinition bad = this.actionService.getActionItemDefinition("badName", ActionItemDefinitionType.condition);
117         assertNull(bad);
118     }
119     
120     public void testGetRuleTypes() throws Exception JavaDoc
121     {
122         RuleType[] ruleTypes = this.actionService.getRuleTypes();
123         assertNotNull(ruleTypes);
124         assertTrue(ruleTypes.length > 0);
125         
126         if (logger.isDebugEnabled() == true)
127         {
128             System.out.println("Rule types:");
129             for (RuleType type : ruleTypes)
130             {
131                 System.out.println(type.getName() + " - " + type.getDisplayLabel());
132             }
133         }
134         
135         RuleType ruleType = this.actionService.getRuleType("inbound");
136         assertNotNull(ruleType);
137         assertEquals("inbound", ruleType.getName());
138         assertNotNull(ruleType.getDisplayLabel());
139         
140         // Check what happens when a bad name is provided
141
RuleType badRuleType = this.actionService.getRuleType("basRuleName");
142         assertNull(badRuleType);
143     }
144     
145     public void testActionPeristance() throws Exception JavaDoc
146     {
147         // Check there are no actions
148
Action[] actions1 = this.actionService.getActions(BaseWebServiceSystemTest.contentReference, null);
149         assertNull(actions1);
150         
151         // Create a new action
152
NamedValue[] parameters = new NamedValue[]{new NamedValue("aspect-name", Constants.ASPECT_VERSIONABLE)};
153         Action newAction1 = new Action();
154         newAction1.setActionName("add-features");
155         newAction1.setTitle("Add the versionable aspect to the node.");
156         newAction1.setDescription("This will add the verisonable aspect to the node and thus create a version history.");
157         newAction1.setExecuteAsynchronously(false);
158         newAction1.setParameters(parameters);
159         
160         // Save the action
161
Action[] saveResults1 = this.actionService.saveActions(BaseWebServiceSystemTest.contentReference, new Action[]{newAction1});
162         assertNotNull(saveResults1);
163         assertEquals(1, saveResults1.length);
164         Action savedAction1 = saveResults1[0];
165         assertNotNull(savedAction1);
166         assertNotNull(savedAction1.getId());
167         assertEquals(BaseWebServiceSystemTest.contentReference.getUuid(), savedAction1.getReference().getUuid());
168         assertEquals("add-features", savedAction1.getActionName());
169         assertEquals("Add the versionable aspect to the node.", savedAction1.getTitle());
170         assertEquals("This will add the verisonable aspect to the node and thus create a version history.", savedAction1.getDescription());
171         assertFalse(savedAction1.isExecuteAsynchronously());
172         
173         // Check the parameters of the saved action
174
// TODO
175

176         // Update the action
177
savedAction1.setTitle("The title has been updated");
178         savedAction1.setExecuteAsynchronously(true);
179         
180         // Save the action
181
Action[] saveResults2 = this.actionService.saveActions(BaseWebServiceSystemTest.contentReference, new Action[]{savedAction1});
182         assertNotNull(saveResults2);
183         assertEquals(1, saveResults2.length);
184         Action savedAction2 = saveResults2[0];
185         assertNotNull(savedAction2);
186         assertEquals(savedAction2.getId(), savedAction2.getId());
187         assertEquals(BaseWebServiceSystemTest.contentReference.getUuid(), savedAction2.getReference().getUuid());
188         assertEquals("add-features", savedAction2.getActionName());
189         assertEquals("The title has been updated", savedAction2.getTitle());
190         assertEquals("This will add the verisonable aspect to the node and thus create a version history.", savedAction2.getDescription());
191         assertTrue(savedAction2.isExecuteAsynchronously());
192         
193         // TODO test action filters
194

195         // Remove the all the actions
196
this.actionService.removeActions(BaseWebServiceSystemTest.contentReference, null);
197         
198         // Check all actions have gone
199
Action[] actions3 = this.actionService.getActions(BaseWebServiceSystemTest.contentReference, null);
200         assertNull(actions3);
201     }
202     
203     public void testActionExecution() throws Exception JavaDoc
204     {
205         Predicate predicate = new Predicate(new Reference[]{BaseWebServiceSystemTest.contentReference}, BaseWebServiceSystemTest.store, null);
206         
207         // First confirm that the content reference does not have the versionable aspect applied
208
Node node1 = this.repositoryService.get(predicate)[0];
209         for(String JavaDoc aspect : node1.getAspects())
210         {
211             if (Constants.ASPECT_VERSIONABLE.equals(aspect) == true)
212             {
213                 fail("The content node already has the versionable aspect applied");
214             }
215         }
216         
217         // Create the action to add the versionable aspect
218
NamedValue[] parameters = new NamedValue[]{new NamedValue("aspect-name", Constants.ASPECT_VERSIONABLE)};
219         Action newAction1 = new Action();
220         newAction1.setActionName("add-features");
221         newAction1.setTitle("Add the versionable aspect to the node.");
222         newAction1.setDescription("This will add the verisonable aspect to the node and thus create a version history.");
223         newAction1.setExecuteAsynchronously(false);
224         newAction1.setParameters(parameters);
225         
226         // Execute the action
227
ActionExecutionResult[] results = this.actionService.executeActions(predicate, new Action[]{newAction1});
228         
229         // Check the execution results
230
assertNotNull(results);
231         assertEquals(1, results.length);
232         ActionExecutionResult result = results[0];
233         assertEquals(BaseWebServiceSystemTest.contentReference.getUuid(), result.getReference().getUuid());
234         assertNotNull(result.getActions());
235         assertEquals(1, result.getActions().length);
236         Action resultAction = result.getActions()[0];
237         assertEquals("add-features", resultAction.getActionName());
238         
239         // Check that the versionable aspect has now been applied to that reference
240
Node node2 = this.repositoryService.get(predicate)[0];
241         boolean bFail = true;
242         for(String JavaDoc aspect : node2.getAspects())
243         {
244             if (Constants.ASPECT_VERSIONABLE.equals(aspect) == true)
245             {
246                 bFail = false;
247             }
248         }
249         if (bFail == true)
250         {
251             fail("The action was executed but the versionable aspect has not been applied to the content reference");
252         }
253     }
254     
255     public void testRulePersistance() throws Exception JavaDoc
256     {
257         // Check there are no rules
258
Rule[] rules1 = this.actionService.getRules(BaseWebServiceSystemTest.contentReference, null);
259         assertNull(rules1);
260         
261         // Create the action
262
NamedValue[] parameters = new NamedValue[]{new NamedValue("aspect-name", Constants.ASPECT_CLASSIFIABLE)};
263         Action newAction = new Action();
264         newAction.setActionName("add-features");
265         newAction.setParameters(parameters);
266         
267         // Create the rule
268
Rule newRule = new Rule();
269         newRule.setRuleType("incomming");
270         newRule.setTitle("This rule adds the classificable aspect");
271         newRule.setActions(new Action[]{newAction});
272         
273         // Save the rule
274
Rule[] saveResults1 = this.actionService.saveRules(BaseWebServiceSystemTest.contentReference, new Rule[]{newRule});
275         assertNotNull(saveResults1);
276         assertEquals(1, saveResults1.length);
277         Rule savedRule1 = saveResults1[0];
278         assertNotNull(savedRule1);
279         assertNotNull(savedRule1.getId());
280         assertEquals(BaseWebServiceSystemTest.contentReference.getUuid(), savedRule1.getReference().getUuid());
281         assertEquals("incomming", savedRule1.getRuleType());
282         assertEquals("This rule adds the classificable aspect", savedRule1.getTitle());
283         assertFalse(savedRule1.isExecuteAsynchronously());
284         
285         // Check the actions of the saved rule
286
// TODO
287

288         // Update the rule
289
savedRule1.setTitle("The title has been updated");
290         savedRule1.setExecuteAsynchronously(true);
291         
292         // Save the action
293
Rule[] saveResults2 = this.actionService.saveRules(BaseWebServiceSystemTest.contentReference, new Rule[]{savedRule1});
294         assertNotNull(saveResults2);
295         assertEquals(1, saveResults2.length);
296         Rule savedRule2 = saveResults2[0];
297         assertNotNull(savedRule2);
298         assertEquals(savedRule2.getId(), savedRule2.getId());
299         assertEquals(BaseWebServiceSystemTest.contentReference.getUuid(), savedRule2.getReference().getUuid());
300         assertEquals("incomming", savedRule2.getRuleType());
301         assertEquals("The title has been updated", savedRule2.getTitle());
302         assertTrue(savedRule2.isExecuteAsynchronously());
303         
304         // TODO test rule filters
305

306         // Remove the all the rules
307
this.actionService.removeRules(BaseWebServiceSystemTest.contentReference, null);
308         
309         // Check all rules have gone
310
Rule[] rules3 = this.actionService.getRules(BaseWebServiceSystemTest.contentReference, null);
311         assertNull(rules3);
312     }
313 }
314
Popular Tags