Changeset 2173


Ignore:
Timestamp:
08/29/12 14:51:22 (12 years ago)
Author:
olhsha
Message:

#181 Rss Items creating is tested on inout components that are read from XML files. The test output channel file is created as well. So, marshalling and unmarshalling is also tested.

Location:
ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test
Files:
3 added
2 edited

Legend:

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

    r2170 r2173  
    228228      }
    229229     
    230        //writing profile file compspec  into the file filename
     230       //writing compspec  into the file filename
    231231      private void writeSpecToFile(CMDComponentSpec compspec, String filename) throws IOException, JAXBException {
    232232         
  • ComponentRegistry/branches/ComponentRegistry-1.13.0-olha/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/RssCreatorTest.java

    r2162 r2173  
    55package clarin.cmdi.componentregistry;
    66
    7 import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    87import clarin.cmdi.componentregistry.model.AbstractDescription;
    98import clarin.cmdi.componentregistry.model.ComponentDescription;
    109import clarin.cmdi.componentregistry.model.ProfileDescription;
    1110import clarin.cmdi.componentregistry.rest.RegistryTestHelper;
     11import clarin.cmdi.componentregistry.rss.Rss;
     12import clarin.cmdi.componentregistry.rss.RssChannel;
    1213import clarin.cmdi.componentregistry.rss.RssItem;
     14import java.io.ByteArrayOutputStream;
     15import java.io.File;
     16import java.io.FileOutputStream;
    1317import java.io.IOException;
     18import java.io.InputStream;
    1419import javax.xml.bind.JAXBException;
    1520import org.junit.After;
     
    109114    }
    110115   
     116   
     117    /////////////////////////////////////////
     118    // writing ByteArrayOutputStream into the file filename
     119      private void writeStreamToFile(ByteArrayOutputStream os, String filename) throws IOException, JAXBException {
     120         
     121        FileOutputStream fop = null;
     122        File file;
     123       
     124        file = new File(filename);
     125        fop = new FileOutputStream(file);
     126       
     127        fop.write(os.toByteArray());
     128       
     129        fop.flush();
     130        fop.close();
     131 
     132        System.out.println("the rss is written into the file and saved");
     133 
     134       
     135      }
     136   
     137   
     138   
     139    ////////////////////////////
    111140    @Test
    112141    public void profileTestToRssItem() {
     
    116145                "description", "domainname", "groupname", "href", "name", true, "uid");
    117146       
     147         
    118148        RssCreator creator = new RssCreator(pdesc);
    119149        RssItem result = creator.toRssItem();
    120150        assertEqualDescriptions(pdesc, result);
    121151       
    122     }
    123    
     152       
     153    }
     154   
     155    // write test component into file
     156    private void writeComponentIntoFile(ComponentDescription cdesc, String filename) throws IOException, JAXBException {
     157       
     158       
     159        ByteArrayOutputStream os = new ByteArrayOutputStream();
     160        MDMarshaller.marshal(cdesc, os);
     161       
     162        writeStreamToFile(os, filename);
     163       
     164    }
     165   
     166    ///////////////////////////////////////
     167    // make test component 1 and write it into file
     168   
     169    private  ComponentDescription makeTestComponent1() throws IOException, JAXBException {
     170       
     171        ComponentDescription cdesc=
     172                createTestComponentDescription(67, "God",
     173                "description1dum", "domainname1dum", "groupname1dum", "href1dum", "name1dum", "uid1dum");
     174     
     175        return cdesc;
     176    }
     177   
     178    ///////////////////////////////////////
     179    // make test component 1 and write it into file
     180   
     181    private  ComponentDescription makeTestComponent2() throws IOException, JAXBException {
     182       
     183        ComponentDescription cdesc=
     184                createTestComponentDescription(23, "Allah",
     185                "description2dum", "domainname2dum", "groupname2dum", "href2dum", "name2dum", "uid2dum");
     186     
     187        return cdesc;
     188    }
     189   
     190    ////////////////////////////////////////
    124191    @Test
    125     public void componentTestToRssItem() {
    126        
    127         ComponentDescription cdesc=
    128                 createTestComponentDescription(67, "creatorname",
    129                 "description", "domainname", "groupname", "href", "name", "uid");
    130        
    131         RssCreator creator = new RssCreator(cdesc);
    132         RssItem result = creator.toRssItem();
    133         assertEqualDescriptions(cdesc, result);
    134        
    135     }
    136    
    137    
    138     @Test
     192    public void testRssChannelAndMarshal() throws IOException, JAXBException {
     193       
     194        ComponentDescription cdesc1=makeTestComponent1();
     195        writeComponentIntoFile(cdesc1, "src/test/resources/xml/Component1.xml");
     196       
     197        ComponentDescription cdesc2=makeTestComponent2();
     198        writeComponentIntoFile(cdesc2, "src/test/resources/xml/Component2.xml");
     199       
     200       
     201       
     202        InputStream  is1 = RegistryTestHelper.getComponentContent(RegistryTestHelper.getProfileContentFromFile("/xml/Component1.xml"));
     203        ComponentDescription desc1 = MDMarshaller.unmarshal(ComponentDescription.class, is1, null) ;
     204       
     205        InputStream  is2 = RegistryTestHelper.getComponentContent(RegistryTestHelper.getProfileContentFromFile("/xml/Component2.xml"));
     206        ComponentDescription desc2 = MDMarshaller.unmarshal(ComponentDescription.class, is2, null) ;
     207       
     208       
     209        RssCreator creator1 = new RssCreator(desc1);
     210        RssItem rssitem1 = creator1.toRssItem();
     211        assertTrue(rssitem1 !=null);
     212        assertEqualDescriptions(desc1, rssitem1);
     213       
     214       
     215        RssCreator creator2 = new RssCreator(desc2);
     216        RssItem rssitem2 = creator2.toRssItem();
     217        assertTrue(rssitem2 !=null);
     218        assertEqualDescriptions(desc2, rssitem2);
     219       
     220       
     221       
     222        final Rss rss = new Rss();
     223        final RssChannel channel = new RssChannel();
     224        rss.setChannel(channel);
     225        channel.getItem().add(rssitem1);
     226        channel.getItem().add(rssitem2);
     227       
     228        ByteArrayOutputStream osrss = new ByteArrayOutputStream();
     229        MDMarshaller.marshal(rss, osrss);
     230       
     231        writeStreamToFile(osrss, "src/test/resources/xml/rssTest.xml");
     232       
     233       
     234    }
     235   
     236   
     237     
     238   
     239     
     240   
     241   
     242    //////////////////////////////////////////////
     243    /* @Test
    139244      public  void fileLargeProfileTestToRssItem() throws IOException, JAXBException {
     245         
     246        InputStream largeProfileStream = RegistryTestHelper.class.getResourceAsStream("/xml/largeProfile.xml");
    140247         
    141           String largeprofilestring = RegistryTestHelper.getLargeProfileContent(); // reading from the file
    142           CMDComponentSpec compspec=RegistryTestHelper.getComponentFromString(largeprofilestring); // calling unmarchaller
     248        AbstractDescription desc=MDMarshaller.unmarshal(ComponentDescription.class, largeProfileStream, null);
     249       
     250        assertTrue(desc !=null);
    143251         
    144          
    145       // do not know how to get AbstractDescription from this file   
     252        RssCreator creator = new RssCreator(desc);
     253        RssItem rss = creator.toRssItem();
     254       
     255        //assertTrue(rss !=null);
     256       
     257       
     258        System.out.println(rss.getAuthor());
     259        System.out.println(rss.getDescription());
     260        System.out.println(rss.getLink());
     261        System.out.println(rss.getPubDate());
     262        System.out.println(rss.getTitle());
     263       
     264       
     265        writeRssToFile(rss, "src/test/resources/xml/rssOfLargeProfile.xml");
     266       
     267       
     268       
    146269         
    147270      }
    148      
     271      */
    149272}
Note: See TracChangeset for help on using the changeset viewer.