Changeset 2194
- Timestamp:
- 09/03/12 15:01:10 (12 years ago)
- Location:
- ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry
- Files:
-
- 11 added
- 10 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r2153 r2194 1 1 package clarin.cmdi.componentregistry.rest; 2 2 3 import clarin.cmdi.componentregistry.CMDComponentTypeWrapper; 3 4 4 import clarin.cmdi.componentregistry.ComponentRegistry; 5 5 import clarin.cmdi.componentregistry.ComponentRegistryException; … … 799 799 800 800 // Olha: removing filename from spec before it gets extended!!! recursion over all the components 801 CMDComponentTypeWrapper setnull = new CMDComponentTypeWrapper(spec);801 setFileNamesFromListToNull(spec.getCMDComponent()); 802 802 803 803 … … 938 938 939 939 940 /// two muchually recursive methods below are used to set filenames of components (and their child components) to null 941 /* 942 * @param List<CMDComponentType> listofcomponents the list of components whose filenames (and the children's names) are to be set to null 943 */ 944 public void setFileNamesFromListToNull(List<CMDComponentType> listofcomponents){ 945 946 for (CMDComponentType currentcomponent : listofcomponents) { 947 setFileNamesToNullCurrent(currentcomponent); 948 } 949 950 } 951 952 /* 953 * @param CMDComponentType currentcomponent the component whose filename (and whose children filenames) is to be set to null 954 */ 955 956 public void setFileNamesToNullCurrent(CMDComponentType currentcomponent){ 957 958 currentcomponent.setFilename(null); 959 setFileNamesFromListToNull(currentcomponent.getCMDComponent()); 960 961 } 962 963 //////////////////////////////////////////////// 964 965 940 966 } -
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/RssCreatorTest.java
r2173 r2194 14 14 import java.io.ByteArrayOutputStream; 15 15 import java.io.File; 16 import java.io.FileInputStream; 16 17 import java.io.FileOutputStream; 17 18 import java.io.IOException; … … 115 116 116 117 117 /////////////////////////////////////////118 // writing ByteArrayOutputStream into the file filename119 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 118 138 119 … … 160 141 MDMarshaller.marshal(cdesc, os); 161 142 162 writeStreamToFile(os, filename);143 RegistryTestHelper.writeStreamToFile(os, filename); 163 144 164 145 } … … 192 173 public void testRssChannelAndMarshal() throws IOException, JAXBException { 193 174 175 String dirName="MyTestXmls"; 176 File testDir = new File(dirName); 177 testDir.mkdir(); 178 179 String path = new File(testDir, dirName).getAbsolutePath(); 180 181 String comp1="Component1.xml"; 182 String comp2="Component2.xml"; 183 String rssOut="rssTest.xml"; 184 185 186 187 194 188 ComponentDescription cdesc1=makeTestComponent1(); 195 writeComponentIntoFile(cdesc1, "src/test/resources/xml/Component1.xml");189 writeComponentIntoFile(cdesc1, path+comp1); 196 190 197 191 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"));192 writeComponentIntoFile(cdesc2, path+comp2); 193 194 195 196 FileInputStream is1 = new FileInputStream(path+comp1); 203 197 ComponentDescription desc1 = MDMarshaller.unmarshal(ComponentDescription.class, is1, null) ; 204 198 205 InputStream is2 = RegistryTestHelper.getComponentContent(RegistryTestHelper.getProfileContentFromFile("/xml/Component2.xml"));199 FileInputStream is2 = new FileInputStream(path+comp2); 206 200 ComponentDescription desc2 = MDMarshaller.unmarshal(ComponentDescription.class, is2, null) ; 207 201 … … 229 223 MDMarshaller.marshal(rss, osrss); 230 224 231 writeStreamToFile(osrss, "src/test/resources/xml/rssTest.xml"); 232 233 234 } 235 236 237 238 239 240 241 242 ////////////////////////////////////////////// 243 /* @Test 244 public void fileLargeProfileTestToRssItem() throws IOException, JAXBException { 245 246 InputStream largeProfileStream = RegistryTestHelper.class.getResourceAsStream("/xml/largeProfile.xml"); 247 248 AbstractDescription desc=MDMarshaller.unmarshal(ComponentDescription.class, largeProfileStream, null); 249 250 assertTrue(desc !=null); 251 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 269 270 } 271 */ 225 RegistryTestHelper.writeStreamToFile(osrss, path+rssOut); 226 227 228 } 229 230 231 272 232 } -
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r2152 r2194 5 5 import clarin.cmdi.componentregistry.ComponentStatus; 6 6 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 7 import clarin.cmdi.componentregistry.components.CMDComponentType; 7 8 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryBeanFactory; 8 9 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase; … … 17 18 import com.sun.jersey.api.representation.Form; 18 19 import com.sun.jersey.multipart.FormDataMultiPart; 19 import java.awt.image.ComponentSampleModel;20 20 import java.io.ByteArrayInputStream; 21 21 import java.util.Date; … … 1143 1143 1144 1144 1145 1146 ///////////////////////////////// 1147 @Test 1148 public void testSetFilenamesToNullOnTestComponent() throws Exception { 1149 1150 CMDComponentSpec spec = RegistryTestHelper.getTestComponent(); 1151 1152 1153 List<CMDComponentType> listofcomponents = spec.getCMDComponent(); 1154 CMDComponentSetFilenamesToNullTestHelper helper = new CMDComponentSetFilenamesToNullTestHelper(); 1155 1156 helper.addDummyFilenamesToListOfComponents(listofcomponents); 1157 assertTrue(helper.checkNonNullnessOfFilenamesInListOfComponents(listofcomponents)); 1158 CMDComponentType compaux = helper.makeTestComponent(); 1159 listofcomponents.add(compaux); 1160 1161 1162 ComponentRegistryRestService restservice = helper.getTestRestService(); 1163 restservice.setFileNamesFromListToNull(spec.getCMDComponent()); 1164 helper.checkNullnessOfFilenamesInListOfComponents(listofcomponents); 1165 } 1166 1167 /////////////////////////////////// 1168 @Test 1169 public void testSetFilenamesToNullOnLargeProfile() throws Exception { 1170 1171 1172 String largeprofilestring = RegistryTestHelper.getLargeProfileContent(); 1173 CMDComponentSpec spec=RegistryTestHelper.getComponentFromString(largeprofilestring); // calling unmarchaller 1174 1175 1176 List<CMDComponentType> listofcomponents = spec.getCMDComponent(); 1177 CMDComponentSetFilenamesToNullTestHelper helper = new CMDComponentSetFilenamesToNullTestHelper(); 1178 1179 helper.addDummyFilenamesToListOfComponents(listofcomponents); 1180 assertTrue(helper.checkNonNullnessOfFilenamesInListOfComponents(listofcomponents)); 1181 1182 ComponentRegistryRestService restservice = helper.getTestRestService(); 1183 restservice.setFileNamesFromListToNull(spec.getCMDComponent()); 1184 helper.checkNullnessOfFilenamesInListOfComponents(listofcomponents); 1185 1186 } 1187 1145 1188 } -
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java
r2170 r2194 20 20 import clarin.cmdi.componentregistry.model.ProfileDescription; 21 21 import java.io.BufferedReader; 22 import java.io.File; 23 import java.io.FileOutputStream; 22 24 import java.io.InputStreamReader; 23 25 … … 27 29 */ 28 30 public final class RegistryTestHelper { 31 32 29 33 30 34 private RegistryTestHelper() { … … 153 157 } 154 158 159 160 public static String getStringFromStream(InputStream largeProfileStream) throws IOException { 161 try { 162 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(largeProfileStream)); 163 StringBuilder profileStringBuilder = new StringBuilder(); 164 String line; 165 while (null != (line = bufferedReader.readLine())) { 166 profileStringBuilder.append(line); 167 } 168 return profileStringBuilder.toString(); 169 } finally { 170 largeProfileStream.close(); 171 } 172 } 173 /////////////////////////////////////////////////////// 174 155 175 public static String getLargeProfileContent() throws IOException { 156 176 InputStream largeProfileStream = RegistryTestHelper.class.getResourceAsStream("/xml/largeProfile.xml"); 157 try { 158 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(largeProfileStream)); 159 StringBuilder profileStringBuilder = new StringBuilder(); 160 String line; 161 while (null != (line = bufferedReader.readLine())) { 162 profileStringBuilder.append(line); 163 } 164 return profileStringBuilder.toString(); 165 } finally { 166 largeProfileStream.close(); 167 } 168 } 169 170 171 // Olha was here 172 // a method similar to getLargeProfileContent(), but allowing to get profile from any fil, not only largeProfile.xml 173 public static String getProfileContentFromFile(String filename) throws IOException { 174 InputStream largeProfileStream = RegistryTestHelper.class.getResourceAsStream(filename); 175 try { 176 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(largeProfileStream)); 177 StringBuilder profileStringBuilder = new StringBuilder(); 178 String line; 179 while (null != (line = bufferedReader.readLine())) { 180 profileStringBuilder.append(line); 181 } 182 return profileStringBuilder.toString(); 183 } finally { 184 largeProfileStream.close(); 185 } 186 } 177 return getStringFromStream(largeProfileStream); 178 } 179 180 181 187 182 188 183 ////////////////////// … … 281 276 return matcher.find() && !matcher.find(); //find only one 282 277 } 278 279 280 // helping method writing byte[] bytes into the filename 281 public static void writeBytesToFile(byte[] bytes, String filename) throws IOException, JAXBException { 282 283 File file = new File(filename); 284 FileOutputStream fop = new FileOutputStream(file); 285 286 fop.write(bytes); 287 288 fop.flush(); 289 fop.close(); 290 291 292 } 293 294 295 296 //helping method writing String str into the file filename 297 public static void writeStringToFile(String str, String filename) throws IOException, JAXBException { 298 299 writeBytesToFile(str.getBytes(), filename); 300 301 302 } 303 304 ///////////////////////////////////////// 305 // writing ByteArrayOutputStream into the file filename 306 public static void writeStreamToFile(ByteArrayOutputStream os, String filename) throws IOException, JAXBException { 307 308 writeBytesToFile(os.toByteArray(), filename); 309 310 311 } 283 312 }
Note: See TracChangeset
for help on using the changeset viewer.