1 package org.kuali.ole.ingest;
2
3 import org.junit.Test;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.OleSpringBaseTestCase;
6 import org.kuali.ole.ingest.krms.builder.OleKrmsBuilder;
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.springframework.transaction.annotation.Transactional;
11
12 import java.io.File;
13 import java.net.URL;
14 import java.util.Iterator;
15 import java.util.List;
16 import java.util.Map;
17
18
19
20
21
22
23
24
25
26 public class IngestProcessor_UT extends OleSpringBaseTestCase {
27
28 @Test
29 @Transactional
30 public void testIngestProcessor() throws Exception {
31 System.setProperty("app.environment", "local");
32 OleKrmsBuilder profileBuilder = new OleKrmsBuilder();
33 URL resource2 = getClass().getResource("profile_new.xml");
34 File file2 = new File(resource2.toURI());
35 String krmsXML = new FileUtil().readFile(file2);
36 List<String> agendas = profileBuilder.persistKrmsFromFileContent(krmsXML);
37 MockIngestProcessor ingestProcessor = new MockIngestProcessor();
38
39
40 URL resource = getClass().getResource("1MarcError.xml");
41 File file = new File(resource.toURI());
42 String rawMarcContent = new FileUtil().readFile(file);
43
44
45 URL resource1 = getClass().getResource("1EdiError.xml");
46 File file1 = new File(resource1.toURI());
47 String rawEdiContent = new FileUtil().readFile(file1);
48
49 IngestRecord ingestRecord = new IngestRecord();
50 ingestRecord.setByPassPreProcessing(false);
51 ingestRecord.setMarcFileContent(rawMarcContent);
52 ingestRecord.setEdiFileContent(rawEdiContent);
53 ingestRecord.setAgendaName(agendas.get(0));
54 ingestRecord.setOriginalMarcFileName(file.getName());
55 ingestRecord.setOriginalEdiFileName(file1.getName());
56 ingestProcessor.start(ingestRecord);
57
58 List<EngineResults> engineResults = ingestProcessor.getEngineResults();
59 System.out.println("Num results: " + engineResults.size());
60 for (Iterator<EngineResults> iterator = engineResults.iterator(); iterator.hasNext(); ) {
61 EngineResults results = iterator.next();
62 System.out.println(OLEConstants.EXCEPTION_CREATION_FLAG + " : " + results.getAttribute(OLEConstants.EXCEPTION_CREATION_FLAG));
63 System.out.println(OLEConstants.UPDATE_ITEM_FLAG + " : " + results.getAttribute(OLEConstants.UPDATE_ITEM_FLAG));
64 System.out.println(OLEConstants.BIB_CREATION_FLAG + " : " + results.getAttribute(OLEConstants.BIB_CREATION_FLAG));
65 OleOrderRecord oleOrderRecord = (OleOrderRecord) results.getAttribute(OLEConstants.OLE_ORDER_RECORD);
66 Map<String,Object> messageMap = oleOrderRecord.getMessageMap();
67 List rulesEvaulvated = (List) messageMap.get("rulesEvaluated");
68 for (Iterator iterator1 = rulesEvaulvated.iterator(); iterator1.hasNext(); ) {
69 String ruleEvauated = (String) iterator1.next();
70 System.out.println(ruleEvauated);
71 }
72 }
73 }
74 }