KickJava   Java API By Example, From Geeks To Geeks.

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


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.CompositeAction;
23
24 /**
25  * Composite action test
26  *
27  * @author Roy Wetherall
28  */

29 public class CompositeActionImplTest extends ActionImplTest
30 {
31     private static final String JavaDoc ACTION1_ID = "action1Id";
32     private static final String JavaDoc ACTION2_ID = "action2Id";
33     private static final String JavaDoc ACTION3_ID = "action3Id";
34     private static final String JavaDoc ACTION1_NAME = "actionName1";
35     private static final String JavaDoc ACTION2_NAME = "actionName1";
36     private static final String JavaDoc ACTION3_NAME = "actionName3";
37
38     public void testActions()
39     {
40         Action action1 = new ActionImpl(ACTION1_ID, ACTION1_NAME, null);
41         Action action2 = new ActionImpl(ACTION2_ID, ACTION2_NAME, null);
42         Action action3 = new ActionImpl(ACTION3_ID, ACTION3_NAME, null);
43         
44         CompositeAction compositeAction = new CompositeActionImpl(ID, null);
45         
46         // Check has no action
47
assertFalse(compositeAction.hasActions());
48         List JavaDoc<Action> noActions = compositeAction.getActions();
49         assertNotNull(noActions);
50         assertEquals(0, noActions.size());
51     
52         // Add actions
53
compositeAction.addAction(action1);
54         compositeAction.addAction(action2);
55         compositeAction.addAction(action3);
56         
57         // Check that the actions that are there and in the correct order
58
assertTrue(compositeAction.hasActions());
59         List JavaDoc<Action> actions = compositeAction.getActions();
60         assertNotNull(actions);
61         assertEquals(3, actions.size());
62         int counter = 0;
63         for (Action action : actions)
64         {
65             if (counter == 0)
66             {
67                 assertEquals(action1, action);
68             }
69             else if (counter == 1)
70             {
71                 assertEquals(action2, action);
72             }
73             else if (counter == 2)
74             {
75                 assertEquals(action3, action);
76             }
77             counter+=1;
78         }
79         assertEquals(action1, compositeAction.getAction(0));
80         assertEquals(action2, compositeAction.getAction(1));
81         assertEquals(action3, compositeAction.getAction(2));
82         
83         // Check remove
84
compositeAction.removeAction(action3);
85         assertEquals(2, compositeAction.getActions().size());
86         
87         // Check set
88
compositeAction.setAction(1, action3);
89         assertEquals(action1, compositeAction.getAction(0));
90         assertEquals(action3, compositeAction.getAction(1));
91         
92         // Check index of
93
assertEquals(0, compositeAction.indexOfAction(action1));
94         assertEquals(1, compositeAction.indexOfAction(action3));
95         
96         // Test insert
97
compositeAction.addAction(1, action2);
98         assertEquals(3, compositeAction.getActions().size());
99         assertEquals(action1, compositeAction.getAction(0));
100         assertEquals(action2, compositeAction.getAction(1));
101         assertEquals(action3, compositeAction.getAction(2));
102         
103         // Check remote all
104
compositeAction.removeAllActions();
105         assertFalse(compositeAction.hasActions());
106         assertEquals(0, compositeAction.getActions().size());
107     }
108 }
109
Popular Tags