1 package org.kuali.ole.ingest;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.junit.runner.RunWith;
6 import org.kuali.ole.ingest.pojo.OleLocationGroup;
7 import org.kuali.ole.ingest.pojo.OleLocationIngest;
8 import org.kuali.ole.ingest.pojo.OleLocationGroup;
9 import org.kuali.ole.service.OleLocationConverterService;
10 import org.kuali.ole.service.OleLocationService;
11 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.context.ApplicationContext;
14 import org.springframework.test.context.ContextConfiguration;
15 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
16 import org.springframework.test.context.transaction.TransactionConfiguration;
17 import org.springframework.transaction.annotation.Transactional;
18
19 import java.io.File;
20 import java.net.URL;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import static junit.framework.Assert.*;
25
26
27
28
29
30
31
32
33
34 @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
35 @RunWith(value = SpringJUnit4ClassRunner.class)
36 @TransactionConfiguration(defaultRollback = true)
37 public class OleLocationConverterService_UT {
38 private OleLocationConverterService oleLocationConverterService;
39 @Autowired
40 private ApplicationContext applicationContext;
41
42 @Before
43 public void setUp() throws Exception {
44 oleLocationConverterService = new OleLocationConverterService();
45 }
46
47
48 @Test
49 @Transactional
50 public void testCreateLocationRecord() throws Exception {
51 URL resource = getClass().getResource("oleLocations.xml");
52 File file = new File(resource.toURI());
53 String fileContent = new FileUtil().readFile(file);
54 OleLocationConverterService oleLocationRecordService = GlobalResourceLoader.getService("oleLocationConverterService");
55 String oleLocations = oleLocationRecordService.persistLocationFromFileContent(fileContent,"oleLocations.xml");
56 assertNotNull(oleLocations);
57 }
58
59 @Test
60 @Transactional
61 public void testBuildLocationFromFileContent() throws Exception {
62 URL resource = getClass().getResource("oleLocations.xml");
63 File file = new File(resource.toURI());
64 String fileContent = new FileUtil().readFile(file);
65 OleLocationGroup oleLocationGroup = oleLocationConverterService.buildLocationFromFileContent(fileContent);
66 assertNotNull(oleLocationGroup);
67 assertNotNull(oleLocationGroup.getLocationGroup());
68 List<OleLocationIngest> locations = oleLocationGroup.getLocationGroup();
69 assertTrue(!locations.isEmpty());
70 for (Iterator<OleLocationIngest> iterator = locations.iterator(); iterator.hasNext(); ) {
71 OleLocationIngest location = iterator.next();
72 assertNotNull(location);
73 assertNotNull(location.getLocationCode());
74 }
75 }
76
77
78
79 }