1 package org.kuali.mobility.util.mapper; 2 3 import static org.junit.Assert.assertTrue; 4 5 import java.util.ArrayList; 6 import java.util.List; 7 8 import org.apache.log4j.Logger; 9 import org.junit.Test; 10 import org.kuali.mobility.util.mapper.domain.Seat; 11 12 public class DataMapperImplTest { 13 14 private static final Logger logger = Logger.getLogger( DataMapperImplTest.class ); 15 16 public static final String DATA_URL = "http://ulib.iupui.edu/utility/seats.php?show=locations&type=data"; 17 18 public static final String DATA_FILE = "seatSampleData.xml"; 19 public static final String MAPPING_FILE = "seatMapping.xml"; 20 21 public static final String JSON_DATA_FILE = "sampleJsonData.json"; 22 public static final String JSON_MAPPING_FILE = "sampleJsonMapping.xml"; 23 24 @Test 25 public void testMapData() { 26 27 List<Seat> seats = new ArrayList<Seat>(); 28 try 29 { 30 DataMapperImpl mapper = new DataMapperImpl(); 31 seats = mapper.mapData( seats, DATA_FILE, MAPPING_FILE); 32 } 33 catch( ClassNotFoundException cnfe ) 34 { 35 logger.error( cnfe ); 36 } 37 38 assertTrue( "failed to parse file.", seats != null && seats.size() == 16 ); 39 40 for( Seat s : seats ) 41 { 42 logger.debug( s.getLab() ); 43 logger.debug( "\t"+ s.getFloor() ); 44 logger.debug( "\t"+ s.getBuildingCode() ); 45 logger.debug( "\t"+ s.getAvailability() ); 46 logger.debug( "\t"+ s.getWindowsAvailability() ); 47 logger.debug( "\t"+ s.getMacAvailability() ); 48 } 49 } 50 51 @Test 52 public void testMapJsonData() { 53 54 List<Seat> seats = new ArrayList<Seat>(); 55 try 56 { 57 DataMapperImpl mapper = new DataMapperImpl(); 58 seats = mapper.mapData( seats, JSON_DATA_FILE, JSON_MAPPING_FILE); 59 } 60 catch( ClassNotFoundException cnfe ) 61 { 62 logger.error( cnfe ); 63 } 64 65 assertTrue( "failed to parse file.", seats != null && seats.size() == 3 ); 66 67 for( Seat s : seats ) 68 { 69 logger.debug( s.getLab() ); 70 logger.debug( "\t"+ s.getFloor() ); 71 logger.debug( "\t"+ s.getBuildingCode() ); 72 logger.debug( "\t"+ s.getAvailability() ); 73 logger.debug( "\t"+ s.getWindowsAvailability() ); 74 logger.debug( "\t"+ s.getMacAvailability() ); 75 } 76 } 77 }