1 | /* |
---|
2 | * To change this template, choose Tools | Templates |
---|
3 | * and open the template in the editor. |
---|
4 | */ |
---|
5 | package clarin.cmdi.componentregistry; |
---|
6 | |
---|
7 | import clarin.cmdi.componentregistry.components.CMDComponentSpec; |
---|
8 | import clarin.cmdi.componentregistry.model.AbstractDescription; |
---|
9 | import clarin.cmdi.componentregistry.model.ComponentDescription; |
---|
10 | import clarin.cmdi.componentregistry.model.ProfileDescription; |
---|
11 | import clarin.cmdi.componentregistry.rest.RegistryTestHelper; |
---|
12 | import clarin.cmdi.componentregistry.rss.RssItem; |
---|
13 | import java.io.IOException; |
---|
14 | import javax.xml.bind.JAXBException; |
---|
15 | import org.junit.After; |
---|
16 | import org.junit.AfterClass; |
---|
17 | import org.junit.Before; |
---|
18 | import org.junit.BeforeClass; |
---|
19 | import org.junit.Test; |
---|
20 | import static org.junit.Assert.*; |
---|
21 | |
---|
22 | /** |
---|
23 | * |
---|
24 | * @author olhsha |
---|
25 | */ |
---|
26 | public class RssCreatorTest { |
---|
27 | |
---|
28 | public RssCreatorTest() { |
---|
29 | } |
---|
30 | |
---|
31 | // ???????????????? |
---|
32 | @BeforeClass |
---|
33 | public static void setUpClass() { |
---|
34 | } |
---|
35 | |
---|
36 | @AfterClass |
---|
37 | public static void tearDownClass() { |
---|
38 | } |
---|
39 | |
---|
40 | @Before |
---|
41 | public void setUp() { |
---|
42 | } |
---|
43 | |
---|
44 | @After |
---|
45 | public void tearDown() { |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * Test of toRssItem method, of class RssCreator. |
---|
50 | */ |
---|
51 | @Test |
---|
52 | public void nullTestToRssItem() { |
---|
53 | |
---|
54 | RssCreator creator = new RssCreator(null); |
---|
55 | RssItem result = creator.toRssItem(); |
---|
56 | assertEquals(null, result); |
---|
57 | |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | |
---|
62 | private ProfileDescription createTestProfileDescription(int commentcount, String creatorname, |
---|
63 | String description, String domainname, String groupname, String href, |
---|
64 | String name, boolean editorflag, String uid){ |
---|
65 | |
---|
66 | ProfileDescription pdesc = ProfileDescription.createNewDescription(); |
---|
67 | |
---|
68 | pdesc.setCommentsCount(commentcount); |
---|
69 | pdesc.setCreatorName(creatorname); |
---|
70 | pdesc.setDescription(description); |
---|
71 | pdesc.setDomainName(domainname); |
---|
72 | pdesc.setGroupName(groupname); |
---|
73 | pdesc.setHref(href); |
---|
74 | pdesc.setName(name); |
---|
75 | pdesc.setShowInEditor(editorflag); |
---|
76 | pdesc.setUserId(uid); |
---|
77 | |
---|
78 | return pdesc; |
---|
79 | |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | private ComponentDescription createTestComponentDescription(int commentcount, String creatorname, |
---|
84 | String description, String domainname, String groupname, String href, |
---|
85 | String name, String uid){ |
---|
86 | |
---|
87 | ComponentDescription cdesc = ComponentDescription.createNewDescription(); |
---|
88 | |
---|
89 | cdesc.setCommentsCount(commentcount); |
---|
90 | cdesc.setCreatorName(creatorname); |
---|
91 | cdesc.setDescription(description); |
---|
92 | cdesc.setDomainName(domainname); |
---|
93 | cdesc.setGroupName(groupname); |
---|
94 | cdesc.setHref(href); |
---|
95 | cdesc.setName(name); |
---|
96 | cdesc.setUserId(uid); |
---|
97 | |
---|
98 | return cdesc; |
---|
99 | |
---|
100 | |
---|
101 | } |
---|
102 | |
---|
103 | private void assertEqualDescriptions(AbstractDescription desc, RssItem item){ |
---|
104 | assertEquals(desc.getCreatorName(), item.getAuthor()); |
---|
105 | assertEquals(desc.getDescription(), item.getDescription()); |
---|
106 | assertEquals(desc.getHref(), item.getLink()); |
---|
107 | assertEquals(desc.getRegistrationDate(), item.getPubDate()); |
---|
108 | assertEquals(desc.getName(), item.getTitle()); |
---|
109 | } |
---|
110 | |
---|
111 | @Test |
---|
112 | public void profileTestToRssItem() { |
---|
113 | |
---|
114 | ProfileDescription pdesc= |
---|
115 | createTestProfileDescription(23, "creatorname", |
---|
116 | "description", "domainname", "groupname", "href", "name", true, "uid"); |
---|
117 | |
---|
118 | RssCreator creator = new RssCreator(pdesc); |
---|
119 | RssItem result = creator.toRssItem(); |
---|
120 | assertEqualDescriptions(pdesc, result); |
---|
121 | |
---|
122 | } |
---|
123 | |
---|
124 | @Test |
---|
125 | public void componentTestToRssItem() { |
---|
126 | |
---|
127 | ComponentDescription cdesc= |
---|
128 | createTestComponentDescription(67, "creatorname", |
---|
129 | "description", "domainname", "groupname", "href", "name", "uid"); |
---|
130 | |
---|
131 | RssCreator creator = new RssCreator(cdesc); |
---|
132 | RssItem result = creator.toRssItem(); |
---|
133 | assertEqualDescriptions(cdesc, result); |
---|
134 | |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | @Test |
---|
139 | public void fileLargeProfileTestToRssItem() throws IOException, JAXBException { |
---|
140 | |
---|
141 | String largeprofilestring = RegistryTestHelper.getLargeProfileContent(); // reading from the file |
---|
142 | CMDComponentSpec compspec=RegistryTestHelper.getComponentFromString(largeprofilestring); // calling unmarchaller |
---|
143 | |
---|
144 | |
---|
145 | // do not know how to get AbstractDescription from this file |
---|
146 | |
---|
147 | } |
---|
148 | |
---|
149 | } |
---|