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