001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019: package de.schlund.pfixcore.generator.iwrpgen;
020:
021: import java.io.File;
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import junit.framework.TestCase;
026: import de.schlund.pfixcore.example.test.Bean;
027: import de.schlund.pfixcore.example.test.BeanWrapper;
028: import de.schlund.pfixcore.example.test.Data;
029: import de.schlund.pfixxml.config.GlobalConfigurator;
030:
031: /**
032: * @author mleidig@schlund.de
033: */
034: public class IWrapperBeanTest extends TestCase {
035:
036: @Override
037: protected void setUp() throws Exception {
038: GlobalConfigurator.setDocroot((new File("projects")
039: .getAbsolutePath()));
040: }
041:
042: public void testWrapperToBean() throws Exception {
043:
044: Bean bean = new Bean();
045: bean.setText("text");
046: ArrayList<Integer> values = new ArrayList<Integer>();
047: values.add(1);
048: values.add(2);
049: values.add(3);
050: bean.setValues(values);
051: List<Float> floatValues = new ArrayList<Float>();
052: floatValues.add(1.2f);
053: bean.floatValues = floatValues;
054: Data data = new Data();
055: data.setText("datatext");
056: bean.setData(data);
057: List<Data> dataList = new ArrayList<Data>();
058: dataList.add(data);
059: bean.setDataList(dataList);
060:
061: // Manually init wrapper
062:
063: BeanWrapper wrapper = new BeanWrapper();
064: wrapper.init("test");
065: wrapper.setStringValText("text");
066: wrapper.setStringValValues(new String[] { "1", "2", "3" });
067: wrapper.setStringValFloatValues(new String[] { "1.2" });
068: wrapper.setStringValData("datatext");
069: wrapper.setStringValDataList(new String[] { "datatext" });
070: wrapper.loadFromStringValues();
071:
072: assertEquals(wrapper.getText(), "text");
073: assertEquals(wrapper.getValues().length, values.size());
074: assertEquals(wrapper.getValues()[0], values.get(0));
075: assertEquals(wrapper.getValues()[1], values.get(1));
076: assertEquals(wrapper.getValues()[2], values.get(2));
077: assertEquals(wrapper.getFloatValues().length, floatValues
078: .size());
079: assertEquals(wrapper.getFloatValues()[0], floatValues.get(0));
080: assertEquals(wrapper.getData().getText(), "datatext");
081: assertEquals(wrapper.getDataList()[0].getText(), "datatext");
082:
083: // Create bean from wrapper
084:
085: Bean myBean = IWrapperToBean.createBean(wrapper, Bean.class);
086:
087: assertEquals(myBean.getText(), "text");
088: assertEquals(myBean.getValues(), values);
089: assertEquals(myBean.floatValues, floatValues);
090: assertEquals(myBean.getData().getText(), "datatext");
091: assertEquals(myBean.getDataList().get(0).getText(), "datatext");
092:
093: // Init wrapper with bean
094:
095: BeanWrapper myWrapper = new BeanWrapper();
096: myWrapper.init("test");
097: BeanToIWrapper.populateIWrapper(myBean, myWrapper);
098: myWrapper.loadFromStringValues();
099: assertEquals(myWrapper.getText(), "text");
100: assertEquals(myWrapper.getValues().length, values.size());
101: assertEquals(myWrapper.getValues()[0], values.get(0));
102: assertEquals(myWrapper.getValues()[1], values.get(1));
103: assertEquals(myWrapper.getValues()[2], values.get(2));
104: assertEquals(myWrapper.getFloatValues().length, floatValues
105: .size());
106: assertEquals(myWrapper.getFloatValues()[0], floatValues.get(0));
107: assertEquals(myWrapper.getData().getText(), "datatext");
108: assertEquals(myWrapper.getDataList()[0].getText(), "datatext");
109:
110: }
111:
112: }
|