1   package org.codehaus.dataforge.engine.configuration;
2   
3   /*
4    * Copyright 2001-2004 Ben Walding
5    * 
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * 
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.File;
20  import java.io.FileInputStream;
21  import java.io.FileOutputStream;
22  
23  import junit.framework.TestCase;
24  
25  import org.codehaus.dataforge.engine.DataForge;
26  import org.codehaus.dataforge.engine.resolvers.FileResolver;
27  import org.codehaus.dataforge.engine.resolvers.Resolver;
28  
29  /***
30   * @author  Ben Walding
31   * @version $Id: MarshallingTest.java,v 1.9 2004/02/28 11:46:40 bwalding Exp $
32   */
33  public class MarshallingTest extends TestCase
34  {
35      /*** log4j logger */
36      private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(MarshallingTest.class);
37  
38      public void testLeakage() throws Exception
39      {
40          DataForge df = XMLConfiguration.quickConfig(getClass(), "simpleconfig.df");
41          LOGGER.debug("Finished parsing forge");
42          
43          DataForgeConfig dfc = df.getDataForgeConfig();
44  
45          int rounds = 10;
46          for (int i = 0; i < rounds; i++)
47          {
48              File f1 = File.createTempFile("dataforge", ".tmp");
49              f1.deleteOnExit();
50              LOGGER.info("Using temporary file : " + f1.getAbsolutePath());
51              FileOutputStream fos1 = new FileOutputStream(f1);
52  
53              XMLConfigurationWriter.writeXML(dfc, fos1);
54              fos1.close();
55  
56              //First we will try to parse it
57              FileInputStream fis1 = new FileInputStream(f1);
58              Resolver resolver = new FileResolver(f1.getParentFile());
59              df = XMLConfiguration.quickConfig(resolver, f1.getName());
60              XMLConfigurationTest.verifySimpleConfig(df, f1.getName());
61              fis1.close();
62  
63              //Then we will do an exact match
64              fis1.close();
65              fis1 = new FileInputStream(f1);
66  
67              //assertEquals(expected, actual);
68              f1.delete();
69          }
70      }
71  
72  }