KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import junit.framework.TestCase;
26
27 import org.alfresco.service.cmr.action.ParameterDefinition;
28 import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
29
30 /**
31  * @author Roy Wetherall
32  */

33 public abstract class BaseParameterizedItemImplTest extends TestCase
34 {
35     protected List JavaDoc<ParameterDefinition> paramDefs = new ArrayList JavaDoc<ParameterDefinition>();
36     protected Map JavaDoc<String JavaDoc, Serializable JavaDoc> paramValues = new HashMap JavaDoc<String JavaDoc, Serializable JavaDoc>();
37     
38     protected static final String JavaDoc ID = "id";
39     protected static final String JavaDoc NAME = "name";
40     protected static final String JavaDoc TITLE = "title";
41     protected static final String JavaDoc DESCRIPTION = "description";
42     
43     private static final String JavaDoc PARAM_1 = "param1";
44     private static final String JavaDoc VALUE_1 = "value1";
45     private static final String JavaDoc PARAM_2 = "param2";
46     private static final String JavaDoc VALUE_2 = "value2";
47     private static final String JavaDoc PARAM_DISPLAYLABEL = "displayLabel";
48    
49     @Override JavaDoc
50     protected void setUp() throws Exception JavaDoc
51     {
52         // Create param defs
53
paramDefs.add(new ParameterDefinitionImpl(PARAM_1, DataTypeDefinition.TEXT, false, PARAM_DISPLAYLABEL));
54         paramDefs.add(new ParameterDefinitionImpl(PARAM_2, DataTypeDefinition.TEXT, false, PARAM_DISPLAYLABEL));
55         
56         // Create param values
57
paramValues.put(PARAM_1, VALUE_1);
58         paramValues.put(PARAM_2, VALUE_2);
59     }
60     
61     public void testConstructor()
62     {
63         create();
64     }
65
66     protected abstract ParameterizedItemImpl create();
67     
68     public void testGetParameterValues()
69     {
70         ParameterizedItemImpl temp = create();
71         Map JavaDoc<String JavaDoc, Serializable JavaDoc> tempParamValues = temp.getParameterValues();
72         assertNotNull(tempParamValues);
73         assertEquals(2, tempParamValues.size());
74         for (Map.Entry JavaDoc entry : tempParamValues.entrySet())
75         {
76             if (entry.getKey() == PARAM_1)
77             {
78                 assertEquals(VALUE_1, entry.getValue());
79             }
80             else if (entry.getKey() == PARAM_2)
81             {
82                 assertEquals(VALUE_2, entry.getValue());
83             }
84             else
85             {
86                 fail("There is an unexpected entry here.");
87             }
88         }
89     }
90     
91     public void testGetParameterValue()
92     {
93         ParameterizedItemImpl temp = create();
94         assertNull(temp.getParameterValue("bobbins"));
95         assertEquals(VALUE_1, temp.getParameterValue(PARAM_1));
96     }
97     
98     public void testSetParameterValue()
99     {
100         ParameterizedItemImpl temp = create();
101         temp.setParameterValue("bobbins", "value");
102         assertEquals("value", temp.getParameterValue("bobbins"));
103     }
104     
105     public void testGetId()
106     {
107         ParameterizedItemImpl temp = create();
108         assertEquals(ID, temp.getId());
109     }
110 }
111
Popular Tags