search/indexer/mmm-search-indexer-api/src/test/java/net/sf/mmm/search/indexer/base/config/SearchIndexerConfigurationBeanTest.java
/**
   * This method creates a {@link SearchIndexerConfigurationBean} with test-data
   * converts it to XML, parses the XML back to java-objects and converts these
   * again to XML to finally check that both XMLs are the same.
   * 
   * @throws Exception if something went wrong.
   */
This method creates a  SearchIndexerConfigurationBean with test-data
converts it to XML, parses the XML back to java-objects and converts these
again to XML to finally check that both XMLs are the same.

@throws Exception if something went wrong.
This method creates a SearchIndexerConfigurationBean with test - data converts it to XML parses the XML back to java - objects and converts these again to XML to finally check that both XMLs are the same . @throws Exception if something went wrong .
@SuppressWarnings("unchecked")
  @Test
  public void testXmlSerialization() throws Exception {
    JAXBContext context = JAXBContext.newInstance(SearchIndexerConfigurationBean.class);
    SearchIndexerConfigurationBean config = new SearchIndexerConfigurationBean();
    SearchIndexConfigurationBean searchIndex = new SearchIndexConfigurationBean();
    searchIndex.setLocation("~/search-index");
    config.setSearchIndex(searchIndex);
    List<SearchIndexerSourceBean> sources = new ArrayList<SearchIndexerSourceBean>();
    SearchIndexerSourceBean source;
    source = new SearchIndexerSourceBean();
    source.setId("Wiki");
    source.setTitle("Wiki");
    source.setUrlPrefix("http://foo.org/twiki/");
    source.setUpdateStrategy(SearchIndexerSource.UPDATE_STRATEGY_NONE);
    sources.add(source);
    source = new SearchIndexerSourceBean();
    source.setId("SVN");
    source.setTitle("Subversion");
    source.setUrlPrefix("http://foo.org/svn/trunk");
    source.setUpdateStrategy(SearchIndexerSource.UPDATE_STRATEGY_VCS);
    sources.add(source);
    config.setSources(sources);
    List<StringTransformerChain> transformerList = new ArrayList<StringTransformerChain>();
    config.setTransformers(transformerList);
    RegexStringTransformerRule rule1 = new RegexStringTransformerRule(Pattern.compile(".txt$"), "",
        false, false);
    RegexStringTransformerRule rule2 = new RegexStringTransformerRule(Pattern.compile("/\\.foo/"),
        "", false, true);
    StringTransformerChain transformer = new StringTransformerChain("wiki-transformer", null,
        rule1, rule2);
    transformerList.add(transformer);
    List<FilterRuleChain<String>> filters = new ArrayList<FilterRuleChain<String>>();
    config.setFilters(filters);
    FilterRuleChain<String> filter;
    PatternFilterRule filterRule1 = new PatternFilterRule("^/doc/", true);
    PatternFilterRule filterRule2 = new PatternFilterRule("(?i)\\.pdf$", false);
    filter = new FilterRuleChain<String>("my-filter", null, true, filterRule1, filterRule2);
    filters.add(filter);
    filterRule1 = new PatternFilterRule("^/data/", true);
    filterRule2 = new PatternFilterRule("(?i)\\.(xml|xsl)$", false);
    filter = new FilterRuleChain<String>("extended-filter", filter, true, filterRule1, filterRule2);
    filters.add(filter);
    List<SearchIndexerDataLocationBean> locationList = new ArrayList<SearchIndexerDataLocationBean>();
    source.setLocations(locationList);
    SearchIndexerDataLocationBean location = new SearchIndexerDataLocationBean();
    location.setEncoding(EncodingUtil.ENCODING_UTF_8);
    location.setFilter(filter);
    location.setLocaltionUri("file:///data/repository");
    location.setSource(source);
    location.setUriTransformer(transformer);
    location.setUpdateStrategyVariant(SearchIndexerDataLocation.UPDATE_STRATEGY_VCS_VARIANT_SVN);
    locationList.add(location);
    StringWriter buffer = new StringWriter();
    context.createMarshaller().marshal(config, buffer);
    String xml = buffer.toString();
    StringReader reader = new StringReader(xml);
    SearchIndexerConfiguration newConfig = (SearchIndexerConfiguration) context
        .createUnmarshaller().unmarshal(reader);
    buffer = new StringWriter();
    context.createMarshaller().marshal(newConfig, buffer);
    String xml2 = buffer.toString();
    Assert.assertEquals(xml, xml2);
  }
