View Javadoc
1   /*
2    * Copyright 2012 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.docstore.model.xstream.metadata;
17  
18  import com.thoughtworks.xstream.core.util.Fields;
19  import org.apache.commons.io.IOUtils;
20  import org.junit.After;
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.kuali.ole.docstore.model.xmlpojo.metadata.DocumentMetaData;
24  import org.kuali.ole.docstore.model.xmlpojo.metadata.DocumentsMetaData;
25  import org.kuali.ole.docstore.model.xmlpojo.metadata.Field;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  import sun.rmi.runtime.Log;
29  
30  import javax.swing.event.ListDataEvent;
31  import java.util.List;
32  
33  import java.util.ArrayList;
34  
35  import static junit.framework.Assert.*;
36  
37  /**
38   * Class to DocStoreMetaDataXmlProcessor_UT.
39   *
40   * @author Rajesh Chowdary K
41   * @created Jun 14, 2012
42   */
43  public class DocStoreMetaDataXmlProcessor_UT {
44  
45      public static final Logger LOG = LoggerFactory.getLogger(DocStoreMetaDataXmlProcessor_UT.class);
46  
47      /**
48       * Method to setUp
49       *
50       * @throws java.lang.Exception
51       */
52      @Before
53      public void setUp() throws Exception {
54      }
55  
56      /**
57       * Method to tearDown
58       *
59       * @throws java.lang.Exception
60       */
61      @After
62      public void tearDown() throws Exception {
63      }
64  
65      /**
66       * Test method for {@link org.kuali.ole.docstore.model.xstream.metadata.DocStoreMetaDataXmlProcessor#fromXml(java.lang.String)}.
67       *
68       * @throws Exception
69       */
70      @Test
71      public void testFromXml() throws Exception {
72          try {
73              DocumentsMetaData metadata = new DocStoreMetaDataXmlProcessor().fromXml(IOUtils.toString(getClass().getResource(
74                      "/org/kuali/ole/docstore/documentsMetaData.xml")));
75              LOG.info("converted to MetaData : " + metadata);
76  
77          } catch (Exception e) {
78              e.printStackTrace();
79              throw e;
80          }
81      }
82  
83      /**
84       * Test method for {@link org.kuali.ole.docstore.model.xstream.metadata.DocStoreMetaDataXmlProcessor#fromXml(java.lang.String)}.
85       *
86       * @throws Exception
87       */
88      @Test
89      public void testDocStoreMetaData() throws Exception {
90          try {
91              DocumentMetaData marcMetaData = DocumentsMetaData.getInstance().getDocumentMetaData("work", "bib", "marc");
92              LOG.info("Marc MetaData : " + marcMetaData);
93              for (Field field : marcMetaData.getFields())
94                  LOG.info("Field:\t" + field.getName() + "\t\t:\t\t" + field.getProperties());
95  
96              DocumentMetaData dubUnqMetaData = DocumentsMetaData.getInstance().getDocumentMetaData("work", "bib", "dublinunq");
97              LOG.info("Dublin Unq MetaData : " + dubUnqMetaData);
98              for (Field field : dubUnqMetaData.getFields())
99                  LOG.info("Field:\t" + field.getName() + "\t\t:\t\t" + field.getProperties());
100 
101             DocumentMetaData dubMetaData = DocumentsMetaData.getInstance().getDocumentMetaData("work", "bib", "dublin");
102             LOG.info("Dublin MetaData : " + dubMetaData);
103             for (Field field : dubMetaData.getFields())
104                 LOG.info("Field:\t" + field.getName() + "\t\t:\t\t" + field.getProperties());
105 
106             DocumentMetaData documentMetaData = new DocumentMetaData();
107             Field field = new Field();
108             List<Field> fieldList = new ArrayList<Field>();
109             documentMetaData.setCategory("category");
110             documentMetaData.setFormat("Format");
111             documentMetaData.setType("type");
112             field.set("property", "value");
113             if (field.get("property") != null) {
114                 LOG.info(field.get("property"));
115             }
116             fieldList.add(field);
117             documentMetaData.setFields(null);
118             if (documentMetaData.getFields() != null) {
119                 for (Field field1 : documentMetaData.getFields()) {
120                     LOG.info(field1.toString());
121                 }
122             }
123             List<DocumentMetaData> documentsMetaDatas = new ArrayList<DocumentMetaData>();
124             documentsMetaDatas.add(documentMetaData);
125             DocumentsMetaData documentsMetaData = new DocumentsMetaData();
126             documentsMetaData.setDocumentsMetaData(documentsMetaDatas);
127             if (documentsMetaData.getDocumentsMetaData() != null) {
128                 for (DocumentMetaData documentMetaData1 : documentsMetaData.getDocumentsMetaData()) {
129                     LOG.info(documentMetaData1.toString());
130                 }
131             }
132 
133         } catch (Exception e) {
134             e.printStackTrace();
135             throw e;
136         }
137     }
138 }