1   /*
2    *  soapUI, copyright (C) 2004-2009 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  package com.eviware.soapui.impl.wsdl.support.xsd;
13  
14  import java.util.ArrayList;
15  import java.util.Arrays;
16  import java.util.LinkedHashMap;
17  import java.util.Map;
18  
19  import javax.xml.namespace.QName;
20  
21  import junit.framework.TestCase;
22  
23  import com.eviware.soapui.config.StringListConfig;
24  
25  /***
26   * 
27   * @author lars
28   */
29  public class SettingUtilsTestCase extends TestCase
30  {
31     public void testqnameValues2String() throws Exception
32     {
33        LinkedHashMap<QName, String[]> valueMap = new LinkedHashMap<QName, String[]>();
34        valueMap.put(new QName("x"), new String[] { "1", "2", "3" } );
35        valueMap.put(new QName("ns2", "y"), new String[] { "a", "b", "c" } );
36        
37        ArrayList<String> expected = new ArrayList<String>();
38        expected.add("x=1,2,3");
39        expected.add("y@ns2=a,b,c");
40        String result = SettingUtils.qnameValues2String(valueMap);
41        StringListConfig config = StringListConfig.Factory.parse(result);
42        assertEquals(expected, config.getEntryList());
43        
44        assertEquals(valueMap2String(valueMap),
45              valueMap2String(SettingUtils.string2QNameValues(result)));
46     }
47     
48     private static String valueMap2String(Map<QName, String[]> valueMap)
49     {
50        StringBuffer buf = new StringBuffer();
51        for(QName qname : valueMap.keySet())
52        {
53           String[] values = valueMap.get(qname);
54           buf.append(qname.toString()).append("=");
55           buf.append(Arrays.toString(values));
56           buf.append("\n");
57        }
58        return buf.toString();
59     }
60  }