Changeset 2162


Ignore:
Timestamp:
08/28/12 15:50:42 (12 years ago)
Author:
olhsha
Message:

# 50testing on files (functional part does work on the existing file, on the freshly written file -- null pointer exception), experimenting with the Marchaller

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  
    77import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    88import clarin.cmdi.componentregistry.components.CMDComponentType;
     9import clarin.cmdi.componentregistry.model.AbstractDescription;
     10import clarin.cmdi.componentregistry.rest.RegistryTestHelper;
     11import java.io.BufferedReader;
     12import java.io.ByteArrayOutputStream;
     13import java.io.File;
     14import java.io.FileOutputStream;
     15import java.io.IOException;
     16import java.io.InputStream;
     17import java.io.InputStreamReader;
    918import java.util.List;
     19import javax.xml.bind.JAXBException;
    1020import org.junit.Test;
    1121import static org.junit.Assert.*;
     
    1727
    1828public class CMDComponentTypeWrapperTest {
    19    
    20    
    2129
    2230    ///////////////////////////////
     
    7280   
    7381    ///////////////////////////////
    74     private void checkNullnessOfFilenames(CMDComponentType component){
     82    // checks if all the filenames related to the component are nulls
     83    private void checkNullnessOfFilenamesInComponent(CMDComponentType component){
    7584       
    7685       
    7786      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    }
    8891   
    8992    ///////////////////////////////
    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;
    105129    }
    106130   
     
    123147     
    124148      CMDComponentType component= makeTestComponent();
    125       assertTrue(checkNonNullnessOfFilenames(component));
     149      assertTrue(checkNonNullnessOfFilenamesInComponent(component));
    126150     
    127151      CMDComponentTypeWrapper wrapper = new CMDComponentTypeWrapper(component);
    128152      wrapper.setFileNamesToNull();
    129       checkNullnessOfFilenames(component);
    130      
    131      
    132      
    133      
    134      
    135      
    136       // TODO: run "setfilenamesToNull" on files!
     153      checkNullnessOfFilenamesInComponent(component);
     154     
     155     
     156     
    137157     
    138158     
     
    157177      wrapper.setFileNamesToNull();
    158178     
    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  
    55package clarin.cmdi.componentregistry;
    66
     7import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    78import clarin.cmdi.componentregistry.model.AbstractDescription;
    89import clarin.cmdi.componentregistry.model.ComponentDescription;
    910import clarin.cmdi.componentregistry.model.ProfileDescription;
     11import clarin.cmdi.componentregistry.rest.RegistryTestHelper;
    1012import clarin.cmdi.componentregistry.rss.RssItem;
     13import java.io.IOException;
     14import javax.xml.bind.JAXBException;
    1115import org.junit.After;
    1216import org.junit.AfterClass;
     
    130134       
    131135    }
     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     
    132149}
Note: See TracChangeset for help on using the changeset viewer.