Changeset 2154


Ignore:
Timestamp:
08/27/12 15:14:50 (12 years ago)
Author:
olhsha
Message:

refactoring of non-server test #50 finished for now; server test should be done

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/CMDComponentTypeWrapperTest.java

    r2152 r2154  
    55package clarin.cmdi.componentregistry;
    66
     7import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    78import clarin.cmdi.componentregistry.components.CMDComponentType;
     9import java.util.List;
    810import org.junit.Test;
    911import static org.junit.Assert.*;
     
    1517
    1618public class CMDComponentTypeWrapperTest {
     19   
     20   
    1721
     22    ///////////////////////////////
     23    private CMDComponentType copyCMDComponentType(CMDComponentType newcomponent) {
     24       
     25       CMDComponentType component= new CMDComponentType();
     26       
     27       // filing in the important fields: fiename
     28       component.setFilename(newcomponent.getFilename());
     29       
     30       // filing in the important fields: the list of child components
     31       List<CMDComponentType> childcomponents = component.getCMDComponent();
     32       boolean emptynesscheck=childcomponents.isEmpty();
     33       assertTrue(emptynesscheck);
     34       
     35       List<CMDComponentType> newchildcomponents = newcomponent.getCMDComponent();
     36       for (CMDComponentType currentcomponent: newchildcomponents){
     37           childcomponents.add(copyCMDComponentType(currentcomponent));
     38       }
     39       
     40       
     41       return component;
     42    }
     43   
     44   
     45    //////////////////////////
     46    private CMDComponentType makeTestComponent(){
     47       CMDComponentType component= new CMDComponentType();
     48       
     49       // fil-in filename
     50      component.setFilename("rhabarber");
     51      assertEquals(component.getFilename(), "rhabarber");
     52     
     53       // fil-in child components
     54      List<CMDComponentType> childcomponents = component.getCMDComponent();
     55      boolean emptynesscheck=childcomponents.isEmpty();
     56      assertTrue(emptynesscheck);
     57     
     58      String[] filenames = {"Guilherme", "Peter", "Twan", "Olha"};
     59      for (String currentname : filenames){
     60         CMDComponentType currentcomponent = new CMDComponentType();
     61         currentcomponent.setFilename(currentname);
     62         assertEquals(currentcomponent.getFilename(), currentname);
     63         childcomponents.add(currentcomponent);
     64       }
     65       
     66       
     67       return component;
     68    }
     69   
     70   
     71   
     72   
     73    ///////////////////////////////
     74    private void checkNullnessOfFilenames(CMDComponentType component){
     75       
     76       
     77      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   
     88   
     89    ///////////////////////////////
     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;
     105    }
     106   
     107    ///////////////////////////
     108    @Test   
     109    public void setFileNamesToNullTestComponent(){
     110       
     111     
     112      /////////////////////////////////////////////////////
     113      // check on a fresh (empty)  CMDComponentType
     114      CMDComponentType emptycomponent= new CMDComponentType();
     115      CMDComponentTypeWrapper emptywrapper = new CMDComponentTypeWrapper(emptycomponent);
     116      emptywrapper.setFileNamesToNull();
     117      assertEquals(emptycomponent.getFilename(), null);
     118     
     119     
     120     
     121      /////////////////////////////////////////////////////
     122      // check on  the test component  CMDComponentType
     123     
     124      CMDComponentType component= makeTestComponent();
     125      assertTrue(checkNonNullnessOfFilenames(component));
     126     
     127      CMDComponentTypeWrapper wrapper = new CMDComponentTypeWrapper(component);
     128      wrapper.setFileNamesToNull();
     129      checkNullnessOfFilenames(component);
     130     
     131     
     132     
     133     
     134     
     135     
     136      // TODO: run "setfilenamesToNull" on files!
     137     
     138     
     139    }
    18140   
    19141   
    20142    @Test   
    21     public void setFileNamesToNullTest(){
    22        
    23       CMDComponentType component= new CMDComponentType();
     143    public void setFileNamesToNullTestSpec(){
     144     
     145      // make test spec
     146      CMDComponentSpec componentspec= new CMDComponentSpec(); 
     147       
     148      CMDComponentType component= makeTestComponent();
     149      CMDComponentType anothercomponent= copyCMDComponentType(component);
    24150     
    25151     
     152      List<CMDComponentType> listofcomponents = componentspec.getCMDComponent();
     153      listofcomponents.add(component);
     154      listofcomponents.add(anothercomponent);
    26155     
    27       // check on a fresh CMDComponentType
    28       //CMDComponentTypeWrapper.setFileNamesToNull(component);
    29       //assertEquals(component.getFilename(), null);
     156      CMDComponentTypeWrapper wrapper = new CMDComponentTypeWrapper(componentspec);
     157      wrapper.setFileNamesToNull();
     158     
     159      for (CMDComponentType currentcomponent : listofcomponents){
     160          checkNullnessOfFilenames(currentcomponent);
     161      }
     162     
     163      // test on files
    30164    }
    31165   
     166   
     167   
     168   
    32169}
Note: See TracChangeset for help on using the changeset viewer.