1 /***
2 * Copyright (C) 2008 rweber <quietgenie@users.sourceforge.net>
3 *
4 * This file is part of CsvObjectMapper.
5 *
6 * CsvObjectMapper is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CsvObjectMapper is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with CsvObjectMapper. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /***
21 *
22 */
23 package com.projectnine.csvmapper;
24
25 import java.math.BigDecimal;
26 import java.util.List;
27 import java.util.Vector;
28
29 import junit.framework.TestCase;
30
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.springframework.core.io.ClassPathResource;
35
36 import com.projectnine.csvmapper.ObjectToCsvMapper;
37 import com.projectnine.spring.SpringLoader;
38
39 /***
40 * @author robweber
41 *
42 */
43 public class ObjectToCsvMapperTest extends TestCase {
44 List<CsvSimpleTestBean> simpleTestBeanList;
45 List<CsvComplexTestBean> complexTestBeanList;
46
47 /***
48 * @throws java.lang.Exception
49 */
50 @Before
51 public void setUp() throws Exception {
52 try {
53 SpringLoader.loadSpringConfiguration(new ClassPathResource(
54 "csvObjectMapper-test.xml"));
55
56 simpleTestBeanList = new Vector<CsvSimpleTestBean>();
57
58 simpleTestBeanList.add(new CsvSimpleTestBean(new BigDecimal(1.01),
59 "Peter Pan"));
60 simpleTestBeanList.add(new CsvSimpleTestBean(new BigDecimal(1.02),
61 "Pooh Bear"));
62 simpleTestBeanList.add(new CsvSimpleTestBean(new BigDecimal(2.01),
63 "Bat Man"));
64
65 complexTestBeanList = new Vector<CsvComplexTestBean>();
66
67 for (int i = 0; i < simpleTestBeanList.size(); i++) {
68 complexTestBeanList.add(new CsvComplexTestBean(
69 simpleTestBeanList.get(i), String.valueOf(i)));
70 }
71 } catch (Exception e) {
72 e.printStackTrace();
73 throw e;
74 }
75 }
76
77 /***
78 * @throws java.lang.Exception
79 */
80 @After
81 public void tearDown() throws Exception {
82 simpleTestBeanList = null;
83 complexTestBeanList = null;
84 SpringLoader.reset();
85 }
86
87 /***
88 * Test method for
89 * {@link com.projectnine.csvmapper.ObjectToCsvMapper#writeObjectsToCsv(java.util.List)}
90 * .
91 */
92 @Test
93 public final void testWriteObjectsToCsv() {
94
95 }
96
97 /***
98 * Test method for
99 * {@link com.projectnine.csvmapper.ObjectToCsvMapper#convertObjectToCsv(java.lang.Object, java.lang.String)}
100 * .
101 *
102 * @throws Exception
103 */
104 @Test
105 public final void testConvertObjectToCsv() throws Exception {
106 try {
107 List<String> list = ObjectToCsvMapper.convertObjectToCsv(
108 complexTestBeanList.get(0), "complexCsvMappingDefinition");
109 System.out.println(list);
110 assertEquals(2, list.size());
111 assertEquals("0", list.get(0));
112 assertEquals(
113 "1.0100000000000000088817841970012523233890533447265625",
114 list.get(1));
115 } catch (Exception e) {
116 e.printStackTrace();
117 throw e;
118 }
119 }
120
121 }