📄 testdatafactory.java
字号:
/*
* Copyright 2005-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.dozer.util.mapping.util;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.sf.dozer.util.mapping.vo.*;
import net.sf.dozer.util.mapping.vo.deep.Address;
import net.sf.dozer.util.mapping.vo.deep.City;
import net.sf.dozer.util.mapping.vo.deep.House;
import net.sf.dozer.util.mapping.vo.deep.Person;
import net.sf.dozer.util.mapping.vo.deep.Room;
import net.sf.dozer.util.mapping.vo.deep.SrcDeepObj;
import net.sf.dozer.util.mapping.vo.deep.SrcNestedDeepObj;
import net.sf.dozer.util.mapping.vo.deep.SrcNestedDeepObj2;
import net.sf.dozer.util.mapping.vo.inheritance.AnotherSubClass;
import net.sf.dozer.util.mapping.vo.inheritance.S2Class;
import net.sf.dozer.util.mapping.vo.inheritance.SClass;
/**
* @author garsombke.franz
* @author sullins.ben
* @author tierney.matt
*/
public abstract class TestDataFactory {
public static SubClass getSubClass()
{
SubClass obj = new SubClass();
obj.setAttribute( "subclass" );
obj.setSuperAttribute( "superclass" );
List superList = new ArrayList();
superList.add( "one" );
superList.add( "two" );
superList.add( "three" );
obj.setSuperList( superList );
obj.setSuperSuperAttribute("supersuperattribute");
obj.setSuperSuperSuperAttr( "toplevel" );
obj.setTestObject( TestDataFactory.getInputGeneralMappingTestObject() );
HydrateTestObject2 sourceObj = new HydrateTestObject2();
TestCustomConverterObject cobj = new TestCustomConverterObject();
CustomDoubleObjectIF doub = new CustomDoubleObject();
doub.setTheDouble(15);
cobj.setAttribute(doub);
obj.setCustomConvert( cobj );
obj.setHydrate( sourceObj );
obj.setSuperFieldToExclude("superFieldToExclude");
return obj;
}
public static SrcDeepObj getSrcDeepObj() {
SrcDeepObj result = new SrcDeepObj();
SrcNestedDeepObj srcNested = new SrcNestedDeepObj();
SrcNestedDeepObj2 srcNested2 = new SrcNestedDeepObj2();
FurtherTestObjectPrime furtherObjectPrime = new FurtherTestObjectPrime();
srcNested2.setSrc5("nestedsrc2field5");
furtherObjectPrime.setOne("fjd");
srcNested.setSrc1("nestedsrc1");
srcNested.setSrc2(Integer.valueOf("5"));
srcNested.setSrc3(90);
srcNested.setSrc4(new String[] { "item1", "item2", "item3" });
srcNested.setSrcNestedObj2(srcNested2);
srcNested.setSrc6(furtherObjectPrime);
//List to List. String to Integer
List hintList = new ArrayList();
hintList.add("1");
hintList.add("2");
srcNested.setHintList(hintList);
//List to List. TheFirstSubClass to TheFirstSubClassPrime
TheFirstSubClass hintList2Obj = new TheFirstSubClass();
hintList2Obj.setS("test");
TheFirstSubClass hintList2Obj2 = new TheFirstSubClass();
hintList2Obj.setS("test2");
List hintList2 = new ArrayList();
hintList2.add(hintList2Obj);
hintList2.add(hintList2Obj2);
srcNested.setHintList2(hintList2);
result.setSrcNestedObj(srcNested);
result.setSameNameField("sameNameField");
return result;
}
public static House getHouse() {
House house = new House();
Address address = new Address();
address.setStreet("1234 street");
City city = new City();
city.setName("Denver");
address.setCity(city);
house.setAddress(address);
Person person = new Person();
person.setName("Franz");
house.setOwner(person);
house.setPrice(1000000);
Van van = new Van();
van.setName("van");
van.setTestValue("testValue");
house.setVan(van);
Room living = new Room();
living.setName("Living");
Room kitchen = new Room();
kitchen.setName("kitchen");
List rooms = new ArrayList();
rooms.add(living);
rooms.add(kitchen);
house.setRooms(rooms);
List custom = new ArrayList();
Van van2 = new Van();
van2.setName("van2");
custom.add(van2);
house.setCustomSetGetMethod(custom);
return house;
}
public static HydrateTestObject getExpectedTestNoSourceValueIterateFieldMapHydrateTestObject() {
Car car = new Car();
car.setName("Build by buildCar");
HydrateTestObject hto = new HydrateTestObject();
//Problem - Destination Field is array of 'cars' - but getMethod() is buildCar() which returns a Car. MapCollection method can not handle this...
//DestinationType is a Car and it should be an array.
//hto.addCar(car);
hto.setCarArray(new Car[0]);
return hto;
}
public static NoCustomMappingsObject getInputTestNoClassMappingsNoCustomMappingsObject() {
NoCustomMappingsObject custom = new NoCustomMappingsObject();
custom.setStringDataType("stringDataType");
return custom;
}
public static NoCustomMappingsObject getInputTestMapFieldWithMapNoCustomMappingsObject() {
NoCustomMappingsObject custom = new NoCustomMappingsObject();
Map map = new HashMap();
map.put("1", "1value");
map.put("2", "2value");
custom.setMapDataType(map);
return custom;
}
public static NoCustomMappingsObject getInputTestMapFieldWithEmptyMapNoCustomMappingsObject() {
NoCustomMappingsObject custom = new NoCustomMappingsObject();
Map map = new HashMap();
custom.setMapDataType(map);
return custom;
}
public static NoCustomMappingsObject getInputTestSetFieldWithSetNoCustomMappingsObject() {
NoCustomMappingsObject custom = new NoCustomMappingsObject();
Set set = new HashSet();
set.add("1value");
set.add("2value");
custom.setSetDataType(set);
return custom;
}
public static NoCustomMappingsObject getInputTestSetFieldWithSetEmptyCustomMappingsObject() {
NoCustomMappingsObject custom = new NoCustomMappingsObject();
Set set = new HashSet();
custom.setSetDataType(set);
return custom;
}
public static NoCustomMappingsObject getInputTestSetFieldComplexSetNoCustomMappingsObject() {
NoCustomMappingsObject custom = new NoCustomMappingsObject();
Set set = new HashSet();
set.add(getInputTestNoClassMappingsNoCustomMappingsObject());
custom.setSetDataType(set);
return custom;
}
public static TestObject getInputTestListFieldEmptyListTestObject() {
TestObject custom = new TestObject();
custom.setEqualNamedList(new ArrayList());
return custom;
}
public static TestObject getInputTestListFieldArrayListTestObject() {
TestObject custom = new TestObject();
Integer[] array = { new Integer(1) };
custom.setArrayForLists(array);
return custom;
}
public static TestObject getInputTestListUsingDestHintTestObject() {
TestObject custom = new TestObject();
List list = new ArrayList();
list.add(new TheFirstSubClass());
custom.setHintList(list);
return custom;
}
public static TestObject getInputGeneralMappingTestObject() {
TestObject custom = new TestObject();
custom.setOne("one");
custom.setTwo(new Integer(2));
int[] pa = { 0 , 1, 2, 3,4};
custom.setPrimArray( pa );
InsideTestObject ito = new InsideTestObject();
ito.setLabel("label");
ito.setWrapper(new Integer(1));
ito.setToWrapper(1);
custom.setThree(ito);
//testing if it will map two custom objects that are different types but same names //
InsideTestObject ito2 = new InsideTestObject();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -