1 17 package org.alfresco.repo.action; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 22 import java.util.List ; 23 import java.util.Map ; 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 33 public abstract class BaseParameterizedItemImplTest extends TestCase 34 { 35 protected List <ParameterDefinition> paramDefs = new ArrayList <ParameterDefinition>(); 36 protected Map <String , Serializable > paramValues = new HashMap <String , Serializable >(); 37 38 protected static final String ID = "id"; 39 protected static final String NAME = "name"; 40 protected static final String TITLE = "title"; 41 protected static final String DESCRIPTION = "description"; 42 43 private static final String PARAM_1 = "param1"; 44 private static final String VALUE_1 = "value1"; 45 private static final String PARAM_2 = "param2"; 46 private static final String VALUE_2 = "value2"; 47 private static final String PARAM_DISPLAYLABEL = "displayLabel"; 48 49 @Override 50 protected void setUp() throws Exception 51 { 52 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 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 <String , Serializable > tempParamValues = temp.getParameterValues(); 72 assertNotNull(tempParamValues); 73 assertEquals(2, tempParamValues.size()); 74 for (Map.Entry 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 |