View Javadoc
1   package org.kuali.ole.docstore.xstream.work.instance.oleml;
2   
3   import junit.framework.Assert;
4   import org.junit.Before;
5   import org.junit.Test;
6   import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
7   import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.*;
8   import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkInstanceOlemlRecordProcessor;
9   import org.kuali.ole.docstore.xstream.BaseTestCase;
10  import org.slf4j.Logger;
11  import org.slf4j.LoggerFactory;
12  
13  import java.io.BufferedReader;
14  import java.io.File;
15  import java.io.FileReader;
16  import java.io.IOException;
17  import java.net.URL;
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import static junit.framework.Assert.fail;
22  import static org.junit.Assert.assertNotNull;
23  
24  /**
25   * User: tirumalesh.b
26   * Date: 10/2/12 Time: 6:48 PM
27   */
28  public class WorkInstanceOlemlRecordProcessor_UT extends BaseTestCase {
29      private static final Logger LOG = LoggerFactory.getLogger(WorkInstanceOlemlRecordProcessor_UT.class);
30      InstanceCollection instanceCollection = null;
31      private Instance instance = null;
32      private Item item = null;
33      private OleHoldings holdings = null;
34      private SourceHoldings sourceHoldings = null;
35      String sampleXmlFilePath = "/org/kuali/ole/instance9.1.1.xml";
36  
37      @Before
38      public void setUp() {
39  
40          ObjectFactory objectFactory = new ObjectFactory();
41          instanceCollection = objectFactory.createInstanceCollection();
42          List<FormerIdentifier> formerResourceIdentifier = null;
43          List<Instance> oleInstanceList = new ArrayList<Instance>();
44          ExtentOfOwnership extentOfOwnership = objectFactory.createExtentOfOwnership();
45          instance = objectFactory.createInstance();
46          instance.setInstanceIdentifier("mockInstacneIdentifier");
47          List<String> resourceIdentifiers = instance.getResourceIdentifier();
48          if (resourceIdentifiers.isEmpty()) {
49              LOG.info("empty values");
50              resourceIdentifiers.add("a1000003");
51          }
52          instance.setResourceIdentifier(resourceIdentifiers);
53  
54          List<FormerIdentifier> formerIdentifierList = instance.getFormerResourceIdentifier();
55  
56          if (formerIdentifierList.isEmpty()) {
57              FormerIdentifier formerIdentifier = objectFactory.createFormerIdentifier();
58              Identifier identifier = objectFactory.createIdentifier();
59              identifier.setIdentifierValue("1000003-2");
60              identifier.setSource("IUHoldings");
61              LOG.info("Identifier Val:" + identifier.getIdentifierValue());
62              LOG.info("Source:" + identifier.getSource());
63  
64              formerIdentifier.setIdentifier(identifier);
65              formerIdentifier.setIdentifierType("Ty 001");
66              formerIdentifierList.add(formerIdentifier);
67              LOG.info("Indentifier Source:" + formerIdentifier.getIdentifier().getSource());
68              LOG.info("Indentifier Type:" + formerIdentifier.getIdentifierType());
69          }
70  
71          instance.setFormerResourceIdentifier(formerIdentifierList);
72  
73          sourceHoldings = objectFactory.createSourceHoldings();
74          sourceHoldings.setHoldingsIdentifier("1000003-2-1");
75  
76  
77          Extension extension = objectFactory.createExtension();
78          if (instance.getExtension() == null) {
79              extension.setDisplayLabel("Extension");
80              sourceHoldings.setHoldings(extension);
81              sourceHoldings.setExtension(extension);
82              sourceHoldings.setName("Holdings");
83              sourceHoldings.setPrimary("primary");
84          }
85  
86          LOG.info("Name:" + sourceHoldings.getName());
87          LOG.info("Display Label:" + sourceHoldings.getExtension().getDisplayLabel());
88          LOG.info("Display Label:" + sourceHoldings.getHoldings().getDisplayLabel());
89          LOG.info("Display Label:" + sourceHoldings.getPrimary());
90          LOG.info("Holdings Identifier:" + sourceHoldings.getHoldingsIdentifier());
91          instance.setSourceHoldings(sourceHoldings);
92  
93          Items items = objectFactory.createItems();
94          item = objectFactory.createItem();
95          List<Item> itemList = new ArrayList<Item>();
96          item.setItemIdentifier("200003-2");
97  
98          ItemType itemType = objectFactory.createItemType();
99          itemType.setCodeValue("IT001");
100         itemType.setFullValue("Item 01");
101         TypeOrSource typeOrSource = objectFactory.createTypeOrSource();
102         typeOrSource.setText("Type");
103         typeOrSource.setPointer("P");
104         itemType.setTypeOrSource(typeOrSource);
105         LOG.info("Text:" + itemType.getTypeOrSource().getText());
106         LOG.info("Pointer:" + itemType.getTypeOrSource().getPointer());
107 
108         item.setItemType(itemType);
109         item.setVendorLineItemIdentifier("V001");
110         AccessInformation accessInformation = objectFactory.createAccessInformation();
111         accessInformation.setBarcode("100001");
112         Uri accessUri = objectFactory.createUri();
113         accessUri.setResolvable("true");
114         accessInformation.setUri(accessUri);
115         Assert.assertNotNull(accessInformation.getUri());
116         item.setExtension(extension);
117         assertNotNull(item.getExtension());
118         item.setBarcodeARSL("ARSL");
119         formerIdentifierList = instance.getFormerResourceIdentifier();
120 
121         if (formerIdentifierList.isEmpty()) {
122             FormerIdentifier formerIdentifier = objectFactory.createFormerIdentifier();
123             Identifier identifier = objectFactory.createIdentifier();
124             identifier.setIdentifierValue("1000003-2");
125             identifier.setSource("IUHoldings");
126             LOG.info("Identifier Val:" + identifier.getIdentifierValue());
127             LOG.info("Source:" + identifier.getSource());
128 
129             formerIdentifier.setIdentifier(identifier);
130             formerIdentifier.setIdentifierType("Ty 001");
131             formerIdentifierList.add(formerIdentifier);
132             LOG.info("Indentifier Source:" + formerIdentifier.getIdentifier().getSource());
133             LOG.info("Indentifier Type:" + formerIdentifier.getIdentifierType());
134         }
135 
136         item.setFormerIdentifier(formerIdentifierList);
137         assertNotNull(item.getFormerIdentifier());
138         List<StatisticalSearchingCode> statisticalSearchingCodeList = new ArrayList<StatisticalSearchingCode>();
139         StatisticalSearchingCode statisticalSearchingCode = objectFactory.createStatisticalSearchingCode();
140         statisticalSearchingCode.setCodeValue("SC001");
141         statisticalSearchingCode.setFullValue("SC001");
142         typeOrSource = new TypeOrSource();
143         typeOrSource.setPointer("P");
144         typeOrSource.setText("T");
145         statisticalSearchingCode.setTypeOrSource(typeOrSource);
146         statisticalSearchingCodeList.add(statisticalSearchingCode);
147         item.setStatisticalSearchingCode(statisticalSearchingCodeList);
148         assertNotNull(item.getStatisticalSearchingCode());
149         item.setCopyNumber("C001");
150         item.setVolumeNumber("V001");
151         /*item.setDonorNote("donorNote");
152         assertNotNull(item.getDonorNote());*/
153         item.setVolumeNumberLabel("V001");
154         Note note = objectFactory.createNote();
155         note.setType("NT");
156         note.setValue("NT");
157         item.getNote().add(note);
158         item.setEnumeration("E");
159         item.setChronology("Chronology-1");
160         accessInformation = new AccessInformation();
161         accessInformation.setBarcode("A-001");
162         item.setAccessInformation(accessInformation);
163         item.setFund("1000");
164         ItemStatus itemStatus = new ItemStatus();
165         itemStatus.setCodeValue("In Process");
166         itemStatus.setFullValue("In Process");
167         item.setItemStatus(itemStatus);
168         HighDensityStorage highDensityStorage = objectFactory.createHighDensityStorage();
169         highDensityStorage.setModule("M001");
170         highDensityStorage.setRow("1");
171         highDensityStorage.setShelf("sh");
172         highDensityStorage.setTray("tr");
173         item.setHighDensityStorage(highDensityStorage);
174         itemType = new ItemType();
175         itemType.setCodeValue("IT001");
176         itemType.setFullValue("IT001");
177         item.setTemporaryItemType(itemType);
178         Location location = objectFactory.createLocation();
179         location.setStatus("ACR");
180         location.setPrimary("true");
181         LocationLevel locationLevel = objectFactory.createLocationLevel();
182         locationLevel.setName("Level1");
183         locationLevel.setLevel("1");
184         location.setLocationLevel(locationLevel);
185         locationLevel.setLocationLevel(locationLevel);
186         assertNotNull(locationLevel.getLocationLevel());
187         item.setLocation(location);
188         //item.setDonorPublicDisplay("Donor");
189         item.setPrice("1000");
190         item.setNumberOfPieces("12");
191         item.setItemStatusEffectiveDate("12/12/12");
192         item.setCheckinNote("Pending");
193         item.setStaffOnlyFlag(true);
194         item.setFastAddFlag(true);
195         item.setAnalytic("yes");
196         item.setResourceIdentifier("IT003");
197         itemList.add(item);
198         items.setItem(itemList);
199         instance.setItems(items);
200 
201         items = instance.getItems();
202         itemList = items.getItem();
203 
204         for (Item item1 : itemList) {
205             LOG.info("Item Identifier:" + item1.getItemIdentifier());
206             LOG.info("Purchase Order Line Item Identifier:" + item1.getPurchaseOrderLineItemIdentifier());
207             LOG.info("Vendor Line Item Identifier:" + item1.getVendorLineItemIdentifier());
208             LOG.info("Barcode:" + item1.getAccessInformation().getBarcode());
209             LOG.info("Barcode ARSL:" + item1.getBarcodeARSL());
210             LOG.info("Identifier:" + item1.getFormerIdentifier().get(0).getIdentifier());
211             LOG.info("Code Val:" + item1.getStatisticalSearchingCode().get(0).getCodeValue());
212             LOG.info("Full Val:" + item1.getStatisticalSearchingCode().get(0).getFullValue());
213             LOG.info("Pointer:" + item1.getStatisticalSearchingCode().get(0).getTypeOrSource().getPointer());
214             LOG.info("Text:" + item1.getStatisticalSearchingCode().get(0).getTypeOrSource().getText());
215             LOG.info("Copy Label:" + item1.getCopyNumberLabel());
216             LOG.info("Volume Number:" + item1.getVolumeNumber());
217             //LOG.info("Donor Public Display:" + item1.getDonorPublicDisplay());
218             LOG.info("Copy Number:" + item1.getCopyNumber());
219             LOG.info("Volume Number Label:" + item1.getVolumeNumberLabel());
220             LOG.info("Note Type:" + item1.getNote());
221             LOG.info("Note Value:" + item1.getNote());
222             LOG.info("Enumeration:" + item1.getEnumeration());
223             LOG.info("Chronology:" + item1.getChronology());
224             LOG.info("Module:" + item1.getHighDensityStorage().getModule());
225             LOG.info("Row:" + item1.getHighDensityStorage().getRow());
226             LOG.info("Shelf:" + item1.getHighDensityStorage().getShelf());
227             LOG.info("Tray:" + item1.getHighDensityStorage().getTray());
228             LOG.info("Code Value:" + item1.getItemType().getCodeValue());
229             LOG.info("Full Value:" + item1.getItemType().getFullValue());
230             LOG.info("Code Value:" + item1.getTemporaryItemType().getCodeValue());
231             LOG.info("Fund:" + item1.getFund());
232             LOG.info("Price:" + item1.getPrice());
233             LOG.info("Number of Pieces:" + item1.getNumberOfPieces());
234             LOG.info("Item Status:" + item1.getItemStatus());
235             LOG.info("Item Status Effective Date:" + item1.getItemStatusEffectiveDate());
236             LOG.info("Check In Note:" + item1.getCheckinNote());
237             LOG.info("Is StaffOnlyFlag:" + item1.isStaffOnlyFlag());
238             LOG.info("Is FastAddFlag:" + item1.isFastAddFlag());
239             LOG.info("Status:" + item1.getLocation().getStatus());
240             LOG.info("Primary:" + item1.getLocation().getPrimary());
241             LOG.info("Level:" + item1.getLocation().getLocationLevel().getLevel());
242             LOG.info("Name:" + item1.getLocation().getLocationLevel().getName());
243 //            LOG.info("Display Label:" + item1.getExtension().getDisplayLabel());
244         }
245 
246         holdings = objectFactory.createOleHoldings();
247         holdings.setHoldingsIdentifier("30004-1");
248         note = new Note();
249         note.setValue("Completed");
250         extentOfOwnership.setTextualHoldings("textualHoldings1");
251         extentOfOwnership.setType("typeOfOwnership1");
252         extentOfOwnership.getNote().add(note);
253         List<ExtentOfOwnership> extentOfOwnershipList = new ArrayList<ExtentOfOwnership>();
254         extentOfOwnershipList.add(extentOfOwnership);
255         extentOfOwnership = new ExtentOfOwnership();
256         extentOfOwnership.setTextualHoldings("textualHoldings2");
257         extentOfOwnershipList.add(extentOfOwnership);
258         holdings.setExtentOfOwnership(extentOfOwnershipList);
259         note = new Note();
260         note.setType("AST");
261         note.setType("AST");
262         holdings.getNote().add(note);
263         holdings.setLocation(location);
264         holdings.setReceiptStatus("Completed");
265         CallNumber callNumber = objectFactory.createCallNumber();
266         callNumber.setItemPart("IT001");
267         callNumber.setNumber("8008");
268         callNumber.setPrefix("IT");
269         callNumber.setType("Valid");
270         item.setCallNumber(callNumber);
271         assertNotNull(item.getCallNumber());
272         holdings.setCallNumber(callNumber);
273         holdings.setPrimary("true");
274 
275         Item item2 = new Item();
276         item2.setStatisticalSearchingCode(null);
277         assertNotNull(item2.getStatisticalSearchingCode());
278         item2.setFormerIdentifier(null);
279         assertNotNull(item2.getFormerIdentifier());
280         ShelvingScheme shelvingScheme = objectFactory.createShelvingScheme();
281         shelvingScheme.setCodeValue("SC001");
282         shelvingScheme.setFullValue("SC001");
283         shelvingScheme.setTypeOrSource(typeOrSource);
284         assertNotNull(shelvingScheme.getCodeValue());
285         assertNotNull(shelvingScheme.getFullValue());
286         assertNotNull(shelvingScheme.getTypeOrSource());
287 
288 
289         ShelvingOrder shelvingOrder = objectFactory.createShelvingOrder();
290         shelvingOrder.setCodeValue("SC002");
291         shelvingOrder.setFullValue("SC002");
292         shelvingOrder.setTypeOrSource(typeOrSource);
293         assertNotNull(shelvingOrder.getTypeOrSource());
294         assertNotNull(shelvingOrder.getFullValue());
295         assertNotNull(shelvingOrder.getCodeValue());
296 
297 
298         callNumber.setClassificationPart("classificationPart");
299         callNumber.setShelvingScheme(shelvingScheme);
300         callNumber.setShelvingOrder(shelvingOrder);
301         assertNotNull(callNumber.getClassificationPart());
302         assertNotNull(callNumber.getShelvingOrder());
303         assertNotNull(callNumber.getShelvingScheme());
304 
305         extentOfOwnershipList = holdings.getExtentOfOwnership();
306         for (ExtentOfOwnership extentOfOwnership1 : extentOfOwnershipList) {
307             LOG.info("Textual Holdings:" + extentOfOwnership1.getTextualHoldings());
308             LOG.info("Type:" + extentOfOwnership1.getType());
309         }
310         LOG.info("Holdings Identifier:" + holdings.getHoldingsIdentifier());
311         LOG.info("Receipt Status:" + holdings.getReceiptStatus());
312         LOG.info("Location Status:" + holdings.getLocation().getStatus());
313         LOG.info("Item Part:" + holdings.getCallNumber().getItemPart());
314         LOG.info("Number:" + holdings.getCallNumber().getNumber());
315         LOG.info("Prefix:" + holdings.getCallNumber().getPrefix());
316         LOG.info("Type:" + holdings.getCallNumber().getType());
317         LOG.info("Primary:" + holdings.getPrimary());
318         LOG.info("Value:" + holdings.getExtentOfOwnership().get(0).getNote().get(0).getValue());
319         LOG.info("Value:" + holdings.getExtentOfOwnership().get(0).getNote().get(0).getValue());
320 
321         instance.setOleHoldings(holdings);
322         instance = objectFactory.createInstance();
323         instance.setItems(items);
324         instance.setResourceIdentifier(resourceIdentifiers);
325         instance.setSourceHoldings(sourceHoldings);
326         oleInstanceList.add(instance);
327         instanceCollection.setInstance(oleInstanceList);
328         Assert.assertNotNull(objectFactory.createInstanceCollection(instanceCollection));
329     }
330 
331 
332     /*   @Before
333    public void setUp() {
334          super.setUp();
335        } catch (Exception e) {
336        }
337       LOG.info("Running Setup()");
338        instanceCollection = new InstanceCollection();
339        List<Instance> oleInstanceList = new ArrayList<Instance>();
340        instance = new Instance();
341        instance.setInstanceIdentifier("mockInstacneIdentifier");
342 
343        List<ResourceIdentifier> resourceIdentifiers = new ArrayList<ResourceIdentifier>();
344        ResourceIdentifier resourceIdentifier = new ResourceIdentifier();
345        resourceIdentifier.setSource("Resource Soruce 1");
346        resourceIdentifier.setValue("Resource Value 1");
347        resourceIdentifiers.add(resourceIdentifier);
348        instance.setResourceIdentifier(resourceIdentifiers);
349 
350        List<FormerResourceIdentifiers> formerRIs = new ArrayList<FormerResourceIdentifiers>();
351        FormerResourceIdentifiers fri = new FormerResourceIdentifiers();
352        fri.setSource("Former Source 1");
353        fri.setValue("Former Resource Value 1");
354        formerRIs.add(fri);
355        instance.setFormerResourceIdentifiers(formerRIs);
356 
357        Extension extension = new Extension();
358        extension.setDisplayLabel("Extension Display Label 1");
359        AdditionalAttributes additionalAttributes = new AdditionalAttributes();
360        additionalAttributes.setDateEntered("2012-02-29");
361        additionalAttributes.setLastUpdated("2012-03-01");
362        additionalAttributes.setFastAddFlag("true");
363        additionalAttributes.setSupressFromPublic("false");
364        additionalAttributes.setHarvestable("true");
365        additionalAttributes.setStatus("n"); // new Record
366        List<Object> extensionContents = new ArrayList<Object>();
367        extensionContents.add(additionalAttributes);
368        extension.setContent(extensionContents);
369        List<Extension> extensions = new ArrayList<Extension>();
370        extensions.add(extension);
371        instance.setExtension(extensions);
372 
373        // HOLDINGS : CREATION :START
374        holdings = new OleHoldings();
375        holdings.setHoldingsIdentifier("holdingsIdentifier");
376 
377        FormerIdentifiers formerIdentifiers1 = new FormerIdentifiers();
378        formerIdentifiers1.setIdentifier("identifier1");
379        formerIdentifiers1.setIdentifierType("identifierType1");
380        FormerIdentifiers formerIdentifiers2 = new FormerIdentifiers();
381        formerIdentifiers2.setIdentifier("identifier2");
382        formerIdentifiers2.setIdentifierType("identifierType2");
383 
384        holdings.getFormerIdentifiers().add(formerIdentifiers1);
385        holdings.getFormerIdentifiers().add(formerIdentifiers2);
386        holdings.setRecordType("recordType");
387        holdings.setEncodingLevel("encodingLevel");
388        holdings.setReceiptStatus("receiptStatus");
389        holdings.setAcquisitionMethod("AquisitionMethod 1");
390        holdings.setExpectedAcquisitionEndDate("expectedAcquisitionEndDate");
391        holdings.setGeneralRetentionPolicy("generalRetentionPolicy");
392 
393        SpecificRetentionPolicy specificRetentionPolicy = new SpecificRetentionPolicy();
394        specificRetentionPolicy.setNumberOfUnits("numberOfUnits");
395        specificRetentionPolicy.setPolicyType("policyType");
396        specificRetentionPolicy.setUnitType("unitType");
397        holdings.setSpecificRetentionPolicy(specificRetentionPolicy);
398 
399        holdings.setCompleteness("completeness");
400        holdings.setCopiesReported("copiesReported");
401        holdings.setLendingPolicy("lendingPolicy");
402        holdings.setReproductionPolicy("reproductionPolicy");
403        holdings.setSeparateOrCompositeReport("separateOrCompositeReport");
404 
405        ActionNote actionNote = new ActionNote();
406        actionNote.setAction("action 1");
407        actionNote.setPrivacy("privacy 1");
408        ArrayList<String> actionIdentifications = new ArrayList<String>();
409        actionIdentifications.add("action Indentification 1");
410        actionIdentifications.add("action Indentification 2");
411        actionNote.setActionIdentification(actionIdentifications);
412 
413   actionNote.getTimeDateOfAction().add("timeDateOfAction1");
414   actionNote.getTimeDateOfAction().add("timeDateOfAction2");
415 
416   actionNote.getActionInterval().add("actionInterval1");
417   actionNote.getActionInterval().add("actionInterval2");
418 
419   actionNote.getContingencyForAction().add("contingencyForAction1");
420   actionNote.getContingencyForAction().add("contingencyForAction2");
421 
422   actionNote.getAuthorization().add("authorization1");
423   actionNote.getAuthorization().add("authorization2");
424 
425   actionNote.getJurisdiction().add("jurisdiction1");
426   actionNote.getJurisdiction().add("jurisdiction2");
427 
428   actionNote.getMethodOfAction().add("methodOfAction1");
429   actionNote.getMethodOfAction().add("methodOfAction2");
430 
431   actionNote.getSiteOfAction().add("siteOfAction1");
432   actionNote.getSiteOfAction().add("siteOfAction2");
433 
434   actionNote.getActionAgent().add("actionAgent1");
435   actionNote.getActionAgent().add("actionAgent2");
436 
437   actionNote.getActionStatus().add("actionStatus1");
438   actionNote.getActionStatus().add("actionStatus2");
439 
440   actionNote.getActionExtent().add("actionExtent1");
441   actionNote.getActionExtent().add("actionExtent2");
442 
443   actionNote.getUnitType().add("unitType1");
444   actionNote.getUnitType().add("unitType2");
445 
446   actionNote.getNonPublicNote().add("nonPublicNote1");
447   actionNote.getNonPublicNote().add("nonPublicNote2");
448 
449   actionNote.getPublicNote().add("publicNote1");
450   actionNote.getPublicNote().add("publicNote2");
451 
452   ArrayList<String> sourceOfTerm = new ArrayList<String>();
453   sourceOfTerm.add("sourceOfTerm1");
454   sourceOfTerm.add("sourceOfTerm2");
455   actionNote.setSourceOfTerm(sourceOfTerm);
456 
457   actionNote.getActionURI().add("actionURI1");
458   actionNote.getActionURI().add("actionURI2");
459 
460   actionNote.setMaterialsSpecified("materialsSpecified1");
461 
462   InstitutionToWhichFieldApplies institution = new InstitutionToWhichFieldApplies();
463   institution.setValue("value20");
464   TypeOrSource typeOrSource3 = new TypeOrSource();
465   typeOrSource3.setPointer("Action pointer1");
466   typeOrSource3.setText("Action text1");
467   institution.setTypeOrSource(typeOrSource3);
468   actionNote.setInstitutionToWhichFieldApplies(institution);
469 
470   holdings.getActionNote().add(actionNote);
471 
472   ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
473   extentOfOwnership.setTypeOfOwnership("typeOfOwnership1");
474   extentOfOwnership.setTextualHoldings("textualHoldings1");
475   extentOfOwnership.setFieldEncodingLevel("fieldEncodingLevel1");
476   extentOfOwnership.setTypeOfNotation("typeOfNotation1");
477 
478   extentOfOwnership.getNonPublicNote().add("nonPublicNote1");
479   extentOfOwnership.getNonPublicNote().add("nonPublicNote2");
480 
481   extentOfOwnership.getPublicNote().add("publicNote1");
482   extentOfOwnership.getPublicNote().add("publicNote2");
483 
484   extentOfOwnership.setExtentSourceOfNotation("extentSourceOfNotation1");
485   holdings.getExtentOfOwnership().add(extentOfOwnership);
486   extentOfOwnership = new ExtentOfOwnership();
487   extentOfOwnership.setTypeOfOwnership("typeOfOwnership2");
488   extentOfOwnership.setTextualHoldings("textualHoldings2");
489   extentOfOwnership.setFieldEncodingLevel("fieldEncodingLevel2");
490   extentOfOwnership.setTypeOfNotation("typeOfNotation2");
491 
492   extentOfOwnership.getNonPublicNote().add("nonPublicNote3");
493   extentOfOwnership.getNonPublicNote().add("nonPublicNote4");
494 
495   extentOfOwnership.getPublicNote().add("publicNote3");
496   extentOfOwnership.getPublicNote().add("publicNote4");
497 
498   extentOfOwnership.setExtentSourceOfNotation("extentSourceOfNotation2");
499   holdings.getExtentOfOwnership().add(extentOfOwnership);
500 
501   AlternateGraphicRepresentation alternateGraph = new AlternateGraphicRepresentation();
502   alternateGraph.getFieldName().add("fieldName1");
503   alternateGraph.getFieldName().add("fieldName2");
504 
505   alternateGraph.getFieldValue().add("fieldValue1");
506   alternateGraph.getFieldValue().add("fieldValue2");
507   holdings.getAlternateGraphicRepresentation().add(alternateGraph);
508 
509   alternateGraph = new AlternateGraphicRepresentation();
510   alternateGraph.getFieldName().add("fieldName3");
511   alternateGraph.getFieldName().add("fieldName4");
512 
513   alternateGraph.getFieldValue().add("fieldValue3");
514   alternateGraph.getFieldValue().add("fieldValue4");
515   holdings.getAlternateGraphicRepresentation().add(alternateGraph);
516 
517   Extension ext1 = new Extension();
518   ext1.setDisplayLabel("Holding Extension1");
519   AdditionalAttributes aa1 = new AdditionalAttributes();
520   aa1.setDateEntered("2012-04-11");
521   aa1.setLastUpdated("2012-04-02");
522   aa1.setSupressFromPublic("false");
523   aa1.setFastAddFlag("false");
524   aa1.setHarvestable("true");
525   aa1.setStatus("n"); // new Record
526   ext1.getContent().add(aa1);
527 
528   holdings.getExtension().add(ext1);
529 
530 
531   instance.setHoldings(holdings);
532   // HOLDINGS : CREATION :END
533 
534   // ITEM : CREATION :START
535   item = new OleItem();
536 
537   item.setItemIdentifier("100001022036542365856232");
538 
539   item.getPurchaseOrderLineItemIdentifier().add("12678953456465456678946");
540   item.getPurchaseOrderLineItemIdentifier().add("254544565654654534343213");
541   item.getPurchaseOrderLineItemIdentifier().add("125545632222215465456456");
542 
543   item.getVendorLineItemIdentifier().add("vendorLineItemIdentifier1");
544   item.getVendorLineItemIdentifier().add("vendorLineItemIdentifier2");
545 
546   // Access Information
547   AccessInformationType accesInfo = new AccessInformationType();
548   accesInfo.setBarcode("1466546456345");
549   Uri accessURI = new Uri();
550   accessURI.setResolvable(true);
551   accesInfo.setUri(accessURI);
552   item.setAccessInformation(accesInfo);
553 
554   //ElectronicLocationAndAccess
555   ElectronicLocationAndAccess electronicLoc = new ElectronicLocationAndAccess();
556   electronicLoc.setAccessMethod("accessMethod");
557   electronicLoc.setRelationship("relationship");
558 
559   electronicLoc.getHostName().add("hostName1");
560   electronicLoc.getHostName().add("hostName2");
561 
562   electronicLoc.getAccessNumber().add("accessNumber1");
563   electronicLoc.getAccessNumber().add("accessNumber2");
564 
565   electronicLoc.getCompressionInformation().add("compressionInformation1");
566   electronicLoc.getCompressionInformation().add("compressionInformation2");
567 
568   electronicLoc.getPath().add("path1");
569   electronicLoc.getPath().add("path2");
570 
571   electronicLoc.getElectronicName().add("electronicName1");
572   electronicLoc.getElectronicName().add("electronicName2");
573 
574   electronicLoc.getRequestProcessor().add("requestProcessor1");
575   electronicLoc.getRequestProcessor().add("requestProcessor2");
576 
577   electronicLoc.getInstruction().add("instruction1");
578   electronicLoc.getInstruction().add("instruction2");
579 
580   electronicLoc.setBitsPerSecond("bitsPerSecond");
581   electronicLoc.setPassword("password");
582   electronicLoc.setLogon("logon");
583 
584   electronicLoc.getAccessAssistanceContact().add("accessAssistanceContact1");
585   electronicLoc.getAccessAssistanceContact().add("accessAssistanceContact2");
586 
587   electronicLoc.setLocationHostName("locationHostName");
588   electronicLoc.setOperatingSystem("operatingSystem");
589   electronicLoc.setPort("port");
590   electronicLoc.setElectronicFormatType("electronicFormatType");
591   electronicLoc.setSettings("setting");
592 
593   electronicLoc.getFileSize().add("fileSize1");
594   electronicLoc.getFileSize().add("fileSize2");
595 
596   electronicLoc.getTerminalEmulation().add("terminalEmulation1");
597   electronicLoc.getTerminalEmulation().add("terminalEmulation2");
598 
599   electronicLoc.getHoursAccessMethodAvailable().add("hoursAccessMethodAvailable1");
600   electronicLoc.getHoursAccessMethodAvailable().add("hoursAccessMethodAvailable2");
601 
602   electronicLoc.getRecordControlNumber().add("recordControlNumber1");
603   electronicLoc.getRecordControlNumber().add("recordControlNumber2");
604 
605   electronicLoc.getNonPublicNote().add("nonPublicNote1");
606   electronicLoc.getNonPublicNote().add("nonPublicNote2");
607 
608   electronicLoc.getLinkText().add("linkText1");
609   electronicLoc.getLinkText().add("linkText2");
610 
611   electronicLoc.getPublicNote().add("publicNote1");
612   electronicLoc.getPublicNote().add("publicNote2");
613 
614   CodeOrIdentifier codeOrIdentifier = new CodeOrIdentifier();
615   codeOrIdentifier.setValue("codeOrIdentifier value");
616 
617   TypeOrSource typeOrSource = new TypeOrSource();
618   typeOrSource.setPointer("pointer");
619   typeOrSource.setText("text");
620 
621   codeOrIdentifier.setTypeOrSource(typeOrSource);
622 
623   electronicLoc.setAdditionalAccessMethodInformation(codeOrIdentifier);
624 
625   electronicLoc.setMaterialsSpecified("materialsSpecified");
626 
627   item.setElectronicLocationAndAccess(electronicLoc);
628   //End For ElectronicLocationAndAccess
629 
630   item.setBarcodeARSL("barcodeARSL");
631 
632   FormerIdentifiers formerIdentifiers3 = new FormerIdentifiers();
633   formerIdentifiers3.setIdentifier("identifier3");
634   formerIdentifiers3.setIdentifierType("identifierType3");
635   item.getFormerIdentifiers().add(formerIdentifiers3);
636 
637   FormerIdentifiers formerIdentifiers4 = new FormerIdentifiers();
638   formerIdentifiers4.setIdentifier("identifier4");
639   formerIdentifiers4.setIdentifierType("identifierType4");
640   item.getFormerIdentifiers().add(formerIdentifiers4);
641 
642 
643   item.getStatisticalSearchingCodes().add("1365466576654167");
644   item.getStatisticalSearchingCodes().add("1365466576654168");
645 
646   item.setItemType("Book");
647 
648   item.setCopyNumber("1");
649   item.setCopyNumberLabel("c");
650   item.setVolumeNumber("volumeNumber");
651   item.setVolumeNumberLabel("volumeNumberLabel");
652   item.setPublicNote("PublicNote");
653   item.setNonPublicNote("nonPublicNote");
654   item.setEnumeration("enumeration");
655   item.setChronology("chronology");
656 
657 
658   // Location
659   PhysicalLocation location = new PhysicalLocation();
660   location.getLocationStatus().add("LR");
661   location.getLocationStatus().add("LR-1");
662   LocationLevel locationLevel = new LocationLevel();
663   CodeOrIdentifier levelName = new CodeOrIdentifier();
664   levelName.setValue("Level Name 1");
665   TypeOrSource typeOrSource1 = new TypeOrSource();
666   typeOrSource1.setPointer("Pointer 1");
667   typeOrSource1.setText("Text for Level Name 1");
668   levelName.setTypeOrSource(typeOrSource1);
669   locationLevel.setLevelName(levelName);
670   CodeOrIdentifier locationName = new CodeOrIdentifier();
671   locationName.setValue("Location Name 1");
672   TypeOrSource typeOrSource2 = new TypeOrSource();
673   typeOrSource2.setPointer("Location Pointer 1");
674   typeOrSource2.setText("Text for Location Name 1");
675   locationName.setTypeOrSource(typeOrSource2);
676   locationLevel.setLocationName(locationName);
677   location.getLocationLevel().add(locationLevel);
678 
679   Classification classification1= new Classification();
680   classification1.setShelvingScheme("shelvingScheme1");
681   classification1.setShelvingOrder("shelvingOrder1");
682   classification1.getCallNumberPrefix().add("Call Number Prefix-1");
683   classification1.getCallNumberPrefix().add("Call Number Prefix-2");
684   classification1.getCallNumberSuffix().add("Call Number Suffix-1");
685   classification1.getCallNumberSuffix().add("Call Number Suffix-2");
686   classification1.setClassificationPart("classificationPart1");
687   classification1.getItemPart().add("itemPart1");
688   classification1.getItemPart().add("itemPart2");
689   classification1.setClassificationSort("classificationSort1");
690   classification1.setClassificationView("classificationView1");
691   location.getClassification().add(classification1);
692   Classification classification2= new Classification();
693   classification2.setShelvingScheme("shelvingScheme2");
694   classification2.setShelvingOrder("shelvingOrder3");
695   classification2.getCallNumberPrefix().add("2Call Number Prefix-1");
696   classification2.getCallNumberPrefix().add("2Call Number Prefix-2");
697   classification2.getCallNumberSuffix().add("2Call Number Suffix-1");
698   classification2.getCallNumberSuffix().add("2Call Number Suffix-2");
699   classification2.setClassificationPart("classificationPart2");
700   classification2.getItemPart().add("2itemPart1");
701   classification2.getItemPart().add("2itemPart2");
702   classification2.setClassificationSort("classificationSort2");
703   classification2.setClassificationView("classificationView2");
704   location.getClassification().add(classification2);
705 
706   location.getFormerShelvingLocation().add("formerShelvingLocation1");
707   location.getFormerShelvingLocation().add("formerShelvingLocation2");
708 
709   location.getAddress().add("address1");
710   location.getAddress().add("address2");
711   location.getAddress().add("address3");
712 
713   location.getCodedLocationQualifier().add("codedLocationQualifier1");
714   location.getCodedLocationQualifier().add("codedLocationQualifier2");
715 
716   location.getNoncodedLocationQualifier().add("noncodedLocationQualifier1");
717   location.getNoncodedLocationQualifier().add("noncodedLocationQualifier2");
718 
719   location.setShelvingControlNumber("shelvingControlNumber1");
720   location.setShelvingFormOfTitle("shelvingFormOfTitle1");
721 
722   CodeOrIdentifier country = new CodeOrIdentifier();
723   country.setValue("country value");
724   TypeOrSource countryType = new TypeOrSource();
725   countryType.setPointer("countryType pointer1");
726   countryType.setText("countryType text1");
727   country.setTypeOrSource(countryType);
728   location.setCountryCode(country);
729 
730   location.getCopyrightArticleFeeCode().add("copyrightArticleFeeCode1");
731   location.getCopyrightArticleFeeCode().add("copyrightArticleFeeCode2");
732 
733   location.setCopyNumber("123455");
734   location.setPieceDesignation("pieceDesignation1");
735 
736   location.getNonPublicNote().add("nonPublicNote11");
737   location.getNonPublicNote().add("nonPublicNote22");
738 
739   location.getPublicNote().add("publicNote11");
740   location.getPublicNote().add("publicNote22");
741 
742   CodeOrIdentifier classificationId = new CodeOrIdentifier();
743   TypeOrSource typeOrSource4 = new TypeOrSource();
744   typeOrSource4.setPointer("Classification Pointer -1");
745   typeOrSource4.setText("Classification Text -1");
746   classificationId.setTypeOrSource(typeOrSource4);
747   classificationId.setValue("Classification-1");
748   location.setClassificationOrShelvingSchemeSource(classificationId);
749 
750   location.setMaterialsSpecified("materialsSpecified1");
751   item.getLocation().add(location);
752 
753   HighDensityStorage highDensityStorage = new HighDensityStorage();
754   highDensityStorage.setHds("hds1");
755   highDensityStorage.setModule("module1");
756   highDensityStorage.setRow("row1");
757   highDensityStorage.setShelf("shelf1");
758   item.setHighDensityStorage(highDensityStorage);
759 
760   item.getVendorLineItemIdentifier().add("Vendoer Line Item Identifier-1");
761 
762   // Extension
763   Extension ext = new Extension();
764   ext.setDisplayLabel("display Label --20");
765   AdditionalAttributes aa = new AdditionalAttributes();
766   aa.setDateEntered("2012-04-10");
767   aa.setLastUpdated("2012-04-01");
768   aa.setSupressFromPublic("false");
769   aa.setFastAddFlag("false");
770   aa.setHarvestable("true");
771   aa.setStatus("n"); // new Record
772   ext.getContent().add(aa);
773   item.getExtension().add(ext);
774   // ITEM : CREATION :END
775 
776   instance.getItem().add(item);
777   oleInstanceList.add(instance);
778   instanceCollection.setInstanceCollection(oleInstanceList);
779 
780 }     */
781 
782     public void tearDown() {
783         LOG.info("Running tearDown()");
784     }
785 
786     @Test
787     public void testGenerateXML() throws Exception {
788         WorkInstanceOlemlRecordProcessor oleInstanceConverter = new WorkInstanceOlemlRecordProcessor();
789         String xml = oleInstanceConverter.toXML(instanceCollection);
790         assertNotNull(xml);
791         LOG.info(xml);
792         InstanceCollection instanceCollection = oleInstanceConverter.fromXML(xml);
793         assertNotNull(instanceCollection);
794         LOG.info("instanceCollection" + instanceCollection);
795 
796         LOG.info("Regained XML: \n" + oleInstanceConverter.toXML(instanceCollection));
797     }
798 
799     @Test
800     public void testToXMLHoldings() {
801         try {
802             WorkInstanceOlemlRecordProcessor processor = new WorkInstanceOlemlRecordProcessor();
803             String holdingsXml = processor.toXML(holdings);
804             String sourceHoldingsXml = processor.toXML(sourceHoldings);
805             LOG.info(holdingsXml);
806             assertNotNull(holdingsXml);
807         } catch (Exception e) {
808             e.printStackTrace();
809             fail("Holdings Object to Xml Conversion Failed." + e);
810         }
811 
812     }
813 
814     @Test
815     public void testToXMLItem() {
816         try {
817             WorkInstanceOlemlRecordProcessor processor = new WorkInstanceOlemlRecordProcessor();
818             String xml = processor.toXML(item);
819             LOG.info("XML : \n" + xml);
820             assertNotNull(xml);
821         } catch (Exception e) {
822             e.printStackTrace();
823             fail("Iteml Object to Xml Conversion Failed." + e);
824         }
825     }
826 
827     @Test
828     public void testGenerateObjectFromXML() throws Exception {
829         WorkInstanceOlemlRecordProcessor oleInstanceConverter = new WorkInstanceOlemlRecordProcessor();
830         URL url = getClass().getResource(sampleXmlFilePath);
831         File file = new File(url.toURI());
832         instanceCollection = oleInstanceConverter.fromXML(readFile(file));
833         LOG.info("entered");
834         for (Instance inst : instanceCollection.getInstance()) {
835             LOG.info("Instance Identifier:" + inst.getInstanceIdentifier());
836             LOG.info("Resource Identifier:" + inst.getResourceIdentifier());
837             LOG.info("Former Resource Identifier:" + inst.getResourceIdentifier());
838             LOG.info(inst.getSourceHoldings().getHoldings().getContent().toString());
839             LOG.info(inst.getItems().getItem().get(0).getAnalytic().toString());
840             LOG.info(inst.getItems().getItem().get(0).getResourceIdentifier());
841             LOG.info(inst.getOleHoldings().getPrimary());
842         }
843         String xml = oleInstanceConverter.toXML(instanceCollection);
844         LOG.info("xml isssssssssss" + xml);
845     }
846 
847     @Test
848     public void testFromXMLAndToXmlInstanceCollection() throws Exception {
849         WorkInstanceOlemlRecordProcessor oleInstanceConverter = new WorkInstanceOlemlRecordProcessor();
850         URL url = getClass().getResource(sampleXmlFilePath);
851         File file = new File(url.toURI());
852         InstanceCollection instanceCollection = oleInstanceConverter.fromXML(readFile(file));
853         assertNotNull(instanceCollection);
854         String xml = oleInstanceConverter.toXML(instanceCollection);
855         LOG.info("Generated XML : " + xml);
856         LOG.info("GENERATED XML: ");
857         LOG.info(xml);
858         assertNotNull(xml);
859     }
860 
861     private String readFile(File file) throws IOException {
862         BufferedReader reader = new BufferedReader(new FileReader(file));
863         String line = null;
864         StringBuilder stringBuilder = new StringBuilder();
865         String ls = System.getProperty("line.separator");
866         while ((line = reader.readLine()) != null) {
867             stringBuilder.append(line);
868             stringBuilder.append(ls);
869         }
870         return stringBuilder.toString();
871     }
872 
873 
874     @Test
875     public void testInstanceAddAttributesFromXml() {
876         URL resource = getClass().getResource(sampleXmlFilePath);
877         WorkInstanceOlemlRecordProcessor oleInstanceConverter = new WorkInstanceOlemlRecordProcessor();
878         try {
879             File file = new File(resource.toURI());
880             String instance = readFile(file);
881             LOG.info("instance" + instance);
882             InstanceCollection instanceCollection = oleInstanceConverter.fromXML(instance);
883             LOG.info(instanceCollection.toString());
884 
885             OleHoldings oleHolding = instanceCollection.getInstance().get(0).getOleHoldings();
886             Item oleItem = instanceCollection.getInstance().get(0).getItems().getItem().get(0);
887 
888             AdditionalAttributes addAttributes = (AdditionalAttributes) oleHolding.getExtension().getContent().get(0);
889             LOG.info("additional attribute names that are existing" + addAttributes.getAttributeNames());
890             addAttributes.setAttribute("createdBy", "HTC GLOBAL SERVICES.");
891             String xml = oleInstanceConverter.toXML(instanceCollection);
892             LOG.info("HOLDINGS XMl with newly added  additional attribute \n" + xml);
893 
894             addAttributes = (AdditionalAttributes) oleItem.getExtension().getContent().get(0);
895             LOG.info("additional attribute names that are existing" + addAttributes.getAttributeNames());
896             addAttributes.setAttribute("createdBy", "HTC GLOBAL SERVICES.");
897             String itemXml = oleInstanceConverter.toXML(instanceCollection);
898             LOG.info("ITEM XML with newly added  additional attribute \n" + itemXml);
899 
900             // Want to ingest this generated xml "createdBy" attribute should registered in customFileNode.cnd file in Doc-Store
901             // Repository should be cleared.
902 
903         } catch (Exception e) {
904             LOG.info(e.getMessage(), e);
905         }
906     }
907 
908     @Test
909     public void testItemValuesFromDefaultXml() {
910         URL resource = getClass().getResource("/schema/work/instance/oleml/instance9.1.1.xsd.xml");
911         WorkInstanceOlemlRecordProcessor oleInstanceConverter = new WorkInstanceOlemlRecordProcessor();
912         try {
913             File file = new File(resource.toURI());
914             String instance = readFile(file);
915 //            LOG.info("instance" + instance);
916             InstanceCollection instanceCollection = oleInstanceConverter.fromXML(instance);
917             LOG.info(instanceCollection.toString());
918             Item oleItem = instanceCollection.getInstance().get(0).getItems().getItem().get(0);
919             LOG.info("location level is " + oleItem.getLocation().getLocationLevel());
920             instanceCollection.setInstance(null);
921             Assert.assertNotNull(instanceCollection.getInstance());
922         } catch (Exception e) {
923             LOG.info(e.getMessage(), e);
924         }
925 
926     }
927 
928 
929 }