1 package org.kuali.ole.ingest;
2
3 import org.junit.Test;
4 import org.junit.runner.RunWith;
5 import org.kuali.ole.FileUtilForRawMarc;
6 import org.kuali.ole.OLEConstants;
7 import org.kuali.ole.ingest.pojo.IngestRecord;
8 import org.kuali.ole.pojo.OleOrderRecord;
9 import org.kuali.rice.krms.api.engine.EngineResults;
10 import org.kuali.rice.krms.api.engine.ResultEvent;
11 import org.springframework.test.context.ContextConfiguration;
12 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 import org.springframework.test.context.transaction.TransactionConfiguration;
14 import org.springframework.transaction.annotation.Transactional;
15
16 import java.io.File;
17 import java.net.URL;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Map;
21
22
23
24
25
26
27
28
29 @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
30 @RunWith(value = SpringJUnit4ClassRunner.class)
31 @TransactionConfiguration(defaultRollback = true)
32 public class IngestProcessor_UT {
33
34 @Test
35 @Transactional
36 public void testIngestProcessor() throws Exception {
37 System.setProperty("app.environment", "local");
38 ProfileBuilder profileBuilder = new ProfileBuilder();
39 String agendaName = profileBuilder.persistKRMSProfile("profile.xml");
40 IngestProcessor ingestProcessor = new IngestProcessor();
41
42
43 URL resource = getClass().getResource("1MarcError.xml");
44 File file = new File(resource.toURI());
45 String rawMarcContent = new FileUtil().readFile(file);
46
47
48 URL resource1 = getClass().getResource("1EdiError.xml");
49 File file1 = new File(resource1.toURI());
50 String rawEdiContent = new FileUtil().readFile(file1);
51
52 IngestRecord ingestRecord = new IngestRecord();
53 ingestRecord.setByPassPreProcessing(false);
54 ingestRecord.setMarcFileContent(rawMarcContent);
55 ingestRecord.setEdiFileContent(rawEdiContent);
56 ingestRecord.setAgendaName(agendaName);
57 ingestRecord.setOriginalMarcFileName(file.getName());
58 ingestRecord.setOriginalEdiFileName(file1.getName());
59 ingestProcessor.start(ingestRecord);
60
61 List<EngineResults> engineResults = ingestProcessor.getEngineResults();
62 System.out.println("Num results: " + engineResults.size());
63 for (Iterator<EngineResults> iterator = engineResults.iterator(); iterator.hasNext(); ) {
64 EngineResults results = iterator.next();
65 System.out.println(OLEConstants.EXCEPTION_CREATION_FLAG + " : " + results.getAttribute(OLEConstants.EXCEPTION_CREATION_FLAG));
66 System.out.println(OLEConstants.UPDATE_ITEM_FLAG + " : " + results.getAttribute(OLEConstants.UPDATE_ITEM_FLAG));
67 System.out.println(OLEConstants.BIB_CREATION_FLAG + " : " + results.getAttribute(OLEConstants.BIB_CREATION_FLAG));
68 OleOrderRecord oleOrderRecord = (OleOrderRecord) results.getAttribute(OLEConstants.OLE_ORDER_RECORD);
69 Map<String,Object> messageMap = oleOrderRecord.getMessageMap();
70 List rulesEvaulvated = (List) messageMap.get("rulesEvaluated");
71 for (Iterator iterator1 = rulesEvaulvated.iterator(); iterator1.hasNext(); ) {
72 String ruleEvauated = (String) iterator1.next();
73 System.out.println(ruleEvauated);
74 }
75 }
76 }
77 }