001    package org.andromda.cartridges.bpm4struts;
002    
003    import junit.framework.TestCase;
004    
005    import java.util.Arrays;
006    
007    public class Bpm4StrutsUtilsTest
008            extends TestCase
009    {
010        public Bpm4StrutsUtilsTest(String name)
011        {
012            super(name);
013        }
014    
015        public void testParseValidatorArgs() throws Exception
016        {
017            final Object[][] fixture = new Object[][]{new Object[]{"myValidator", new Object[0]}, new Object[]{
018                "myValidator(myVar=myArg)", new Object[]{"myArg"}}, new Object[]{
019                    "myValidator(myVar=myArg,myOtherVar=myOtherArg)", new Object[]{"myArg", "myOtherArg"}}};
020    
021            for (Object[] objects : fixture)
022            {
023                assertTrue(Arrays.equals(Bpm4StrutsUtils.parseValidatorArgs((String) objects[0]).toArray(),
024                        (Object[]) objects[1]));
025            }
026        }
027    
028        public void testParseValidatorVars() throws Exception
029        {
030            final Object[][] fixture = new Object[][]{new Object[]{"myValidator", new Object[0]}, new Object[]{
031                "myValidator(myVar=myArg)", new Object[]{"myVar"}}, new Object[]{
032                    "myValidator(myVar=myArg,myOtherVar=myOtherArg)", new Object[]{"myVar", "myOtherVar"}}};
033    
034            for (Object[] objects : fixture)
035            {
036                assertTrue(Arrays.equals(Bpm4StrutsUtils.parseValidatorVars((String) objects[0]).toArray(),
037                        (Object[]) objects[1]));
038            }
039        }
040    
041        public void testParseValidatorName() throws Exception
042        {
043            final String[][] fixture = new String[][]{new String[]{"myValidator", "myValidator"}, new String[]{
044                "myValidator(myVar=myArg)", "myValidator"}, new String[]{"myValidator(myVar=myArg,myOtherVar=myOtherArg)",
045                                                                         "myValidator"}};
046    
047            for (String[] strings : fixture)
048            {
049                assertEquals(Bpm4StrutsUtils.parseValidatorName(strings[0]), strings[1]);
050            }
051        }
052    
053        public void testToWebFileName() throws Exception
054        {
055            final String[][] fixture = new String[][]{
056                new String[]{"singleword", "singleword"},
057                new String[]{"two words", "two-words"},
058                new String[]{" stuff   with whitespace  ", "stuff-with-whitespace"}};
059    
060            for (String[] strings : fixture)
061            {
062                assertEquals(Bpm4StrutsUtils.toWebFileName(strings[0]), strings[1]);
063            }
064        }
065    }