View Javadoc

1   package org.kuali.student.core.assembly.data;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import java.text.DateFormat;
6   import java.text.SimpleDateFormat;
7   import java.util.ArrayList;
8   import java.util.HashMap;
9   import java.util.List;
10  import java.util.Map;
11  
12  import org.junit.Before;
13  import org.junit.Test;
14  import org.kuali.student.core.assembly.transform.DataBeanMapper;
15  import org.kuali.student.core.assembly.transform.DefaultDataBeanMapper;
16  
17  
18  public class TestDataMapper {
19  
20  	MockPerson person;
21  
22  	@Before
23  	public void setup() throws Exception{
24  		person = new MockPerson();
25  		person.setFirstName("first");
26  		person.setLastName("last");
27  		person.setEmail("first@test.com");
28  		person.setType("STUDENT");
29  		person.setState("CREATE");
30  		person.setId("P1");
31  		person.setGpa(3.5);
32  		DateFormat df = new SimpleDateFormat("yy-MM-DD");
33  		person.setDob(df.parse("1978-01-01"));
34  		
35  		
36  		MockAddress address = new MockAddress();
37          address.setState("ACTIVE");
38          address.setType("MAILING");
39          address.setId("A1");
40          address.setCity("TLH");
41          address.setStateCode("FL");
42          address.setCountry("US");
43          address.setLine1("");
44          address.setLine2("line2value");
45          address.setPostalCode("32306");
46  
47          //Add a dynamic attribute
48          Map<String,String> attributes = new HashMap<String,String>();
49          attributes.put("POBox", "1145");
50          attributes.put("building", "Residential");
51          address.setAttributes(attributes);
52          
53          List<MockAddress> addressL = new ArrayList<MockAddress>();
54          addressL.add(address);
55  
56          person.setAddress(addressL);
57  
58  		
59  	}
60  
61  	@Test
62  	public void testConverDTOtoData() throws Exception {
63  		DataBeanMapper dataMapper = new DefaultDataBeanMapper();
64  		
65  		Data data = dataMapper.convertFromBean(person);
66  		Metadata metadata = new Metadata();
67  		MockPerson convertedPerson = (MockPerson)dataMapper.convertFromData(data, MockPerson.class,metadata);
68  
69  		assertEquals(person.getDob(), convertedPerson.getDob());
70  		assertEquals(person.getEmail(), convertedPerson.getEmail());
71  		assertEquals(person.getFirstName(), convertedPerson.getFirstName());
72  		assertEquals(person.getGpa(), convertedPerson.getGpa());
73  		assertEquals(person.getId(), convertedPerson.getId());
74  		assertEquals(person.getLastName(), convertedPerson.getLastName());
75  		assertEquals(person.getState(), convertedPerson.getState());
76  		assertEquals(person.getType(), convertedPerson.getType());
77  			
78  		assertEquals(convertedPerson.getAddress().size(),1);
79  		
80  		MockAddress address = person.getAddress().get(0);
81  		MockAddress convertedAddress = convertedPerson.getAddress().get(0);
82  		
83  		assertEquals(address.getCity(), convertedAddress.getCity());
84  		assertEquals(address.getCountry(), convertedAddress.getCountry());
85  		assertEquals(address.getId(), convertedAddress.getId());
86  		assertEquals(address.getLine1(), convertedAddress.getLine1());
87  		assertEquals(address.getLine2(), convertedAddress.getLine2());
88  		assertEquals(address.getPostalCode(), convertedAddress.getPostalCode());
89  		assertEquals(address.getState(), convertedAddress.getState());
90  		assertEquals(address.getStateCode(), convertedAddress.getStateCode());
91  		assertEquals(address.getType(), convertedAddress.getType());
92  		
93  		Map<String,String> attributes = convertedAddress.getAttributes();
94  		assertEquals(attributes.size(),2);
95  		assertEquals(attributes.get("POBox"),"1145");
96  		assertEquals(attributes.get("building"),"Residential");
97  	}
98  	
99  	
100 
101 }