Changeset 2170
- Timestamp:
- 08/29/12 10:04:26 (12 years ago)
- Location:
- ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test
- Files:
-
- 1 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/CMDComponentTypeWrapperTest.java
r2162 r2170 28 28 public class CMDComponentTypeWrapperTest { 29 29 30 /////////////////////////////// 30 ////////////////////////////////////////////////// 31 31 private CMDComponentType copyCMDComponentType(CMDComponentType newcomponent) { 32 32 33 33 CMDComponentType component= new CMDComponentType(); 34 34 35 // filing in the important fields: fiename35 // filing in filename 36 36 component.setFilename(newcomponent.getFilename()); 37 37 38 // filing in the important fields: thelist of child components38 // filing in the list of child components 39 39 List<CMDComponentType> childcomponents = component.getCMDComponent(); 40 40 boolean emptynesscheck=childcomponents.isEmpty(); … … 51 51 52 52 53 ////////////////////////// 53 //////////////////////////////////////////// 54 55 54 56 private CMDComponentType makeTestComponent(){ 55 57 CMDComponentType component= new CMDComponentType(); 56 58 57 59 // fil-in filename 58 component.setFilename(" rhabarber");59 assertEquals(component.getFilename(), " rhabarber");60 component.setFilename("mini0.619"); 61 assertEquals(component.getFilename(), "mini0.619"); 60 62 61 63 // fil-in child components … … 79 81 80 82 81 /////////////////////////////// 83 ///////////////////////////////////////////// 82 84 // checks if all the filenames related to the component are nulls 83 85 private void checkNullnessOfFilenamesInComponent(CMDComponentType component){ … … 91 93 92 94 /////////////////////////////// 95 // checks if all the filenames related to the list of component are nulls 93 96 private void checkNullnessOfFilenamesInListOfComponents(List<CMDComponentType> listofcomponents){ 94 97 … … 102 105 103 106 104 /////////////////////////////// 105 // true if all the filenames for the inpit component are not null107 ///////////////////////////////////////////////// 108 // returns true if all the filenames related to the input component are not null 106 109 private boolean checkNonNullnessOfFilenamesInComponent(CMDComponentType component){ 107 110 … … 116 119 117 120 ////////////////// ///////////// 118 // true if all thefilenames inthe list of components are not null121 // returns true if all thefilenames related to the list of components are not null 119 122 private boolean checkNonNullnessOfFilenamesInListOfComponents(List<CMDComponentType> listofcomponents){ 120 123 … … 129 132 } 130 133 131 /////////////////////////// 134 //////////////////////////////////////// 135 136 132 137 @Test 133 138 public void setFileNamesToNullTestComponent(){ 134 139 135 140 136 /////////////////////////////////////////////////////137 // check ona fresh (empty) CMDComponentType141 142 // check a fresh (empty) CMDComponentType 138 143 CMDComponentType emptycomponent= new CMDComponentType(); 139 144 CMDComponentTypeWrapper emptywrapper = new CMDComponentTypeWrapper(emptycomponent); … … 143 148 144 149 145 ///////////////////////////////////////////////////// 146 // check on the test component CMDComponentType 150 // check the test component CMDComponentType 147 151 148 152 CMDComponentType component= makeTestComponent(); … … 153 157 checkNullnessOfFilenamesInComponent(component); 154 158 155 156 157 158 159 } 160 159 } 160 161 /////////////////////////////////////// 161 162 162 163 @Test … … 174 175 listofcomponents.add(anothercomponent); 175 176 177 // run the nuller 176 178 CMDComponentTypeWrapper wrapper = new CMDComponentTypeWrapper(componentspec); 177 179 wrapper.setFileNamesToNull(); … … 180 182 } 181 183 182 184 185 186 ////////////////////////////////////////////////////////////// 187 /// Testing on the profile XML file 188 // There are a few auxiliary methods preceeding the test method, which is at the end 183 189 184 190 // adding dummy filenames to a component … … 190 196 191 197 List<CMDComponentType> listofcomponents = component.getCMDComponent(); 192 193 198 addDummyFilenamesToListOfComponents(listofcomponents); 194 199 … … 196 201 } 197 202 198 // adding dummy filenames to list of component203 // adding dummy filenames to the list of components 199 204 private void addDummyFilenamesToListOfComponents(List<CMDComponentType> listofcomponents){ 200 205 … … 215 220 216 221 List<CMDComponentType> listofcomponents = compspec.getCMDComponent(); 217 218 222 addDummyFilenamesToListOfComponents(listofcomponents); 219 223 220 224 assertTrue(checkNonNullnessOfFilenamesInListOfComponents(listofcomponents)); 221 225 222 223 224 226 return compspec; 225 227 226 228 } 227 229 228 //writing profile file into the directory229 private void writeSpecToFile(CMDComponentSpec compspec ) throws IOException, JAXBException {230 //writing profile file compspec into the file filename 231 private void writeSpecToFile(CMDComponentSpec compspec, String filename) throws IOException, JAXBException { 230 232 231 233 String os = RegistryTestHelper.getXml(compspec); 232 233 234 234 235 FileOutputStream fop = null; 235 236 File file; 236 237 237 file = new File( "src/test/resources/xml/Olhatest.xml");238 file = new File(filename); 238 239 fop = new FileOutputStream(file); 239 240 … … 248 249 } 249 250 250 @Test251 251 252 // creating the profile with filenames filled by "Dummy" and writing it into the file 252 253 public void writeDummiedXML() throws IOException, JAXBException{ 253 254 254 255 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 256 writeSpecToFile(compspec, "src/test/resources/xml/largeProfileDummyFilenames.xml"); 257 258 259 260 } 261 262 263 264 ///////////////////////////////////////////// 265 // testing the nuller on the XML file 277 266 278 267 @Test … … 280 269 public void setFileNamesToNullTestFile() throws IOException, JAXBException { 281 270 282 CMDComponentSpec compspec = makeTestSpecFromLargeProfile(); 283 writeSpecToFile(compspec); 284 285 String dummiedcontent = getProfileContentFromFile("xml/Olhatest.xml"); 271 writeDummiedXML(); 272 273 String dummiedcontent = RegistryTestHelper.getProfileContentFromFile("/xml/largeProfileDummyFilenames.xml"); 286 274 CMDComponentSpec newcompspec = RegistryTestHelper.getComponentFromString(dummiedcontent); // calling unmarchaller 287 275 -
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java
r1916 r2170 167 167 } 168 168 } 169 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 } 187 188 ////////////////////// 189 190 170 191 public static CMDComponentSpec getComponentFromString(String contentString) throws JAXBException { 171 192 return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentContent(contentString), MDMarshaller.getCMDComponentSchema());
Note: See TracChangeset
for help on using the changeset viewer.