View Javadoc

1   package au.com.bytecode.opencsv.bean;
2   
3   /**
4    Copyright 2007 Kyle Miller.
5   
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9   
10   http://www.apache.org/licenses/LICENSE-2.0
11  
12   Unless required by applicable law or agreed to in writing, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   See the License for the specific language governing permissions and
16   limitations under the License.
17   */
18  
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  
24  import java.io.StringReader;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  
29  import org.junit.Test;
30  
31  
32  public class HeaderColumnNameTranslateMappingStrategyTest {
33  
34  	@Test
35      public void testParse() {
36          String s = "n,o,foo\n" +
37                  "kyle,123456,emp123\n" +
38                  "jimmy,abcnum,cust09878";
39          HeaderColumnNameTranslateMappingStrategy<MockBean> strat = new HeaderColumnNameTranslateMappingStrategy<MockBean>();
40          strat.setType(MockBean.class);
41          Map<String, String> map = new HashMap<String, String>();
42          map.put("n", "name");
43          map.put("o", "orderNumber");
44          map.put("foo", "id");
45          strat.setColumnMapping(map);
46  
47          CsvToBean<MockBean> csv = new CsvToBean<MockBean>();
48          List<MockBean> list = csv.parse(strat, new StringReader(s));
49          assertNotNull(list);
50          assertTrue(list.size() == 2);
51          MockBean bean = list.get(0);
52          assertEquals("kyle", bean.getName());
53          assertEquals("123456", bean.getOrderNumber());
54          assertEquals("emp123", bean.getId());
55      }
56  
57  }