Ignore:
Timestamp:
02/25/14 09:35:47 (10 years ago)
Author:
twagoo
Message:

Fixed errors due to schema change allowing only one root element in a profile or component (see r4525)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/CMDComponentSetFilenamesToNullTestRunner.java

    r3449 r4550  
    1111import java.io.IOException;
    1212import java.io.InputStreamReader;
     13import java.util.Collections;
    1314import java.util.List;
    1415import javax.xml.bind.JAXBException;
     
    1617
    1718/**
    18  * non-automated developers. test, with and input (a valid
    19  *         component/prifile xml file and a path to it) and the output (the file
    20  *         where all filenames are set to null, in the same directory as the
    21  *         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
    2324 * @author George.Georgovassilis@mpi.nl
    2425 */
     
    2627
    2728    /**
    28      * 
     29     *
    2930     * @author olhsha
    3031     */
    3132    /**
    3233     * 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
    3938     * @return the reference to the new component
    4039     */
    4140    protected CMDComponentType makeTestComponent(String filename,
    42             List<CMDComponentType> childcomponents) {
    43 
    44         CMDComponentType component = new CMDComponentType();
    45         component.setFilename(filename);
    46         List<CMDComponentType> kids = component.getCMDComponent();
    47         assertFalse(kids == null);
    48         assertEquals(kids.size(), 0);
    49         if (childcomponents != null) {
    50             kids.addAll(childcomponents);
    51         }
    52         ;
    53         return component;
     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;
    5453    }
    5554
     
    5857     */
    5958    private void checkNullnessOfFilenamesInComponent(CMDComponentType component) {
    60         assertEquals(component.getFilename(), null);
    61         checkNullnessOfFilenamesInListOfComponents(component.getCMDComponent());
     59        assertEquals(component.getFilename(), null);
     60        checkNullnessOfFilenamesInListOfComponents(component.getCMDComponent());
    6261    }
    6362
     
    6665     */
    6766    private void checkNullnessOfFilenamesInListOfComponents(
    68             List<CMDComponentType> listofcomponents) {
    69         for (CMDComponentType currentcomponent : listofcomponents) {
    70             checkNullnessOfFilenamesInComponent(currentcomponent);
    71         }
     67            List<CMDComponentType> listofcomponents) {
     68        for (CMDComponentType currentcomponent : listofcomponents) {
     69            checkNullnessOfFilenamesInComponent(currentcomponent);
     70        }
    7271    }
    7372
     
    7776     */
    7877    private boolean checkNonNullnessOfFilenamesInComponent(
    79             CMDComponentType component) {
    80 
    81         String filename = component.getFilename();
    82         System.out.println(filename);
    83         boolean check = (filename == null);
    84         if (check) {
    85             return false;
    86         }
    87         return checkNonNullnessOfFilenamesInListOfComponents(component
    88                 .getCMDComponent());
     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());
    8988    }
    9089
     
    9493     */
    9594    private boolean checkNonNullnessOfFilenamesInListOfComponents(
    96             List<CMDComponentType> listofcomponents) {
    97         boolean check;
    98         for (CMDComponentType currentcomponent : listofcomponents) {
    99             check = checkNonNullnessOfFilenamesInComponent(currentcomponent);
    100             if (!check) {
    101                 return false;
    102             }
    103         }
    104         return true;
     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;
    105104    }
    106105
     
    109108     */
    110109    private void addDummyFilenamesToComponent(CMDComponentType component) {
    111         if (component != null) {
    112             component.setFilename("Dummy");
    113             List<CMDComponentType> listofcomponents = component
    114                     .getCMDComponent();
    115             addDummyFilenamesToListOfComponents(listofcomponents);
    116         }
     110        if (component != null) {
     111            component.setFilename("Dummy");
     112            List<CMDComponentType> listofcomponents = component
     113                    .getCMDComponent();
     114            addDummyFilenamesToListOfComponents(listofcomponents);
     115        }
    117116    }
    118117
     
    121120     */
    122121    private void addDummyFilenamesToListOfComponents(
    123             List<CMDComponentType> listofcomponents) {
    124         for (CMDComponentType currentcomponent : listofcomponents) {
    125             addDummyFilenamesToComponent(currentcomponent);
    126         }
     122            List<CMDComponentType> listofcomponents) {
     123        for (CMDComponentType currentcomponent : listofcomponents) {
     124            addDummyFilenamesToComponent(currentcomponent);
     125        }
    127126    }
    128127
     
    131130     */
    132131    private CMDComponentSpec makeTestFromFile(String filename)
    133             throws IOException, JAXBException {
    134         FileInputStream is = new FileInputStream(filename);
    135         String profilestring = RegistryTestHelper.getStringFromStream(is);
    136         CMDComponentSpec compspec = RegistryTestHelper
    137                 .getComponentFromString(profilestring); // calling unmarchaller
    138         List<CMDComponentType> listofcomponents = compspec.getCMDComponent();
    139         addDummyFilenamesToListOfComponents(listofcomponents);
    140         assertTrue(checkNonNullnessOfFilenamesInListOfComponents(listofcomponents));
    141         return compspec;
     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;
    142141    }
    143142
     
    147146     */
    148147    private void writeDummiedXML(String filenamein, String filenameout)
    149             throws IOException, JAXBException {
    150         CMDComponentSpec compspec = makeTestFromFile(filenamein);
    151         String os = RegistryTestHelper.getXml(compspec);
    152         RegistryTestHelper.writeStringToFile(os, filenameout);
     148            throws IOException, JAXBException {
     149        CMDComponentSpec compspec = makeTestFromFile(filenamein);
     150        String os = RegistryTestHelper.getXml(compspec);
     151        RegistryTestHelper.writeStringToFile(os, filenameout);
    153152    }
    154153
     
    157156     */
    158157    private void setFileNamesToNullInFile(String dirName, String fileNameInit,
    159             String fileNameDummied, String fileNameUnDummied)
    160             throws IOException, JAXBException {
    161 
    162         String path = RegistryTestHelper.openTestDir(dirName);
    163         writeDummiedXML(path + fileNameInit, path + fileNameDummied);
    164 
    165         FileInputStream is = new FileInputStream(path + fileNameDummied);
    166         String dummiedcontent = RegistryTestHelper.getStringFromStream(is);
    167         CMDComponentSpec compspec = RegistryTestHelper
    168                 .getComponentFromString(dummiedcontent); // calling unmarchaller
    169 
    170         List<CMDComponentType> listofcomponents = compspec.getCMDComponent();
    171 
    172         IComponentRegistryRestService testrestservice = new ComponentRegistryRestService();
    173         testrestservice.setFileNamesFromListToNull(listofcomponents);
    174         checkNullnessOfFilenamesInListOfComponents(listofcomponents);
    175 
    176         String os = RegistryTestHelper.getXml(compspec);
    177         RegistryTestHelper.writeStringToFile(os, path + fileNameUnDummied);
     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);
    178177    }
    179178
     
    184183     */
    185184    public static void main(String args[]) throws java.io.IOException,
    186             JAXBException {
    187 
    188         BufferedReader buffer = new BufferedReader(new InputStreamReader(
    189                 System.in));
    190 
    191         System.out.println("");
    192         System.out
    193                 .print("Sub-directory (of target/) name? (up to 32 symbols): ");
    194         String dirName = buffer.readLine();
    195         System.out.println("");
    196         System.out
    197                 .println("(Watch out: this is a temorary directory, which is removed after any new clean+build)");
    198         System.out.println(dirName);
    199 
    200         System.out.println("");
    201         System.out.println("Check if your file is in this temorary directory");
    202         System.out.print("and input the file name (up to 32 symbols): ");
    203         String fileName = buffer.readLine();
    204         System.out.println(fileName);
    205 
    206         System.out.println("Bedankt, ff wachten .. ");
    207 
    208         String fileNameDummied = "Dummied" + fileName;
    209         String fileNameUnDummied = "Nulled" + fileName;
    210 
    211         CMDComponentSetFilenamesToNullTestRunner helper = new CMDComponentSetFilenamesToNullTestRunner();
    212 
    213         helper.setFileNamesToNullInFile(dirName, fileName, fileNameDummied,
    214                 fileNameUnDummied);
    215 
    216         System.out.println("Now look up the directory target/" + dirName);
     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);
    217216    }
    218217}
Note: See TracChangeset for help on using the changeset viewer.