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