001package org.kuali.ole;
002
003import org.junit.Test;
004import org.kuali.ole.docstore.xstream.FileUtil;
005import org.kuali.ole.pojo.OleBibRecord;
006import org.kuali.ole.pojo.OleEditorResponse;
007import org.slf4j.Logger;
008import org.slf4j.LoggerFactory;
009import sun.rmi.runtime.Log;
010
011import java.io.File;
012import java.net.URL;
013import java.util.HashMap;
014import java.util.Map;
015
016import static junit.framework.Assert.assertEquals;
017import static junit.framework.Assert.assertNotNull;
018import static junit.framework.Assert.assertTrue;
019
020/**
021 * Created by IntelliJ IDEA.
022 * User: pvsubrah
023 * Date: 4/11/12
024 * Time: 2:52 PM
025 * To change this template use File | Settings | File Templates.
026 */
027public class OleEditorResponseHandler_UT {
028    public static final Logger LOG = LoggerFactory.getLogger(OleEditorResponseHandler_UT.class);
029    private String xmlContent = "";
030
031    //TODO
032    @Test
033    public void testToXML() throws Exception {
034        OleEditorResponseHandler handler = new OleEditorResponseHandler();
035        OleEditorResponse response = new OleEditorResponse();
036        response.setTokenId("3000_0");
037        OleBibRecord record = new OleBibRecord();
038        record.setBibUUID("2345-6789");
039        record.setLinkedInstanceId("123-34567");
040        Map bibAssociatedFieldsValueMap = new HashMap();
041        bibAssociatedFieldsValueMap.put("author", "mock_author");
042        bibAssociatedFieldsValueMap.put("title", "mock_title");
043        record.setBibAssociatedFieldsValueMap(bibAssociatedFieldsValueMap);
044        response.setOleBibRecord(record);
045        LOG.info(handler.toXML(response));
046        //
047        if (record.getBibAssociatedFieldsValueMap() != null) {
048            LOG.info("BIbValueMap is not empty");
049        }
050        if (response.getTokenId() != null) {
051            LOG.info(response.getTokenId());
052        }
053    }
054
055
056    //TODO
057    @Test
058    public void testFrom() throws Exception {
059        OleEditorResponseHandler oleEditorResponseHandler =
060                new OleEditorResponseHandler();
061
062        URL resource = getClass().getResource("OleEditorResponse.xml");
063        String xmlContent = new FileUtil().readFile(new File(resource.toURI()));
064
065        OleEditorResponse oleEditorResponse = oleEditorResponseHandler.fromXML(xmlContent);
066        assertNotNull(oleEditorResponse);
067        assertEquals(oleEditorResponse.getOleBibRecord().getBibUUID(), "2345-6789");
068        assertEquals(oleEditorResponse.getOleBibRecord().getLinkedInstanceId(), "123-34567");
069    }
070}