1 package org.kuali.ole.docstore.model.jaxb.config;
2
3 import org.apache.commons.io.FileUtils;
4 import org.junit.Test;
5 import org.kuali.ole.docstore.model.xmlpojo.config.*;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8
9 import java.io.File;
10 import java.net.URL;
11
12
13
14
15
16
17
18
19 public class DocumentConfigConverter_UT {
20
21 public static final Logger LOG = LoggerFactory.getLogger(DocumentConfigConverter_UT.class);
22
23 @Test
24 public void unmarshal() {
25 DocumentConfigConverter documentConverter = new DocumentConfigConverter();
26 String nullXml = null;
27
28 URL resource = getClass().getResource("/org/kuali/ole/docstore/DocumentConfig.xml");
29 try {
30 File file = new File(resource.toURI());
31 String docXml = FileUtils.readFileToString(file);
32 DocumentConfig documentConfig = documentConverter.unmarshal(docXml);
33 LOG.info("Types size: " + documentConfig.getDocumentCategories().get(0).getDocumentTypes().size());
34 for (DocumentCategory documentCategory : documentConfig.getDocumentCategories()) {
35 LOG.info("Category Name: " + documentCategory.getName());
36 LOG.info("Category ID: " + documentCategory.getId());
37 for (DocumentType documentType : documentCategory.getDocumentTypes()) {
38 LOG.info("Type Name: " + documentType.getName());
39 LOG.info("Type ID: " + documentType.getId());
40 for (DocumentFormat documentFormat : documentType.getDocumentFormats()) {
41 LOG.info("Format Name: " + documentFormat.getName());
42 LOG.info("Format ID: " + documentFormat.getId());
43 for (Field field : documentFormat.getFields()) {
44 LOG.info("Field Name: " + field.getName());
45 LOG.info("Field ID: " + field.getId());
46 LOG.info("Field Type: " + field.getType());
47 }
48 }
49 }
50 }
51 String docConfigXml = documentConverter.marshal(documentConfig);
52 LOG.info("Document Config XML" + docConfigXml);
53 DocumentConfig documentConfig1 = DocumentConfig.getInstance();
54 if (documentConfig1.getDocumentCategories() != null) {
55 for (DocumentCategory documentCategory : documentConfig1.getDocumentCategories()) {
56 LOG.info(documentCategory.toString());
57 }
58 }
59 } catch (Exception e) {
60 LOG.info(e.getMessage(), e);
61 }
62
63 try {
64 documentConverter.unmarshal(nullXml);
65
66 } catch (Exception e) {
67 LOG.info("invalid file");
68 }
69
70 }
71 }