1 package org.kuali.ole.license.checkList;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.junit.runner.RunWith;
6 import org.kuali.ole.ingest.FileUtil;
7 import org.kuali.ole.license.bo.OleCheckListBo;
8 import org.kuali.ole.license.maintenance.OleCheckListMaintenanceImpl;
9 import org.kuali.rice.core.api.CoreApiServiceLocator;
10 import org.kuali.rice.core.api.config.property.ConfigurationService;
11 import org.kuali.rice.kim.api.identity.Person;
12 import org.kuali.rice.krad.UserSession;
13 import org.kuali.rice.krad.service.BusinessObjectService;
14 import org.kuali.rice.krad.service.KRADServiceLocator;
15 import org.kuali.rice.krad.util.GlobalVariables;
16 import org.kuali.rice.krad.util.KRADConstants;
17 import org.springframework.test.context.ContextConfiguration;
18 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
19 import org.springframework.test.context.transaction.TransactionConfiguration;
20 import org.springframework.transaction.annotation.Transactional;
21 import org.springframework.web.multipart.MultipartFile;
22
23 import java.io.ByteArrayInputStream;
24 import java.io.File;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.net.URL;
28 import java.sql.Timestamp;
29 import java.util.UUID;
30
31 import static junit.framework.Assert.*;
32
33
34
35
36
37
38
39
40 @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
41 @RunWith(value = SpringJUnit4ClassRunner.class)
42 @TransactionConfiguration(defaultRollback = true)
43 public class OleCheckListBo_UT {
44 private String MULTIPART_FILE_NAME = "checkList_template.txt";
45 private String FILE_NAME="checkList_template.txt";
46 private String MULTIPART_CONTENT_TYPE="text/plain";
47 private String fileContent = "";
48 private BusinessObjectService businessObjectService;
49 private File file;
50
51 @Before
52 public void setUp() throws Exception {
53 businessObjectService = KRADServiceLocator.getBusinessObjectService();
54 }
55
56 @Test
57 @Transactional
58 public void testCreateCheckList() throws Exception {
59 URL resource = getClass().getResource(MULTIPART_FILE_NAME);
60 file = new File(resource.toURI());
61 fileContent = new FileUtil().readFile(file);
62 OleCheckListBo checkListBo = new OleCheckListBo();
63 checkListBo.setFileName(FILE_NAME);
64 GlobalVariables.setUserSession(new UserSession("admin"));
65 Person kualiUser = GlobalVariables.getUserSession().getPerson();
66 checkListBo.setDescription("Mock Description");
67 checkListBo.setName("Mock CheckList Name");
68 checkListBo.setLastModified((Timestamp) CoreApiServiceLocator.getDateTimeService().getCurrentTimestamp());
69 checkListBo.setAuthor(kualiUser.getPrincipalId());
70 checkListBo.setMimeType(MULTIPART_CONTENT_TYPE);
71 checkListBo.setRemoteObjectIdentifier(UUID.randomUUID().toString());
72 checkListBo.setActiveIndicator(true);
73 OleCheckListMaintenanceImpl mainImple = new OleCheckListMaintenanceImpl();
74
75 OleCheckListBo savedcheckListBo = businessObjectService.save(checkListBo);
76 assertNotNull(savedcheckListBo);
77 assertNotNull(savedcheckListBo.getOleCheckListId());
78
79
80
81
82 }
83
84 public ConfigurationService getKualiConfigurationService() {
85 return KRADServiceLocator.getKualiConfigurationService();
86 }
87
88
89
90 @Test
91 @Transactional
92 public void testSearchCheckList() throws Exception{
93 URL resource = getClass().getResource(MULTIPART_FILE_NAME);
94 file = new File(resource.toURI());
95 fileContent = new FileUtil().readFile(file);
96 OleCheckListBo checkListBo = new OleCheckListBo();
97 checkListBo.setFileName(FILE_NAME);
98 GlobalVariables.setUserSession(new UserSession("admin"));
99 Person kualiUser = GlobalVariables.getUserSession().getPerson();
100 checkListBo.setDescription("Mock Description");
101 checkListBo.setName("Mock CheckList Name");
102 checkListBo.setRemoteObjectIdentifier(UUID.randomUUID().toString());
103 checkListBo.setLastModified((Timestamp) CoreApiServiceLocator.getDateTimeService().getCurrentTimestamp());
104 checkListBo.setAuthor(kualiUser.getPrincipalId());
105 checkListBo.setMimeType(MULTIPART_CONTENT_TYPE);
106 checkListBo.setActiveIndicator(true);
107 OleCheckListMaintenanceImpl mainImple = new OleCheckListMaintenanceImpl();
108
109 OleCheckListBo savedcheckListBo = businessObjectService.save(checkListBo);
110 assertNotNull(savedcheckListBo);
111 assertNotNull(savedcheckListBo.getOleCheckListId());
112
113
114 OleCheckListBo oleCheckListBo = businessObjectService.findBySinglePrimaryKey(OleCheckListBo.class, savedcheckListBo.getOleCheckListId());
115 assertNotNull(oleCheckListBo);
116
117
118 }
119 }