Changeset 2162
- Timestamp:
- 08/28/12 15:50:42 (12 years ago)
- Location:
- ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/CMDComponentTypeWrapperTest.java
r2154 r2162 7 7 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 8 8 import clarin.cmdi.componentregistry.components.CMDComponentType; 9 import clarin.cmdi.componentregistry.model.AbstractDescription; 10 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 11 import java.io.BufferedReader; 12 import java.io.ByteArrayOutputStream; 13 import java.io.File; 14 import java.io.FileOutputStream; 15 import java.io.IOException; 16 import java.io.InputStream; 17 import java.io.InputStreamReader; 9 18 import java.util.List; 19 import javax.xml.bind.JAXBException; 10 20 import org.junit.Test; 11 21 import static org.junit.Assert.*; … … 17 27 18 28 public class CMDComponentTypeWrapperTest { 19 20 21 29 22 30 /////////////////////////////// … … 72 80 73 81 /////////////////////////////// 74 private void checkNullnessOfFilenames(CMDComponentType component){ 82 // checks if all the filenames related to the component are nulls 83 private void checkNullnessOfFilenamesInComponent(CMDComponentType component){ 75 84 76 85 77 86 assertEquals(component.getFilename(), null); 78 79 List<CMDComponentType> childcomponents = component.getCMDComponent(); 80 81 for (CMDComponentType currentcomponent : childcomponents){ 82 checkNullnessOfFilenames(currentcomponent); 83 } 84 85 86 } 87 87 checkNullnessOfFilenamesInListOfComponents(component.getCMDComponent()); 88 89 90 } 88 91 89 92 /////////////////////////////// 90 // true if there at least one non-null filename in the given component or its children 91 private boolean checkNonNullnessOfFilenames(CMDComponentType component){ 92 93 boolean check=(component.getFilename() != null); 94 95 if (check) return true; 96 97 List<CMDComponentType> childcomponents = component.getCMDComponent(); 98 99 for (CMDComponentType currentcomponent : childcomponents){ 100 check=checkNonNullnessOfFilenames(currentcomponent); 101 if(check) return true; 102 } 103 104 return false; 93 private void checkNullnessOfFilenamesInListOfComponents(List<CMDComponentType> listofcomponents){ 94 95 96 for (CMDComponentType currentcomponent : listofcomponents){ 97 checkNullnessOfFilenamesInComponent(currentcomponent); 98 } 99 100 101 } 102 103 104 /////////////////////////////// 105 // true if all the filenames for the inpit component are not null 106 private boolean checkNonNullnessOfFilenamesInComponent(CMDComponentType component){ 107 108 String filename = component.getFilename(); 109 System.out.println(filename); 110 boolean check=(filename == null); 111 112 if (check) return false; 113 114 return checkNonNullnessOfFilenamesInListOfComponents(component.getCMDComponent()); 115 } 116 117 ////////////////// ///////////// 118 // true if all thefilenames in the list of components are not null 119 private boolean checkNonNullnessOfFilenamesInListOfComponents(List<CMDComponentType> listofcomponents){ 120 121 boolean check; 122 123 for (CMDComponentType currentcomponent : listofcomponents){ 124 check = checkNonNullnessOfFilenamesInComponent(currentcomponent); 125 if(!check) return false; 126 } 127 128 return true; 105 129 } 106 130 … … 123 147 124 148 CMDComponentType component= makeTestComponent(); 125 assertTrue(checkNonNullnessOfFilenames (component));149 assertTrue(checkNonNullnessOfFilenamesInComponent(component)); 126 150 127 151 CMDComponentTypeWrapper wrapper = new CMDComponentTypeWrapper(component); 128 152 wrapper.setFileNamesToNull(); 129 checkNullnessOfFilenames(component); 130 131 132 133 134 135 136 // TODO: run "setfilenamesToNull" on files! 153 checkNullnessOfFilenamesInComponent(component); 154 155 156 137 157 138 158 … … 157 177 wrapper.setFileNamesToNull(); 158 178 159 for (CMDComponentType currentcomponent : listofcomponents){ 160 checkNullnessOfFilenames(currentcomponent); 161 } 162 163 // test on files 164 } 165 166 167 168 169 } 179 checkNullnessOfFilenamesInListOfComponents(listofcomponents); 180 } 181 182 183 184 // adding dummy filenames to a component 185 private void addDummyFilenamesToComponent(CMDComponentType component){ 186 187 188 if (component != null) { 189 component.setFilename("Dummy"); 190 191 List<CMDComponentType> listofcomponents = component.getCMDComponent(); 192 193 addDummyFilenamesToListOfComponents(listofcomponents); 194 195 } 196 } 197 198 // adding dummy filenames to list of component 199 private void addDummyFilenamesToListOfComponents(List<CMDComponentType> listofcomponents){ 200 201 202 for (CMDComponentType currentcomponent : listofcomponents) { 203 addDummyFilenamesToComponent(currentcomponent); 204 } 205 206 207 208 } 209 210 // adds dummy filenames to the content of largeProfile.XML 211 private CMDComponentSpec makeTestSpecFromLargeProfile() throws IOException, JAXBException { 212 213 String largeprofilestring = RegistryTestHelper.getLargeProfileContent(); // reading from the file 214 CMDComponentSpec compspec=RegistryTestHelper.getComponentFromString(largeprofilestring); // calling unmarchaller 215 216 List<CMDComponentType> listofcomponents = compspec.getCMDComponent(); 217 218 addDummyFilenamesToListOfComponents(listofcomponents); 219 220 assertTrue(checkNonNullnessOfFilenamesInListOfComponents(listofcomponents)); 221 222 223 224 return compspec; 225 226 } 227 228 //writing profile file into the directory 229 private void writeSpecToFile(CMDComponentSpec compspec) throws IOException, JAXBException { 230 231 String os = RegistryTestHelper.getXml(compspec); 232 233 234 FileOutputStream fop = null; 235 File file; 236 237 file = new File("src/test/resources/xml/Olhatest.xml"); 238 fop = new FileOutputStream(file); 239 240 fop.write(os.getBytes()); 241 242 fop.flush(); 243 fop.close(); 244 245 System.out.println("Done"); 246 247 248 } 249 250 @Test 251 252 public void writeDummiedXML() throws IOException, JAXBException{ 253 254 CMDComponentSpec compspec=makeTestSpecFromLargeProfile(); 255 writeSpecToFile(compspec); 256 257 258 259 } 260 261 262 private String getProfileContentFromFile(String filename) throws IOException { 263 InputStream dummiedProfileStream = RegistryTestHelper.class.getResourceAsStream(filename); 264 try { 265 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(dummiedProfileStream)); 266 StringBuilder profileStringBuilder = new StringBuilder(); 267 String line; 268 while (null != (line = bufferedReader.readLine())) { 269 profileStringBuilder.append(line); 270 } 271 return profileStringBuilder.toString(); 272 } finally { 273 dummiedProfileStream.close(); 274 } 275 } 276 277 278 @Test 279 280 public void setFileNamesToNullTestFile() throws IOException, JAXBException { 281 282 CMDComponentSpec compspec = makeTestSpecFromLargeProfile(); 283 writeSpecToFile(compspec); 284 285 String dummiedcontent = getProfileContentFromFile("xml/Olhatest.xml"); 286 CMDComponentSpec newcompspec = RegistryTestHelper.getComponentFromString(dummiedcontent); // calling unmarchaller 287 288 289 CMDComponentTypeWrapper wrapper = new CMDComponentTypeWrapper(newcompspec); 290 291 wrapper.setFileNamesToNull(); 292 293 checkNullnessOfFilenamesInListOfComponents(newcompspec.getCMDComponent()); 294 } 295 296 297 298 } 299 300 301 302 303 -
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/RssCreatorTest.java
r2158 r2162 5 5 package clarin.cmdi.componentregistry; 6 6 7 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 7 8 import clarin.cmdi.componentregistry.model.AbstractDescription; 8 9 import clarin.cmdi.componentregistry.model.ComponentDescription; 9 10 import clarin.cmdi.componentregistry.model.ProfileDescription; 11 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 10 12 import clarin.cmdi.componentregistry.rss.RssItem; 13 import java.io.IOException; 14 import javax.xml.bind.JAXBException; 11 15 import org.junit.After; 12 16 import org.junit.AfterClass; … … 130 134 131 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 132 149 }
Note: See TracChangeset
for help on using the changeset viewer.