View Javadoc

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