@ SuppressWarnings ( "unchecked" ) @ Test public void testXmlSerialization ( ) throws Exception { JAXBContext context = JAXBContext . newInstance ( SearchIndexerConfigurationBean . class ) ; SearchIndexerConfigurationBean config = new SearchIndexerConfigurationBean ( ) ; SearchIndexConfigurationBean searchIndex = new SearchIndexConfigurationBean ( ) ; searchIndex . setLocation ( "~/search-index" ) ; config . setSearchIndex ( searchIndex ) ; List < SearchIndexerSourceBean > sources = new ArrayList < SearchIndexerSourceBean > ( ) ; SearchIndexerSourceBean source ; source = new SearchIndexerSourceBean ( ) ; source . setId ( "Wiki" ) ; source . setTitle ( "Wiki" ) ; source . setUrlPrefix ( "http://foo.org/twiki/" ) ; source . setUpdateStrategy ( SearchIndexerSource . UPDATE_STRATEGY_NONE ) ; sources . add ( source ) ; source = new SearchIndexerSourceBean ( ) ; source . setId ( "SVN" ) ; source . setTitle ( "Subversion" ) ; source . setUrlPrefix ( "http://foo.org/svn/trunk" ) ; source . setUpdateStrategy ( SearchIndexerSource . UPDATE_STRATEGY_VCS ) ; sources . add ( source ) ; config . setSources ( sources ) ; List < StringTransformerChain > transformerList = new ArrayList < StringTransformerChain > ( ) ; config . setTransformers ( transformerList ) ; RegexStringTransformerRule rule1 = new RegexStringTransformerRule ( Pattern . compile ( ".txt$" ) , "" , false , false ) ; RegexStringTransformerRule rule2 = new RegexStringTransformerRule ( Pattern . compile ( "/\\.foo/" ) , "" , false , true ) ; StringTransformerChain transformer = new StringTransformerChain ( "wiki-transformer" , null , rule1 , rule2 ) ; transformerList . add ( transformer ) ; List < FilterRuleChain < String > > filters = new ArrayList < FilterRuleChain < String > > ( ) ; config . setFilters ( filters ) ; FilterRuleChain < String > filter ; PatternFilterRule filterRule1 = new PatternFilterRule ( "^/doc/" , true ) ; PatternFilterRule filterRule2 = new PatternFilterRule ( "(?i)\\.pdf$" , false ) ; filter = new FilterRuleChain < String > ( "my-filter" , null , true , filterRule1 , filterRule2 ) ; filters . add ( filter ) ; filterRule1 = new PatternFilterRule ( "^/data/" , true ) ; filterRule2 = new PatternFilterRule ( "(?i)\\.(xml|xsl)$" , false ) ; filter = new FilterRuleChain < String > ( "extended-filter" , filter , true , filterRule1 , filterRule2 ) ; filters . add ( filter ) ; List < SearchIndexerDataLocationBean > locationList = new ArrayList < SearchIndexerDataLocationBean > ( ) ; source . setLocations ( locationList ) ; SearchIndexerDataLocationBean location = new SearchIndexerDataLocationBean ( ) ; location . setEncoding ( EncodingUtil . ENCODING_UTF_8 ) ; location . setFilter ( filter ) ; location . setLocaltionUri ( "file:///data/repository" ) ; location . setSource ( source ) ; location . setUriTransformer ( transformer ) ; location . setUpdateStrategyVariant ( SearchIndexerDataLocation . UPDATE_STRATEGY_VCS_VARIANT_SVN ) ; locationList . add ( location ) ; StringWriter buffer = new StringWriter ( ) ; context . createMarshaller ( ) . marshal ( config , buffer ) ; String xml = buffer . toString ( ) ; StringReader reader = new StringReader ( xml ) ; SearchIndexerConfiguration newConfig = ( SearchIndexerConfiguration ) context . createUnmarshaller ( ) . unmarshal ( reader ) ; buffer = new StringWriter ( ) ; context . createMarshaller ( ) . marshal ( newConfig , buffer ) ; String xml2 = buffer . toString ( ) ; Assert . assertEquals ( xml , xml2 ) ; }
This method creates a {@link SearchIndexerConfigurationBean} with test-data
 converts it to XML, parses the XML back to java-objects and converts these
 again to XML to finally check that both XMLs are the same.
This method creates a { @link SearchIndexerConfigurationBean } with test - data converts it to XML parses the XML back to java - objects and converts these again to XML to finally check that both XMLs are the same .
// create an example configuration as java object... // index // sources // transformers // filters // locations // configuration object created... // serialize/marshal as XML to string // deserialize/unmarshal XML string to object // serialize/marshal object back to XML // compare that both XMLs are equal // dumpAsXml(context, newConfig);