Changeset 2173
- Timestamp:
- 08/29/12 14:51:22 (12 years ago)
- Location:
- ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/CMDComponentTypeWrapperTest.java
r2170 r2173 228 228 } 229 229 230 //writing profile filecompspec into the file filename230 //writing compspec into the file filename 231 231 private void writeSpecToFile(CMDComponentSpec compspec, String filename) throws IOException, JAXBException { 232 232 -
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/RssCreatorTest.java
r2162 r2173 5 5 package clarin.cmdi.componentregistry; 6 6 7 import clarin.cmdi.componentregistry.components.CMDComponentSpec;8 7 import clarin.cmdi.componentregistry.model.AbstractDescription; 9 8 import clarin.cmdi.componentregistry.model.ComponentDescription; 10 9 import clarin.cmdi.componentregistry.model.ProfileDescription; 11 10 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 11 import clarin.cmdi.componentregistry.rss.Rss; 12 import clarin.cmdi.componentregistry.rss.RssChannel; 12 13 import clarin.cmdi.componentregistry.rss.RssItem; 14 import java.io.ByteArrayOutputStream; 15 import java.io.File; 16 import java.io.FileOutputStream; 13 17 import java.io.IOException; 18 import java.io.InputStream; 14 19 import javax.xml.bind.JAXBException; 15 20 import org.junit.After; … … 109 114 } 110 115 116 117 ///////////////////////////////////////// 118 // writing ByteArrayOutputStream into the file filename 119 private void writeStreamToFile(ByteArrayOutputStream os, String filename) throws IOException, JAXBException { 120 121 FileOutputStream fop = null; 122 File file; 123 124 file = new File(filename); 125 fop = new FileOutputStream(file); 126 127 fop.write(os.toByteArray()); 128 129 fop.flush(); 130 fop.close(); 131 132 System.out.println("the rss is written into the file and saved"); 133 134 135 } 136 137 138 139 //////////////////////////// 111 140 @Test 112 141 public void profileTestToRssItem() { … … 116 145 "description", "domainname", "groupname", "href", "name", true, "uid"); 117 146 147 118 148 RssCreator creator = new RssCreator(pdesc); 119 149 RssItem result = creator.toRssItem(); 120 150 assertEqualDescriptions(pdesc, result); 121 151 122 } 123 152 153 } 154 155 // write test component into file 156 private void writeComponentIntoFile(ComponentDescription cdesc, String filename) throws IOException, JAXBException { 157 158 159 ByteArrayOutputStream os = new ByteArrayOutputStream(); 160 MDMarshaller.marshal(cdesc, os); 161 162 writeStreamToFile(os, filename); 163 164 } 165 166 /////////////////////////////////////// 167 // make test component 1 and write it into file 168 169 private ComponentDescription makeTestComponent1() throws IOException, JAXBException { 170 171 ComponentDescription cdesc= 172 createTestComponentDescription(67, "God", 173 "description1dum", "domainname1dum", "groupname1dum", "href1dum", "name1dum", "uid1dum"); 174 175 return cdesc; 176 } 177 178 /////////////////////////////////////// 179 // make test component 1 and write it into file 180 181 private ComponentDescription makeTestComponent2() throws IOException, JAXBException { 182 183 ComponentDescription cdesc= 184 createTestComponentDescription(23, "Allah", 185 "description2dum", "domainname2dum", "groupname2dum", "href2dum", "name2dum", "uid2dum"); 186 187 return cdesc; 188 } 189 190 //////////////////////////////////////// 124 191 @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 192 public void testRssChannelAndMarshal() throws IOException, JAXBException { 193 194 ComponentDescription cdesc1=makeTestComponent1(); 195 writeComponentIntoFile(cdesc1, "src/test/resources/xml/Component1.xml"); 196 197 ComponentDescription cdesc2=makeTestComponent2(); 198 writeComponentIntoFile(cdesc2, "src/test/resources/xml/Component2.xml"); 199 200 201 202 InputStream is1 = RegistryTestHelper.getComponentContent(RegistryTestHelper.getProfileContentFromFile("/xml/Component1.xml")); 203 ComponentDescription desc1 = MDMarshaller.unmarshal(ComponentDescription.class, is1, null) ; 204 205 InputStream is2 = RegistryTestHelper.getComponentContent(RegistryTestHelper.getProfileContentFromFile("/xml/Component2.xml")); 206 ComponentDescription desc2 = MDMarshaller.unmarshal(ComponentDescription.class, is2, null) ; 207 208 209 RssCreator creator1 = new RssCreator(desc1); 210 RssItem rssitem1 = creator1.toRssItem(); 211 assertTrue(rssitem1 !=null); 212 assertEqualDescriptions(desc1, rssitem1); 213 214 215 RssCreator creator2 = new RssCreator(desc2); 216 RssItem rssitem2 = creator2.toRssItem(); 217 assertTrue(rssitem2 !=null); 218 assertEqualDescriptions(desc2, rssitem2); 219 220 221 222 final Rss rss = new Rss(); 223 final RssChannel channel = new RssChannel(); 224 rss.setChannel(channel); 225 channel.getItem().add(rssitem1); 226 channel.getItem().add(rssitem2); 227 228 ByteArrayOutputStream osrss = new ByteArrayOutputStream(); 229 MDMarshaller.marshal(rss, osrss); 230 231 writeStreamToFile(osrss, "src/test/resources/xml/rssTest.xml"); 232 233 234 } 235 236 237 238 239 240 241 242 ////////////////////////////////////////////// 243 /* @Test 139 244 public void fileLargeProfileTestToRssItem() throws IOException, JAXBException { 245 246 InputStream largeProfileStream = RegistryTestHelper.class.getResourceAsStream("/xml/largeProfile.xml"); 140 247 141 String largeprofilestring = RegistryTestHelper.getLargeProfileContent(); // reading from the file 142 CMDComponentSpec compspec=RegistryTestHelper.getComponentFromString(largeprofilestring); // calling unmarchaller 248 AbstractDescription desc=MDMarshaller.unmarshal(ComponentDescription.class, largeProfileStream, null); 249 250 assertTrue(desc !=null); 143 251 144 145 // do not know how to get AbstractDescription from this file 252 RssCreator creator = new RssCreator(desc); 253 RssItem rss = creator.toRssItem(); 254 255 //assertTrue(rss !=null); 256 257 258 System.out.println(rss.getAuthor()); 259 System.out.println(rss.getDescription()); 260 System.out.println(rss.getLink()); 261 System.out.println(rss.getPubDate()); 262 System.out.println(rss.getTitle()); 263 264 265 writeRssToFile(rss, "src/test/resources/xml/rssOfLargeProfile.xml"); 266 267 268 146 269 147 270 } 148 271 */ 149 272 }
Note: See TracChangeset
for help on using the changeset viewer.