Changeset 2170


Ignore:
Timestamp:
08/29/12 10:04:26 (12 years ago)
Author:
olhsha
Message:

#50 Test in a file: null pointer exception fixed, the path to the file was misspelled
the method reading of a profile (a string) from a generic xml file is added to the RegistryTestHelper?

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  
    2828public class CMDComponentTypeWrapperTest {
    2929
    30     ///////////////////////////////
     30    //////////////////////////////////////////////////
    3131    private CMDComponentType copyCMDComponentType(CMDComponentType newcomponent) {
    3232       
    3333       CMDComponentType component= new CMDComponentType();
    3434       
    35        // filing in the important fields: fiename
     35       // filing in filename
    3636       component.setFilename(newcomponent.getFilename());
    3737       
    38        // filing in the important fields: the list of child components
     38       // filing in the list of child components
    3939       List<CMDComponentType> childcomponents = component.getCMDComponent();
    4040       boolean emptynesscheck=childcomponents.isEmpty();
     
    5151   
    5252   
    53     //////////////////////////
     53    ////////////////////////////////////////////
     54   
     55   
    5456    private CMDComponentType makeTestComponent(){
    5557       CMDComponentType component= new CMDComponentType();
    5658       
    5759       // fil-in filename
    58       component.setFilename("rhabarber");
    59       assertEquals(component.getFilename(), "rhabarber");
     60      component.setFilename("mini0.619");
     61      assertEquals(component.getFilename(), "mini0.619");
    6062     
    6163       // fil-in child components
     
    7981   
    8082   
    81     ///////////////////////////////
     83    /////////////////////////////////////////////
    8284    // checks if all the filenames related to the component are nulls
    8385    private void checkNullnessOfFilenamesInComponent(CMDComponentType component){
     
    9193   
    9294    ///////////////////////////////
     95    // checks if all the filenames related to the list of component are nulls
    9396    private void checkNullnessOfFilenamesInListOfComponents(List<CMDComponentType> listofcomponents){
    9497       
     
    102105   
    103106   
    104     ///////////////////////////////
    105     // true if all the filenames for the inpit component are not null
     107    /////////////////////////////////////////////////
     108    // returns true if all the filenames related to the input component are not null
    106109    private boolean checkNonNullnessOfFilenamesInComponent(CMDComponentType component){
    107110     
     
    116119   
    117120    ////////////////// /////////////
    118     // true if all thefilenames in the list of components are not null
     121    // returns true if all thefilenames related to the list of components are not null
    119122    private boolean checkNonNullnessOfFilenamesInListOfComponents(List<CMDComponentType> listofcomponents){
    120123       
     
    129132    }
    130133   
    131     ///////////////////////////
     134    ////////////////////////////////////////
     135   
     136   
    132137    @Test   
    133138    public void setFileNamesToNullTestComponent(){
    134139       
    135140     
    136       /////////////////////////////////////////////////////
    137       // check on a fresh (empty)  CMDComponentType
     141     
     142      // check a fresh (empty)  CMDComponentType
    138143      CMDComponentType emptycomponent= new CMDComponentType();
    139144      CMDComponentTypeWrapper emptywrapper = new CMDComponentTypeWrapper(emptycomponent);
     
    143148     
    144149     
    145       /////////////////////////////////////////////////////
    146       // check on  the test component  CMDComponentType
     150      // check  the test component  CMDComponentType
    147151     
    148152      CMDComponentType component= makeTestComponent();
     
    153157      checkNullnessOfFilenamesInComponent(component);
    154158     
    155      
    156      
    157      
    158      
    159     }
    160    
     159    }
     160   
     161    ///////////////////////////////////////
    161162   
    162163    @Test   
     
    174175      listofcomponents.add(anothercomponent);
    175176     
     177      // run the nuller
    176178      CMDComponentTypeWrapper wrapper = new CMDComponentTypeWrapper(componentspec);
    177179      wrapper.setFileNamesToNull();
     
    180182    }
    181183     
    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
    183189   
    184190    // adding dummy filenames to a component
     
    190196       
    191197        List<CMDComponentType> listofcomponents = component.getCMDComponent();
    192        
    193198        addDummyFilenamesToListOfComponents(listofcomponents);
    194199       
     
    196201    }
    197202   
    198     // adding dummy filenames to list of  component
     203    // adding dummy filenames to the list of  components
    199204    private void addDummyFilenamesToListOfComponents(List<CMDComponentType> listofcomponents){
    200205       
     
    215220         
    216221          List<CMDComponentType> listofcomponents = compspec.getCMDComponent();
    217          
    218222          addDummyFilenamesToListOfComponents(listofcomponents);
    219223         
    220224          assertTrue(checkNonNullnessOfFilenamesInListOfComponents(listofcomponents));
    221225         
    222          
    223          
    224226          return compspec;
    225227         
    226228      }
    227229     
    228        //writing profile file into the directory
    229       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 {
    230232         
    231233        String  os = RegistryTestHelper.getXml(compspec);
    232        
    233234       
    234235        FileOutputStream fop = null;
    235236        File file;
    236237       
    237         file = new File("src/test/resources/xml/Olhatest.xml");
     238        file = new File(filename);
    238239        fop = new FileOutputStream(file);
    239240       
     
    248249      }
    249250     
    250       @Test
    251      
     251     
     252      // creating the profile with filenames filled by "Dummy" and writing it into the file
    252253      public void writeDummiedXML() throws IOException, JAXBException{
    253254         
    254255          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
    277266           
    278267      @Test
     
    280269      public void setFileNamesToNullTestFile() throws IOException, JAXBException {
    281270         
    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");
    286274         CMDComponentSpec newcompspec  = RegistryTestHelper.getComponentFromString(dummiedcontent); // calling unmarchaller
    287275         
  • ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java

    r1916 r2170  
    167167        }
    168168    }
    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   
    170191    public static CMDComponentSpec getComponentFromString(String contentString) throws JAXBException {
    171192        return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentContent(contentString), MDMarshaller.getCMDComponentSchema());
Note: See TracChangeset for help on using the changeset viewer.