View Javadoc
1   package org.kuali.ole.docstore.model.xmlpojo.work.bib.marc;
2   
3   import org.junit.Test;
4   import org.kuali.ole.docstore.xstream.BaseTestCase;
5   import org.slf4j.Logger;
6   import org.slf4j.LoggerFactory;
7   
8   import java.util.ArrayList;
9   import java.util.Arrays;
10  import java.util.List;
11  
12  import static junit.framework.Assert.assertNotNull;
13  
14  /**
15   * Created with IntelliJ IDEA.
16   * User: ?
17   * Date: 1/21/13
18   * Time: 12:44 AM
19   * To change this template use File | Settings | File Templates.
20   */
21  public class WorkBibMarcRecords_UT extends BaseTestCase {
22      private static final Logger LOG = LoggerFactory.getLogger(WorkBibMarcRecords_UT.class);
23  
24      @Test
25      public void testWorkBibMarcRecords() throws Exception {
26  
27          WorkBibMarcRecords workBibMarcRecords = new WorkBibMarcRecords();
28          List<WorkBibMarcRecord> workBibMarcRecordList = new ArrayList<WorkBibMarcRecord>();
29          List<ControlField> controlFieldList = new ArrayList<ControlField>();
30          List<DataField> dataFieldList = new ArrayList<DataField>();
31          WorkBibMarcRecord workBibMarcRecord = new WorkBibMarcRecord();
32          workBibMarcRecord.setLeader("test");
33          ControlField marcControlField = new ControlField();
34          marcControlField.setTag("001");
35          marcControlField.setValue("1223");
36          ControlField marcControlField1 = new ControlField("ts");
37          marcControlField1.setTag("001");
38          marcControlField1.setValue("1223");
39  
40          if (marcControlField.equals(marcControlField1)) {
41              LOG.info("ControlFields are equal");
42          }
43          DataField marcDataField1 = new DataField("aa");
44          marcDataField1.setTag("500");
45          marcDataField1.setInd1("");
46          marcDataField1.setInd2("");
47          SubField marcSubField1 = new SubField("bb");
48          marcSubField1.setCode("a");
49          marcSubField1.setValue("688");
50          SubField marcSubField2 = new SubField();
51          marcSubField2.setCode("b");
52          marcSubField2.setValue("7225");
53          marcDataField1.addAllSubFields(Arrays.asList(marcSubField1, marcSubField2));
54          marcDataField1.setSubFields(Arrays.asList(marcSubField1, marcSubField2));
55  
56          controlFieldList.add(marcControlField);
57          dataFieldList.add(marcDataField1);
58          workBibMarcRecord.setControlFields(controlFieldList);
59          workBibMarcRecord.setDataFields(dataFieldList);
60          workBibMarcRecordList.add(workBibMarcRecord);
61  
62          workBibMarcRecord = new WorkBibMarcRecord();
63          workBibMarcRecord.setLeader("test");
64          ControlField marcControlField2 = new ControlField();
65          marcControlField2.setTag("005");
66          marcControlField2.setValue("1665");
67          ControlField marcControlField3 = new ControlField("ts");
68          marcControlField3.setTag("007");
69          marcControlField3.setValue("447774");
70          DataField marcDataField2 = new DataField("aa");
71          marcDataField2.setTag("500");
72          marcDataField2.setInd1("");
73          marcDataField2.setInd2("");
74          SubField marcSubField3 = new SubField("bb");
75          marcSubField3.setCode("a");
76          marcSubField3.setValue("688");
77          SubField marcSubField4 = new SubField();
78          marcSubField4.setCode("b");
79          marcSubField4.setValue("7225");
80          workBibMarcRecord.getControlFields().add(marcControlField3);
81          marcDataField2.setSubFields(Arrays.asList(marcSubField3, marcSubField4));
82          workBibMarcRecord.addMarcDataField(marcDataField2);
83          workBibMarcRecord.getDataFields().add(marcDataField2);
84          workBibMarcRecordList.add(workBibMarcRecord);
85          workBibMarcRecords.setRecords(workBibMarcRecordList);
86  
87          if (marcDataField1.equals(marcDataField2)) {
88              LOG.info("equals");
89          }
90          List<WorkBibMarcRecord> workBibMarcRecordResultList = workBibMarcRecords.getRecords();
91          if (workBibMarcRecord.getDataFieldForTag("78231") != null) {
92              LOG.info("Datafield exists");
93          }
94          for (WorkBibMarcRecord workBibMarcRecordResult : workBibMarcRecordResultList) {
95              LOG.info("Leader:" + workBibMarcRecordResult.getLeader());
96              List<ControlField> controlFieldList1 = workBibMarcRecordResult.getControlFields();
97              for (ControlField controlField : controlFieldList1) {
98                  LOG.info("Control Field Tag:" + controlField.getTag());
99                  LOG.info("Control Field Value:" + controlField.getValue());
100             }
101             List<DataField> dataFieldList1 = workBibMarcRecordResult.getDataFields();
102             LOG.info("size:" + dataFieldList1.size());
103             for (DataField dataField : dataFieldList1) {
104                 LOG.info("Data Field Ind1:" + dataField.getInd1());
105                 LOG.info("Data Field Ind2:" + dataField.getInd2());
106                 List<SubField> subFieldList = dataField.getSubFields();
107                 for (SubField subField : subFieldList) {
108                     LOG.info("Sub Field Code:" + subField.getCode());
109                     LOG.info("Sub Field Value:" + subField.getValue());
110                 }
111             }
112 
113         }
114 
115         LOG.info("Data Field for Tag");
116         DataField dataField = workBibMarcRecord.getDataFieldForTag("500");
117         LOG.info("Data Field Ind1:" + dataField.getInd1());
118         LOG.info("Data Field Ind2:" + dataField.getInd2());
119         LOG.info(String.valueOf(marcControlField.hashCode()));
120         LOG.info(String.valueOf(marcDataField1.hashCode()));
121         LOG.info(String.valueOf(marcSubField1.hashCode()));
122         workBibMarcRecord.setControlFields(null);
123         workBibMarcRecord.setDataFields(null);
124         assertNotNull(workBibMarcRecord.getControlFields());
125         assertNotNull(workBibMarcRecord.getDataFields());
126 
127     }
128 
129 }