1 package org.kuali.ole;
2
3 import org.junit.Test;
4 import org.kuali.ole.docstore.xstream.FileUtil;
5 import org.kuali.ole.pojo.OleBibRecord;
6 import org.kuali.ole.pojo.OleEditorResponse;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9 import sun.rmi.runtime.Log;
10
11 import java.io.File;
12 import java.net.URL;
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import static junit.framework.Assert.assertEquals;
17 import static junit.framework.Assert.assertNotNull;
18 import static junit.framework.Assert.assertTrue;
19
20
21
22
23
24
25
26
27 public class OleEditorResponseHandler_UT {
28 public static final Logger LOG = LoggerFactory.getLogger(OleEditorResponseHandler_UT.class);
29 private String xmlContent = "";
30
31
32 @Test
33 public void testToXML() throws Exception {
34 OleEditorResponseHandler handler = new OleEditorResponseHandler();
35 OleEditorResponse response = new OleEditorResponse();
36 response.setTokenId("3000_0");
37 OleBibRecord record = new OleBibRecord();
38 record.setBibUUID("2345-6789");
39 record.setLinkedInstanceId("123-34567");
40 Map bibAssociatedFieldsValueMap = new HashMap();
41 bibAssociatedFieldsValueMap.put("author", "mock_author");
42 bibAssociatedFieldsValueMap.put("title", "mock_title");
43 record.setBibAssociatedFieldsValueMap(bibAssociatedFieldsValueMap);
44 response.setOleBibRecord(record);
45 LOG.info(handler.toXML(response));
46
47 if (record.getBibAssociatedFieldsValueMap() != null) {
48 LOG.info("BIbValueMap is not empty");
49 }
50 if (response.getTokenId() != null) {
51 LOG.info(response.getTokenId());
52 }
53 }
54
55
56
57 @Test
58 public void testFrom() throws Exception {
59 OleEditorResponseHandler oleEditorResponseHandler =
60 new OleEditorResponseHandler();
61
62 URL resource = getClass().getResource("OleEditorResponse.xml");
63 String xmlContent = new FileUtil().readFile(new File(resource.toURI()));
64
65 OleEditorResponse oleEditorResponse = oleEditorResponseHandler.fromXML(xmlContent);
66 assertNotNull(oleEditorResponse);
67 assertEquals(oleEditorResponse.getOleBibRecord().getBibUUID(), "2345-6789");
68 assertEquals(oleEditorResponse.getOleBibRecord().getLinkedInstanceId(), "123-34567");
69 }
70 }