Changeset 4550 for ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/CMDComponentSetFilenamesToNullTestRunner.java
- Timestamp:
- 02/25/14 09:35:47 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/CMDComponentSetFilenamesToNullTestRunner.java
r3449 r4550 11 11 import java.io.IOException; 12 12 import java.io.InputStreamReader; 13 import java.util.Collections; 13 14 import java.util.List; 14 15 import javax.xml.bind.JAXBException; … … 16 17 17 18 /** 18 * non-automated developers. test, with and input (a valid 19 * component/prifile xml file and a path to it) and the output (the file20 * where all filenames are set to null, in the same directory as the21 * input file)22 * @author olhsha 19 * non-automated developers. test, with and input (a valid component/prifile xml 20 * file and a path to it) and the output (the file where all filenames are set 21 * to null, in the same directory as the input file) 22 * 23 * @author olhsha 23 24 * @author George.Georgovassilis@mpi.nl 24 25 */ … … 26 27 27 28 /** 28 * 29 * 29 30 * @author olhsha 30 31 */ 31 32 /** 32 33 * makes a new component (with filled-in filename) 33 * 34 * @param filename 35 * is assigned to the filed "filename" of the new component 36 * @param childcomponents 37 * is assigned to the list of child components of the new 38 * component 34 * 35 * @param filename is assigned to the filed "filename" of the new component 36 * @param childcomponents is assigned to the list of child components of the 37 * new component 39 38 * @return the reference to the new component 40 39 */ 41 40 protected CMDComponentType makeTestComponent(String filename, 42 43 44 45 46 47 48 49 50 51 52 53 41 List<CMDComponentType> childcomponents) { 42 43 CMDComponentType component = new CMDComponentType(); 44 component.setFilename(filename); 45 List<CMDComponentType> kids = component.getCMDComponent(); 46 assertFalse(kids == null); 47 assertEquals(kids.size(), 0); 48 if (childcomponents != null) { 49 kids.addAll(childcomponents); 50 } 51 ; 52 return component; 54 53 } 55 54 … … 58 57 */ 59 58 private void checkNullnessOfFilenamesInComponent(CMDComponentType component) { 60 61 59 assertEquals(component.getFilename(), null); 60 checkNullnessOfFilenamesInListOfComponents(component.getCMDComponent()); 62 61 } 63 62 … … 66 65 */ 67 66 private void checkNullnessOfFilenamesInListOfComponents( 68 69 70 71 67 List<CMDComponentType> listofcomponents) { 68 for (CMDComponentType currentcomponent : listofcomponents) { 69 checkNullnessOfFilenamesInComponent(currentcomponent); 70 } 72 71 } 73 72 … … 77 76 */ 78 77 private boolean checkNonNullnessOfFilenamesInComponent( 79 80 81 82 83 84 85 86 87 88 78 CMDComponentType component) { 79 80 String filename = component.getFilename(); 81 System.out.println(filename); 82 boolean check = (filename == null); 83 if (check) { 84 return false; 85 } 86 return checkNonNullnessOfFilenamesInListOfComponents(component 87 .getCMDComponent()); 89 88 } 90 89 … … 94 93 */ 95 94 private boolean checkNonNullnessOfFilenamesInListOfComponents( 96 97 98 99 100 101 102 103 104 95 List<CMDComponentType> listofcomponents) { 96 boolean check; 97 for (CMDComponentType currentcomponent : listofcomponents) { 98 check = checkNonNullnessOfFilenamesInComponent(currentcomponent); 99 if (!check) { 100 return false; 101 } 102 } 103 return true; 105 104 } 106 105 … … 109 108 */ 110 109 private void addDummyFilenamesToComponent(CMDComponentType component) { 111 112 113 114 115 116 110 if (component != null) { 111 component.setFilename("Dummy"); 112 List<CMDComponentType> listofcomponents = component 113 .getCMDComponent(); 114 addDummyFilenamesToListOfComponents(listofcomponents); 115 } 117 116 } 118 117 … … 121 120 */ 122 121 private void addDummyFilenamesToListOfComponents( 123 124 125 126 122 List<CMDComponentType> listofcomponents) { 123 for (CMDComponentType currentcomponent : listofcomponents) { 124 addDummyFilenamesToComponent(currentcomponent); 125 } 127 126 } 128 127 … … 131 130 */ 132 131 private CMDComponentSpec makeTestFromFile(String filename) 133 134 135 136 137 138 List<CMDComponentType> listofcomponents = compspec.getCMDComponent();139 140 141 132 throws IOException, JAXBException { 133 FileInputStream is = new FileInputStream(filename); 134 String profilestring = RegistryTestHelper.getStringFromStream(is); 135 CMDComponentSpec compspec = RegistryTestHelper 136 .getComponentFromString(profilestring); // calling unmarchaller 137 List<CMDComponentType> listofcomponents = Collections.singletonList(compspec.getCMDComponent()); 138 addDummyFilenamesToListOfComponents(listofcomponents); 139 assertTrue(checkNonNullnessOfFilenamesInListOfComponents(listofcomponents)); 140 return compspec; 142 141 } 143 142 … … 147 146 */ 148 147 private void writeDummiedXML(String filenamein, String filenameout) 149 150 151 152 148 throws IOException, JAXBException { 149 CMDComponentSpec compspec = makeTestFromFile(filenamein); 150 String os = RegistryTestHelper.getXml(compspec); 151 RegistryTestHelper.writeStringToFile(os, filenameout); 153 152 } 154 153 … … 157 156 */ 158 157 private void setFileNamesToNullInFile(String dirName, String fileNameInit, 159 160 161 162 163 164 165 166 167 168 169 170 List<CMDComponentType> listofcomponents = compspec.getCMDComponent();171 172 173 174 175 176 177 158 String fileNameDummied, String fileNameUnDummied) 159 throws IOException, JAXBException { 160 161 String path = RegistryTestHelper.openTestDir(dirName); 162 writeDummiedXML(path + fileNameInit, path + fileNameDummied); 163 164 FileInputStream is = new FileInputStream(path + fileNameDummied); 165 String dummiedcontent = RegistryTestHelper.getStringFromStream(is); 166 CMDComponentSpec compspec = RegistryTestHelper 167 .getComponentFromString(dummiedcontent); // calling unmarchaller 168 169 List<CMDComponentType> listofcomponents = Collections.singletonList(compspec.getCMDComponent()); 170 171 IComponentRegistryRestService testrestservice = new ComponentRegistryRestService(); 172 testrestservice.setFileNamesFromListToNull(listofcomponents); 173 checkNullnessOfFilenamesInListOfComponents(listofcomponents); 174 175 String os = RegistryTestHelper.getXml(compspec); 176 RegistryTestHelper.writeStringToFile(os, path + fileNameUnDummied); 178 177 } 179 178 … … 184 183 */ 185 184 public static void main(String args[]) throws java.io.IOException, 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 185 JAXBException { 186 187 BufferedReader buffer = new BufferedReader(new InputStreamReader( 188 System.in)); 189 190 System.out.println(""); 191 System.out 192 .print("Sub-directory (of target/) name? (up to 32 symbols): "); 193 String dirName = buffer.readLine(); 194 System.out.println(""); 195 System.out 196 .println("(Watch out: this is a temorary directory, which is removed after any new clean+build)"); 197 System.out.println(dirName); 198 199 System.out.println(""); 200 System.out.println("Check if your file is in this temorary directory"); 201 System.out.print("and input the file name (up to 32 symbols): "); 202 String fileName = buffer.readLine(); 203 System.out.println(fileName); 204 205 System.out.println("Bedankt, ff wachten .. "); 206 207 String fileNameDummied = "Dummied" + fileName; 208 String fileNameUnDummied = "Nulled" + fileName; 209 210 CMDComponentSetFilenamesToNullTestRunner helper = new CMDComponentSetFilenamesToNullTestRunner(); 211 212 helper.setFileNamesToNullInFile(dirName, fileName, fileNameDummied, 213 fileNameUnDummied); 214 215 System.out.println("Now look up the directory target/" + dirName); 217 216 } 218 217 }
Note: See TracChangeset
for help on using the changeset viewer.